修改 monitor

pull/2/head
guanghongwei 2014-11-06 17:32:43 +08:00
parent f3efa9b914
commit d134b2279b
5 changed files with 19 additions and 17 deletions

View File

@ -24,6 +24,8 @@ if not cur_dir:
sys.path.append('%s/webroot/AutoSa/' % cur_dir) sys.path.append('%s/webroot/AutoSa/' % cur_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
import django
django.setup()
from UserManage.models import User, Logs, Pid from UserManage.models import User, Logs, Pid
from Assets.models import Assets from Assets.models import Assets
@ -88,18 +90,6 @@ def getwinsize():
return struct.unpack('HHHH', x)[0:2] return struct.unpack('HHHH', x)[0:2]
# def connect_db(user, passwd, db, host='127.0.0.1', port=3306):
# """This function connect db and return db and cursor"""
# db = MySQLdb.connect(host=host,
# port=port,
# user=user,
# passwd=passwd,
# db=db,
# charset='utf8')
# cursor = db.cursor()
# return db, cursor
def run_cmd(cmd): def run_cmd(cmd):
"""run command and return stdout""" """run command and return stdout"""
pipe = subprocess.Popen(cmd, pipe = subprocess.Popen(cmd,
@ -120,8 +110,7 @@ def connect(host, port, user, password):
"""Use pexpect module to connect other server.""" """Use pexpect module to connect other server."""
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d')) log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
if not os.path.isdir(log_date_dir): if not os.path.isdir(log_date_dir):
os.mkdir(log_date_dir) os.mkdir(log_date_dir, 0777)
os.chmod(log_date_dir, 0777)
structtime_start = time.localtime() structtime_start = time.localtime()
datetime_start = time.strftime('%Y%m%d%H%M%S', structtime_start) datetime_start = time.strftime('%Y%m%d%H%M%S', structtime_start)
logtime_start = time.strftime('%Y/%m/%d %H:%M:%S', structtime_start) logtime_start = time.strftime('%Y/%m/%d %H:%M:%S', structtime_start)
@ -259,6 +248,13 @@ def exec_cmd_servers(username):
cmd = raw_input('\033[1;32mCmd(s): \033[0m') cmd = raw_input('\033[1;32mCmd(s): \033[0m')
if cmd in ['q', 'Q']: if cmd in ['q', 'Q']:
break break
if not os.path.isdir():
exec_log_dir = os.path.join(log_dir, 'exec_cmds')
os.mkdir(exec_log_dir, 0777)
filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d'))
f = open(filename, 'a')
f.write("DateTime: %s User: %s Host: %s Cmds: %s" %
(time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd))
for host in hosts: for host in hosts:
remote_exec_cmd(host, username, cmd) remote_exec_cmd(host, username, cmd)

View File

@ -9,6 +9,8 @@ cur_dir = os.path.dirname(__file__)
sys.path.append('%s/webroot/AutoSa/' % cur_dir) sys.path.append('%s/webroot/AutoSa/' % cur_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
import django
django.setup()
from UserManage.models import Logs, Pid from UserManage.models import Logs, Pid
@ -24,7 +26,6 @@ def log_hanler(logid):
print 'Handler % ok.' % filename print 'Handler % ok.' % filename
def set_finish(id): def set_finish(id):
logs = Logs.objects.filter(id=id, finish=0) logs = Logs.objects.filter(id=id, finish=0)
if logs: if logs:

View File

@ -68,6 +68,12 @@
<div class="col-sm-4"> <div class="col-sm-4">
{{ form.group }} {{ form.group }}
</div> </div>
<div class="col-sm-4">
<a href="/addGroup/">添加属组</a>
</div>
<div class="col-sm-4">
<a href="/showGroup/">删除属组</a>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
{{ form.is_admin.errors }} {{ form.is_admin.errors }}

View File

@ -27,7 +27,7 @@
<td><a href="/logHistory/?id={{ log.id }}" class="log_command">命令统计</a></td> <td><a href="/logHistory/?id={{ log.id }}" class="log_command">命令统计</a></td>
<td>阻断</td> <td>阻断</td>
{% else %} {% else %}
<td><a href="#">监控</a></td> <td><span class='monitor' filename="{{ log_name }}">监控</span></td>
<td>命令统计</td> <td>命令统计</td>
<td><a href="/killSession/?id={{ log.id }}">阻断</a> </td> <td><a href="/killSession/?id={{ log.id }}">阻断</a> </td>
{% endif %} {% endif %}

View File

@ -30,7 +30,6 @@
<td>{{ user.id }}</td> <td>{{ user.id }}</td>
<td>{{ user.username }}</td> <td>{{ user.username }}</td>
<td>{{ user.name }}</td> <td>{{ user.name }}</td>
<!--<td>{{ user.group }}</td>-->
<td> <td>
{% for group in user.group.all %} {% for group in user.group.all %}
{{ group.name }} {{ group.name }}