Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
b30697ea
Commit
b30697ea
authored
Nov 03, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基本完成
parent
50d21fcd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
18 deletions
+78
-18
api.py
jumpserver/api.py
+1
-0
run_log_watch.py
run_log_watch.py
+21
-15
log_monitor.html
templates/jlog/log_monitor.html
+1
-1
log_online.html
templates/jlog/log_online.html
+55
-2
No files found.
jumpserver/api.py
View file @
b30697ea
...
...
@@ -182,6 +182,7 @@ class Jtty(object):
raise
ServerError
(
'Create
%
s failed, Please modify
%
s permission.'
%
(
today_connect_log_dir
,
tty_log_dir
))
try
:
# log_file_f = open('/opt/jumpserver/logs/tty/20151102/a_b_191034.log', 'a')
log_file_f
=
open
(
log_file_path
+
'.log'
,
'a'
)
log_time_f
=
open
(
log_file_path
+
'.time'
,
'a'
)
except
IOError
:
...
...
run_log_watch.py
View file @
b30697ea
...
...
@@ -11,11 +11,13 @@ import tornado.options
import
tornado.web
import
tornado.websocket
import
tornado.httpserver
import
tornado.gen
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
)
define
(
"host"
,
default
=
'0.0.0.0'
,
help
=
"run port on"
,
type
=
str
)
class
EventHandler
(
ProcessEvent
):
...
...
@@ -63,7 +65,7 @@ class Application(tornado.web.Application):
def
__init__
(
self
):
handlers
=
[
(
r'/'
,
MainHandler
),
(
r'/
send'
,
Send
Handler
),
(
r'/
monitor'
,
Monitor
Handler
),
]
setting
=
{
...
...
@@ -75,31 +77,33 @@ class Application(tornado.web.Application):
tornado
.
web
.
Application
.
__init__
(
self
,
handlers
,
**
setting
)
class
Send
Handler
(
tornado
.
websocket
.
WebSocketHandler
):
class
Monitor
Handler
(
tornado
.
websocket
.
WebSocketHandler
):
clients
=
set
()
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
file_path
=
None
super
(
self
.
__class__
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
check_origin
(
self
,
origin
):
return
True
def
open
(
self
):
SendHandler
.
clients
.
add
(
self
)
# 获取监控的path
self
.
file_path
=
self
.
get_argument
(
'file_path'
,
''
)
MonitorHandler
.
clients
.
add
(
self
)
self
.
stream
.
set_nodelay
(
True
)
def
on_message
(
self
,
message
):
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'
)
self
.
write_message
(
'Connect WebSocket Success. <br/>'
)
# 监控日志,发生变动发向客户端
file_monitor
(
'
%
s.log'
%
self
.
file_path
,
client
=
self
)
self
.
write_message
(
'Disconnect WebSocket.<br/>'
)
def
on_close
(
self
):
# 客户端主动关闭
SendHandler
.
clients
.
remove
(
self
)
self
.
close
()
self
.
finish
()
MonitorHandler
.
clients
.
remove
(
self
)
class
MainHandler
(
tornado
.
web
.
RequestHandler
):
...
...
@@ -111,5 +115,7 @@ if __name__ == '__main__':
tornado
.
options
.
parse_command_line
()
app
=
Application
()
server
=
tornado
.
httpserver
.
HTTPServer
(
app
)
server
.
listen
(
options
.
port
)
server
.
bind
(
options
.
port
,
options
.
host
)
# server.listen(options.port)
server
.
start
(
num_processes
=
1
)
tornado
.
ioloop
.
IOLoop
.
instance
()
.
start
()
templates/jlog/log_monitor.html
View file @
b30697ea
...
...
@@ -42,7 +42,7 @@
ws
.
onmessage
=
function
(
evt
){
console
.
log
(
evt
.
data
);
$
(
'#content'
).
append
(
evt
.
data
.
replace
(
'
\
r
\
n'
,
'<br />'
).
replace
(
'[
\
r
\
n]'
,
'<br /
>'
));
$
(
'#content'
).
append
(
evt
.
data
.
replace
(
/
\n
|
\r
|
(\r\n)
|
(\u
0085
)
|
(\u
2028
)
|
(\u
2029
)
/g
,
'<br
>'
));
};
ws
.
onclose
=
function
(
evt
){
...
...
templates/jlog/log_online.html
View file @
b30697ea
...
...
@@ -77,7 +77,7 @@
<td
id=
"remote_ip"
class=
"text-center"
>
{{ post.remote_ip }}
</td>
{% ifnotequal session_role_id 0 %}
<td
class=
"text-center"
><a
href=
"/jlog/history/?id={{ post.id }}"
class=
"log_command"
>
命令统计
</a></td>
<td
class=
"text-center"
><a
class=
"monitor"
file
name
=
"{{ post.log_path }}"
>
监控
</a></td>
<td
class=
"text-center"
><a
class=
"monitor"
file
_path
=
"{{ post.log_path }}"
>
监控
</a></td>
<td
class=
"text-center"
><input
type=
"button"
id=
"cut"
class=
"btn btn-danger btn-xs"
name=
"cut"
value=
"阻断"
onclick=
'cut("{{ post.pid }}")'
/></td>
{% endifnotequal %}
<td
class=
"text-center"
>
{{ post.start_time|date:"Y-m-d H:i:s" }}
</td>
...
...
@@ -99,9 +99,62 @@
{#
<script
src=
"http://{{ web_socket_host }}/socket.io/socket.io.js"
></script>
#}
<script>
{
#
$
(
document
).
ready
(
function
(){
#
}
{
#
$
(
'.monitor'
).
click
(
function
(){
#
}
{
#
window
.
open
(
'/jlog/monitor/'
,
'监控'
,
'height=500, width=910, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'
);
#
}
{
#
})
#
}
{
#
});
#
}
function
init
(
obj
){
var
file_path
=
obj
.
attr
(
'file_path'
);
console
.
log
(
file_path
);
var
socket
=
new
WebSocket
(
'ws://j:8080/monitor?file_path='
+
file_path
);
socket
.
onopen
=
function
(
evt
){
socket
.
send
(
file_path
)
};
var
username
=
obj
.
closest
(
'tr'
).
find
(
'#username'
).
text
();
var
ip
=
obj
.
closest
(
'tr'
).
find
(
'#ip'
).
text
();
BootstrapDialog
.
show
({
message
:
function
(){
var
tag
=
$
(
'<pre id="log" style="height: 500px;overflow: auto;background-color: rgba(0, 0, 0, 0);line-height: 0.8; border: none"></pre>'
);
{
#
document
.
cookie
.
split
(
'; '
).
forEach
(
function
(
obj
){
#
}
{
#
var
info
=
obj
.
split
(
'='
);
#
}
{
#
if
(
info
.
length
==
2
){
#
}
{
#
if
(
info
[
0
]
==
'username'
){
#
}
{
#
username
=
info
[
1
];
#
}
{
#
}
else
if
(
info
[
0
]
==
'seed'
){
#
}
{
#
seed
=
info
[
1
];
#
}
{
#
}
#
}
{
#
}
#
}
{
#
});
#
}
//服务器端认证
{
#
socket
.
send
(
'login'
,
{
userid
:
message
.
id
,
filename
:
message
.
filename
,
username
:
username
,
seed
:
seed
});
#
}
socket
.
onmessage
=
function
(
evt
){
var
control_regx
=
/
\x
1B
\[([
0-9
]{1,3}((
;
[
0-9
]{1,3})
*
)?)?[
m|K
]
/g
;
var
newline_regx
=
/
\n
|
\r
|
(\r\n)
|
(\u
0085
)
|
(\u
2028
)
|
(\u
2029
)
/g
;
{
#
if
(
option
==
'new'
)
{
#
}
tag
.
append
(
evt
.
data
.
replace
(
newline_regx
,
'<br />'
).
replace
(
control_regx
,
''
));
{
#
}
else
if
(
option
==
'exist'
)
{
#
}
{
#
tag
.
append
(
'<pre>'
+
exsit_message
+
'</pre>'
);
#
}
{
#
}
#
}
tag
.
animate
({
scrollTop
:
tag
[
0
].
scrollHeight
},
1
);
};
tag
[
0
].
style
.
color
=
"#00FF00"
;
return
tag
[
0
];
}
,
title
:
'Jumpserver实时监控 '
+
' 登录用户名: '
+
'<span class="text-info">'
+
username
+
'</span>'
+
' 登录主机: '
+
'<span class="text-info">'
+
ip
,
onhide
:
function
(){
socket
.
close
();
}});
}
$
(
document
).
ready
(
function
(){
$
(
'.monitor'
).
click
(
function
(){
window
.
open
(
'/jlog/monitor/'
,
'监控'
,
'height=500, width=910, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'
);
init
(
$
(
this
))
})
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment