Oct 18, 2012 10:36 AM
transform to split event message
-
Like (0)
hello,
i have a script which parses weblogic logs at 5 minute intervals, extracts the lines with error codes and for each line , sends the following to zenoss:-
timestamp
error code
error message
i am sending the message separated by new line (\n)... at zenoss i am trying to apply a transform to split the event message according to \n and then create separate events for each line... however the split does not seem to work ... i am doing something like - linelist=evt.message.split('\n') - and this should populate the list linelist with the lines in event message as items... but that is not happening. Any pointers ?
regards
Sadat
To get each line, I think it'd be something like:
linelist=evt.message.split('\n')
line1=linelist[0]
line2=linelist[1]
line3=linelist[2]
Though the split may not be seeing '\n' as a line break. So you could try adding an escape character to treat the \n properly:
linelist=evt.message.split('\\n')
hi,
1./ '\n' is being used correctly by split... no need to use escape character
2./ what i want is to create a new event for each line in original message...
linelist=evt.summary.split('\n')
for line in linelist:
evt.message = line
evt.severity = 2
the above code though takes only first line from the original message ( doen not go through with the loop)... how can i create those different events from the original event ?
regards
Sadat
Your loop looks to be OK. This is it running in a Python shell:
>>> txt="one/ntwo/nthree"
>>> linelist=txt.split('/n')
>>> for line in linelist:
... print "LINE " + line
...
LINE one
LINE two
LINE three
>>>
As you may have figured out what your code snippet is doing is repeatedly manipulating the current event. Unfortunately I don't know how to create a new event in Python inside a transform. I've been having a look round, and the only thing I've found concerns creating an event from outside of Zenoss: docs/DOC-2476
You may be able to get some ideas from that link. Sorry I can't be of more help.
hi,
thanks so much for the right direction... now i am doing something like
import subprocess
d=evt.device
ip=evt.ipAddress
linelist=evt.message.split('\n')
for line in linelist:
subprocess.call(['/opt/zenoss/bin/zensendevent','-d d','-i ip','-p weblogic','-c /Cmd/Weblogic','-s Critical','"line"'])
and the transform does not apply... where/how can i debug this ?
regards
Sadat
You might see something in zenhub.log if you change the zenhub log level to DEBUG.
yes the zenhub log, in debug mode ,does report details about the event like message , severity etc. but it dies not give any information whatsoever about the transform nor does it log any thing from the transform...
regards
Sadat
zenhub.log will give you the details yor after. Its a little tough to pick them out, and its been a little bit since I looked at it, but it says something about "before transform" and "after transform" (thats not the exact wording). The debug log will show you what happened to the message after each transform
sorry but i do not see any messages whatsoever related to the transform in zenhub.log after enabling debug mode as well... also i am using both log.debug and print statements in transform for debugging purpose and i can't see those as well in the log...
regards
Sadat
hi,
got a pointer... i am getting the following in zenhub.log for a new event
2012-10-24 16:23:59,659 INFO zen.ZenHub: Worker reports 2012-10-24 16:23:59,659 DEBUG zen.Events: =============== incoming event ===============
as can be seen it has INFO severity inspite of zenhub log severity being set at debug... this is confirmed from additional logging in the log... any pointers ?
regards
Sadat
Setting zenhub log level at debug means that it will show any messages of level debug and above. eg. info, warning, error, critical.
that is fine , but there is no trace of any kind of debug info related to the transform whatsoever in the log... which is very surprising...
regards
Sadat
what i want to do is run a system command from a transform... i am using the sys.Popen() command to run the system command... but what is happening is it is spawning many processes and does not exit... the same behaviour is not displayed by the same functionality in a script. any pointers as to why the transform is behaving differently from a normal python script ?
Just a thought, maybe a transform is not the best place to run your external event scripts?
Should it be better as an event trigger?
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||