mirror of
https://github.com/adulau/aha.git
synced 2024-12-26 18:56:14 +00:00
aha-eye uses getopt
This commit is contained in:
parent
91e3e177a7
commit
58e19929ba
1 changed files with 54 additions and 14 deletions
|
@ -5,12 +5,31 @@
|
|||
#process vectors on the fly
|
||||
|
||||
from ahalib import *
|
||||
|
||||
import getopt
|
||||
logfile='aha.log'
|
||||
aha = AHAActions('../in','../out')
|
||||
aha = AHAActions(None,None)
|
||||
ptress = ProcessTrees()
|
||||
|
||||
def extract_object(obj):
|
||||
def usage(exitcode):
|
||||
print """
|
||||
Analyze log files of aha-worker and recovers process trees
|
||||
|
||||
OPTIONS
|
||||
|
||||
-h Shows this screen
|
||||
-e Specifies an export file (i.e. accessible through apache)
|
||||
-l Specifies the log file generated by aha-worker
|
||||
|
||||
AUTHOR
|
||||
Gerard Wagener
|
||||
|
||||
LICENSE
|
||||
|
||||
GPL
|
||||
"""
|
||||
sys.exit(exitcode)
|
||||
|
||||
def extract_object(obj,exportdir):
|
||||
try:
|
||||
#FIXME Until now discard decisions from aha
|
||||
if obj.has_key('block') and obj.has_key('insult'):
|
||||
|
@ -47,29 +66,50 @@ def extract_object(obj):
|
|||
#User disconnected generate a report, to avoid that other
|
||||
#information is droped
|
||||
print "List export is triggered for root ",pid
|
||||
ptress.exportUserListTxt('userlist.txt')
|
||||
ptress.exportUserListTxt(exportdir)
|
||||
ptress.silent_remove_pid(pid)
|
||||
#Cleanup annotated list
|
||||
print "Clean annotated list"
|
||||
ptress.clean_aplist(pid)
|
||||
except ValueError,e:
|
||||
print "Failed to parse ",obj
|
||||
sys.stderr.write("Failed to parse "+str(obj) + '\n')
|
||||
except KeyError,e:
|
||||
print "Incomplete message"
|
||||
sys.stderr.write("Incomplete message\n")
|
||||
|
||||
line = None
|
||||
try:
|
||||
f = open('aha.log','r')
|
||||
line = None
|
||||
logfile = None
|
||||
exportdir = None
|
||||
opts,args = getopt.getopt(sys.argv[1:],"hl:e:",["help","logfile=", "export="])
|
||||
for o,a in opts:
|
||||
if o in ('--help','-h'):
|
||||
usage(0)
|
||||
if o in ('--logfile','-l'):
|
||||
logfile = a
|
||||
if o in ('--export','-e'):
|
||||
exportdir = a
|
||||
if logfile == None:
|
||||
sys.stderr.write('A log file from aha-worker needs to be specified\n')
|
||||
sys.exit(1)
|
||||
#Load config file and get opts
|
||||
if exportdir == None:
|
||||
sys.stderr.write('An export file needs to be specified\n')
|
||||
sys.exit(1)
|
||||
f = open(logfile,'r')
|
||||
for line in f:
|
||||
(timestamp,key,serobj) = line.split('|',2)
|
||||
obj = aha.unserializeMessage(serobj)
|
||||
extract_object(obj)
|
||||
extract_object(obj,exportdir)
|
||||
f.close()
|
||||
#Dump process trees
|
||||
ptress.exportUserListTxt(exportdir)
|
||||
sys.exit(0)
|
||||
except ValueError,e:
|
||||
#File may be incomplete
|
||||
print "Value error"
|
||||
print e
|
||||
print line
|
||||
sys.stderr("Value error, file may be incomplete\n")
|
||||
sys.stderr.write(str(e) + '\n')
|
||||
sys.stderr.write(line)
|
||||
|
||||
#Dump process trees
|
||||
ptress.exportUserListTxt('userlist.txt')
|
||||
except getopt.GetoptError,e:
|
||||
sys.stderr.write(str(e)+'\n')
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Reference in a new issue