修改 monitor

pull/2/head
guanghongwei 10 years ago
parent f3efa9b914
commit d134b2279b

@ -24,6 +24,8 @@ if not cur_dir:
sys.path.append('%s/webroot/AutoSa/' % cur_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
import django
django.setup()
from UserManage.models import User, Logs, Pid
from Assets.models import Assets
@ -88,18 +90,6 @@ def getwinsize():
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):
"""run command and return stdout"""
pipe = subprocess.Popen(cmd,
@ -120,8 +110,7 @@ def connect(host, port, user, password):
"""Use pexpect module to connect other server."""
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
if not os.path.isdir(log_date_dir):
os.mkdir(log_date_dir)
os.chmod(log_date_dir, 0777)
os.mkdir(log_date_dir, 0777)
structtime_start = time.localtime()
datetime_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')
if cmd in ['q', 'Q']:
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:
remote_exec_cmd(host, username, cmd)

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

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

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

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

Loading…
Cancel
Save