diff --git a/.DS_Store b/.DS_Store index 228971d07..9538c92a1 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/jlog/urls.py b/jlog/urls.py index 4013a79fa..785a83a9c 100644 --- a/jlog/urls.py +++ b/jlog/urls.py @@ -3,10 +3,11 @@ from django.conf.urls import patterns, include, url from jlog.views import * urlpatterns = patterns('', - url(r'^$', log_list), - url(r'^log_list/(\w+)/$', log_list), + url(r'^$', log_list), + url(r'^log_list/(\w+)/$', log_list), + url(r'^history/$', log_history), # url(r'^log_kill/', log_kill), - url(r'^history/$', log_history), - url(r'^record/$', log_record), - url(r'^search/$', log_search), - ) \ No newline at end of file + url(r'^record/$', log_record), + url(r'^search/$', log_search), + url(r'^monitor/$', log_monitor), + ) \ No newline at end of file diff --git a/jlog/views.py b/jlog/views.py index 513cf584e..98ab38edf 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -110,6 +110,11 @@ def log_search(request): print request.GET return render_to_response('jlog/log_filter.html', locals()) + +def log_monitor(request): + return my_render('jlog/log_monitor.html', locals(), request) + + # def log_search(request): # """ 日志搜索 """ # offset = request.GET.get('env', '') diff --git a/run_log_watch.py b/run_log_watch.py index bdfdd1894..ad8168739 100644 --- a/run_log_watch.py +++ b/run_log_watch.py @@ -2,6 +2,8 @@ import time import json +import os +import sys import os.path import tornado.ioloop @@ -11,10 +13,52 @@ import tornado.websocket import tornado.httpserver from tornado.options import define, options +from pyinotify import WatchManager, Notifier, ProcessEvent, IN_DELETE, IN_CREATE, IN_MODIFY define("port", default=8080, help="run on the given port", type=int) +class EventHandler(ProcessEvent): + def __init__(self, client=None): + self.client = client + + def process_IN_CREATE(self, event): + print "Create file:%s." % os.path.join(event.path, event.name) + + def process_IN_DELETE(self, event): + print "Delete file:%s." % os.path.join(event.path, event.name) + + def process_IN_MODIFY(self, event): + print "Modify file:%s." % os.path.join(event.path, event.name) + self.client.write_message(f.read()) + + +def file_monitor(path='.', client=None): + wm = WatchManager() + mask = IN_DELETE | IN_CREATE | IN_MODIFY + notifier = Notifier(wm, EventHandler(client)) + wm.add_watch(path, mask, auto_add=True, rec=True) + if not os.path.isfile(path): + print "You should monitor a file" + sys.exit(3) + else: + print "now starting monitor %s." %path + global f + f = open(path, 'r') + st_size = os.stat(path)[6] + f.seek(st_size) + + while True: + try: + notifier.process_events() + if notifier.check_events(): + notifier.read_events() + except KeyboardInterrupt: + print "keyboard Interrupt." + notifier.stop() + break + + class Application(tornado.web.Application): def __init__(self): handlers = [ @@ -34,21 +78,25 @@ class Application(tornado.web.Application): class SendHandler(tornado.websocket.WebSocketHandler): clients = set() + def check_origin(self, origin): + return True + def open(self): SendHandler.clients.add(self) - self.write_message(json.dumps({'input': 'connected...'})) self.stream.set_nodelay(True) def on_message(self, message): - message = json.loads(message) - self.write_message(json.dumps({'input': 'response...'})) - while True: - self.write_message(json.dumps(message)) - time.sleep(1) + self.write_message(message) + # while True: + # self.write_message(json.dumps(message)) + # time.sleep(1) # # 服务器主动关闭 # self.close() # SendHandler.clients.remove(self) + file_monitor('/opt/jumpserver/logs/tty/20151102/a_b_191034.log', client=self) + self.write_message('monitor /tmp/test1234') + def on_close(self): # 客户端主动关闭 SendHandler.clients.remove(self) diff --git a/templates/jlog/log_monitor.html b/templates/jlog/log_monitor.html new file mode 100644 index 000000000..91037b1c2 --- /dev/null +++ b/templates/jlog/log_monitor.html @@ -0,0 +1,56 @@ + + + + + + + + + Jumpserver | 开源跳板机系统 + + + {% include 'link_css.html' %} + {% include 'head_script.html' %} + + + + +
+
+
+
+
实时监控
+
+ +
+ 你好
+
+
+
+
+ + + {% block self_footer_js %} + + {% endblock %} + diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 6dad4148b..55bacb4fb 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -97,83 +97,13 @@ - +{##} -
-
-
-
-
>>输入
-
-
-
-
- -
+{#
#} +{# #} +{#
#} +{#
#} +{#
>>输入
#} +{#
#} +{#
#} +{#
#} +{#
#} +{# #} +{#
#} +{#
#} +{#
#} +{#
#} +{# #} +{# #} +{# #} +{#
#} +{#
#} +{#
#} +{#
#} +{# #} +{#
#} +{#
#} +{#
>> 输出
#} +{#
#} +{#
#} +{#
#} +{#
#} +{#
#} +
+
+
+
实时监控
+
-
-
- - - -
+ +
+ 你好
+ 你好
+ 你好
+ 你好你好你好
+ 你好
+ 你好
+ 你好
+ 你好
+ 你好
+ 你好
+ + +
-
- -
-
-
>> 输出
-
-
-
-
-
+
\ No newline at end of file diff --git a/templates/test.html b/templates/test.html index 3bcdd3174..e69de29bb 100644 --- a/templates/test.html +++ b/templates/test.html @@ -1,74 +0,0 @@ - - - - - - -{##} - - - - -

- 这是段落中的粗体文本。 -

hello

- -

- - - - - - - diff --git a/templates/test2.html b/templates/test2.html new file mode 100644 index 000000000..14d1f375f --- /dev/null +++ b/templates/test2.html @@ -0,0 +1,10 @@ + + + Poem Maker Pro + +

Your poem

+

Two {{roads}} diverged in a {{wood}}, and I—
+I took the one less travelled by,
+And that has {{made}} all the {{difference}}.

+ + \ No newline at end of file