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
2212cf24
Commit
2212cf24
authored
Nov 03, 2014
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志处理系统
parent
d728c068
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
3 deletions
+90
-3
jumpserver.iml
.idea/jumpserver.iml
+1
-1
jumpserver.py
jumpserver.py
+5
-2
log_handler.py
webroot/AutoSa/AutoSa/log_handler.py
+82
-0
models.py
webroot/AutoSa/UserManage/models.py
+2
-0
No files found.
.idea/jumpserver.iml
View file @
2212cf24
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
6 (C:/Python27/
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
8 (C:\Python27\
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</component>
</module>
</module>
...
...
jumpserver.py
View file @
2212cf24
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
import
os
import
os
import
sys
import
sys
import
subprocess
import
subprocess
import
MySQLdb
import
struct
import
struct
import
fcntl
import
fcntl
import
termios
import
termios
...
@@ -17,6 +16,7 @@ from binascii import b2a_hex, a2b_hex
...
@@ -17,6 +16,7 @@ from binascii import b2a_hex, a2b_hex
import
ConfigParser
import
ConfigParser
import
paramiko
import
paramiko
import
pxssh
import
pxssh
import
pexpect
cur_dir
=
os
.
path
.
dirname
(
__file__
)
cur_dir
=
os
.
path
.
dirname
(
__file__
)
sys
.
path
.
append
(
'
%
s/webroot/AutoSa/'
%
cur_dir
)
sys
.
path
.
append
(
'
%
s/webroot/AutoSa/'
%
cur_dir
)
...
@@ -131,7 +131,7 @@ def connect(host, port, user, password):
...
@@ -131,7 +131,7 @@ def connect(host, port, user, password):
foo
.
login
(
host
,
user
,
password
,
port
=
port
,
auto_prompt_reset
=
False
)
foo
.
login
(
host
,
user
,
password
,
port
=
port
,
auto_prompt_reset
=
False
)
log
=
Logs
(
user
=
user
,
host
=
host
,
logfile
=
logfile_name
,
start_time
=
timestamp_start
,
ppid
=
os
.
getpid
())
# 日志信息记录到数据库
log
=
Logs
(
user
=
user
,
host
=
host
,
logfile
=
logfile_name
,
start_time
=
timestamp_start
,
ppid
=
os
.
getpid
())
# 日志信息记录到数据库
log
.
save
()
log
.
save
()
pid
=
Pid
(
ppid
=
os
.
getpid
(),
cpid
=
foo
.
pid
)
pid
=
Pid
(
ppid
=
os
.
getpid
(),
cpid
=
foo
.
pid
,
start_time
=
timestamp_start
,
logid
=
log
.
id
)
pid
.
save
()
pid
.
save
()
logfile
=
open
(
logfile_name
,
'a'
)
# 记录日志文件
logfile
=
open
(
logfile_name
,
'a'
)
# 记录日志文件
...
@@ -145,8 +145,11 @@ def connect(host, port, user, password):
...
@@ -145,8 +145,11 @@ def connect(host, port, user, password):
log
.
finish
=
1
log
.
finish
=
1
log
.
end_time
=
int
(
time
.
time
())
log
.
end_time
=
int
(
time
.
time
())
log
.
save
()
log
.
save
()
except
pxssh
.
ExceptionPxssh
as
e
:
except
pxssh
.
ExceptionPxssh
as
e
:
print
(
'登录失败:
%
s'
%
e
)
print
(
'登录失败:
%
s'
%
e
)
except
pexpect
.
EOF
:
print
(
'登录失败: Host refuse'
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
foo
.
logout
()
foo
.
logout
()
log
.
finish
=
1
log
.
finish
=
1
...
...
webroot/AutoSa/AutoSa/log_handler.py
0 → 100644
View file @
2212cf24
#!/usr/bin/python
#coding: utf-8
import
os
import
sys
import
time
cur_dir
=
os
.
path
.
dirname
(
__file__
)
sys
.
path
.
append
(
'
%
s/webroot/AutoSa/'
%
cur_dir
)
os
.
environ
[
'DJANGO_SETTINGS_MODULE'
]
=
'AutoSa.settings'
from
UserManage.models
import
Logs
,
Pid
def
log_hanler
(
logid
):
log
=
Logs
.
objects
.
filter
(
id
=
logid
)
if
log
:
log
=
log
[
0
]
filename
=
log
.
logfile
os
.
system
(
'cat
%
s | grep "DateTime" >
%
s.his'
%
(
filename
,
filename
))
os
.
system
(
'cat
%
s | grep "
\
[.*@.*
\
][
\
$
\
#]" >>
%
s.his'
%
(
filename
,
filename
))
os
.
system
(
'cat
%
s | grep "EndTime" >>
%
s.his'
%
(
filename
,
filename
))
def
set_finish
(
id
):
logs
=
Logs
.
objects
.
filter
(
id
=
id
,
finish
=
0
)
if
logs
:
structtime_start
=
time
.
localtime
()
timestamp_end
=
int
(
time
.
mktime
(
structtime_start
))
log
=
logs
[
0
]
log
.
finish
=
1
log
.
end_time
=
timestamp_end
log
.
save
()
def
kill_pid
(
pid
):
try
:
os
.
kill
(
pid
,
9
)
except
OSError
:
pass
def
pid_exist
(
pid
):
pid_dir
=
"/proc/
%
s"
%
pid
if
os
.
path
.
isdir
(
pid_dir
):
return
True
else
:
return
False
def
get_pids
():
pids
=
[]
pids_obj
=
Pid
.
objects
.
all
()
for
pid_obj
in
pids_obj
:
pids
.
append
((
pid_obj
.
ppid
,
pid_obj
.
cpid
,
pid_obj
.
logid
,
pid_obj
.
start_time
))
return
pids
def
run
():
for
ppid
,
cpid
,
logid
,
start_time
in
get_pids
():
if
pid_exist
(
cpid
):
if
pid_exist
(
ppid
):
structtime_start
=
time
.
localtime
()
timestamp_end
=
int
(
time
.
mktime
(
structtime_start
))
if
timestamp_end
-
start_time
>
7200
:
kill_pid
(
ppid
)
kill_pid
(
cpid
)
set_finish
(
logid
)
log_hanler
(
logid
)
else
:
kill_pid
(
cpid
)
set_finish
(
logid
)
log_hanler
(
logid
)
else
:
set_finish
(
logid
)
log_hanler
(
logid
)
if
__name__
==
'__main__'
:
while
True
:
run
()
time
.
sleep
(
0.5
)
webroot/AutoSa/UserManage/models.py
View file @
2212cf24
...
@@ -43,4 +43,6 @@ class Pid(models.Model):
...
@@ -43,4 +43,6 @@ class Pid(models.Model):
"""
"""
ppid
=
models
.
IntegerField
()
ppid
=
models
.
IntegerField
()
cpid
=
models
.
IntegerField
()
cpid
=
models
.
IntegerField
()
logid
=
models
.
IntegerField
()
start_time
=
models
.
IntegerField
()
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