mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 11:16:11 +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
|
#process vectors on the fly
|
||||||
|
|
||||||
from ahalib import *
|
from ahalib import *
|
||||||
|
import getopt
|
||||||
logfile='aha.log'
|
logfile='aha.log'
|
||||||
aha = AHAActions('../in','../out')
|
aha = AHAActions(None,None)
|
||||||
ptress = ProcessTrees()
|
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:
|
try:
|
||||||
#FIXME Until now discard decisions from aha
|
#FIXME Until now discard decisions from aha
|
||||||
if obj.has_key('block') and obj.has_key('insult'):
|
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
|
#User disconnected generate a report, to avoid that other
|
||||||
#information is droped
|
#information is droped
|
||||||
print "List export is triggered for root ",pid
|
print "List export is triggered for root ",pid
|
||||||
ptress.exportUserListTxt('userlist.txt')
|
ptress.exportUserListTxt(exportdir)
|
||||||
ptress.silent_remove_pid(pid)
|
ptress.silent_remove_pid(pid)
|
||||||
#Cleanup annotated list
|
#Cleanup annotated list
|
||||||
print "Clean annotated list"
|
print "Clean annotated list"
|
||||||
ptress.clean_aplist(pid)
|
ptress.clean_aplist(pid)
|
||||||
except ValueError,e:
|
except ValueError,e:
|
||||||
print "Failed to parse ",obj
|
sys.stderr.write("Failed to parse "+str(obj) + '\n')
|
||||||
except KeyError,e:
|
except KeyError,e:
|
||||||
print "Incomplete message"
|
sys.stderr.write("Incomplete message\n")
|
||||||
|
|
||||||
line = None
|
|
||||||
try:
|
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:
|
for line in f:
|
||||||
(timestamp,key,serobj) = line.split('|',2)
|
(timestamp,key,serobj) = line.split('|',2)
|
||||||
obj = aha.unserializeMessage(serobj)
|
obj = aha.unserializeMessage(serobj)
|
||||||
extract_object(obj)
|
extract_object(obj,exportdir)
|
||||||
f.close()
|
f.close()
|
||||||
|
#Dump process trees
|
||||||
|
ptress.exportUserListTxt(exportdir)
|
||||||
|
sys.exit(0)
|
||||||
except ValueError,e:
|
except ValueError,e:
|
||||||
#File may be incomplete
|
#File may be incomplete
|
||||||
print "Value error"
|
sys.stderr("Value error, file may be incomplete\n")
|
||||||
print e
|
sys.stderr.write(str(e) + '\n')
|
||||||
print line
|
sys.stderr.write(line)
|
||||||
|
|
||||||
#Dump process trees
|
except getopt.GetoptError,e:
|
||||||
ptress.exportUserListTxt('userlist.txt')
|
sys.stderr.write(str(e)+'\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in a new issue