Colorize output depending on idle

This commit is contained in:
Oleksii Shevchuk 2017-03-16 18:07:51 +02:00
parent 8be925b74c
commit 398542404b
1 changed files with 22 additions and 16 deletions

View File

@ -31,14 +31,24 @@ class WModule(PupyModule):
for user, hosts in reversed(sorted(data.iteritems())): for user, hosts in reversed(sorted(data.iteritems())):
for host, sessions in hosts.iteritems(): for host, sessions in hosts.iteritems():
for session in sessions: for session in sessions:
color = ""
if 'idle' in session:
idle = session['idle']
color = "cyan" if idle < 10*60 else (
"grey" if idle > 60*60*24 else ""
)
object = { object = {
'HOST': host, 'HOST': colorize(host, color),
'USER': colorize( 'USER': colorize(
user, user,
"yellow" if user in ADMINS else ( "yellow" if user in ADMINS else (
"green" if session.get('me') else "") "green" if session.get('me') else "")
), ),
'LOGIN': str(datetime.fromtimestamp(int(session['started']))), 'LOGIN': colorize(
str(datetime.fromtimestamp(int(session['started']))), color
),
} }
if session.get('terminal'): if session.get('terminal'):
@ -51,9 +61,9 @@ class WModule(PupyModule):
what = '' what = ''
object.update({ object.update({
'IDLE': str(timedelta(seconds=session['idle'])), 'IDLE': colorize(str(timedelta(seconds=session['idle'])), color),
'PID': session.get('pid', ''), 'PID': colorize(str(session.get('pid', '')), color),
'WHAT': what 'WHAT': colorize(what, color)
}) })
tablein.append(object) tablein.append(object)
@ -62,7 +72,3 @@ class WModule(PupyModule):
except Exception, e: except Exception, e:
logging.exception(e) logging.exception(e)