Page 1 of 1
More SNMP Questions
Posted: Mon Dec 17, 2012 10:25 am
by BanditBBS
As I mentioned in another post, I have an app that sends out traps, but all of them use the some oid.
They all have something in the "Ent Value 0" field. It is always in the same format, with the "oid=date, time, SEVERITY, type, random text".
I'd like to modify a script to translate the severity into ok, warning or critical and then pass on the remaining text to NagiosXI. Which script should I add that logic to?
Thanks
Re: More SNMP Questions
Posted: Mon Dec 17, 2012 10:29 am
by scottwilkerson
If you are using SNMPTT the /etc/snmp/snmptt.conf should have your trap info and passes it to /usr/local/bin/snmptraphandling.py
I would think any additional logic could be placed in /usr/local/bin/snmptraphandling.py
Re: More SNMP Questions
Posted: Mon Dec 17, 2012 11:46 am
by BanditBBS
Ok, so I added this to snmptt.conf file:
Code: Select all
EVENT sitescanalert .1.3.6.1.4.1.7061.0.0 "Status Events" Normal
FORMAT $*
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "$-*" "$*"
SDESC
A sitescan notification signifies
that there has been a change in the state of
a sitescan monitored device.
Variables:
EDESC
And this now appears in my snmptt.log:
Code: Select all
Mon Dec 17 11:43:01 2012 .1.3.6.1.4.1.7061.0.0 Normal "Status Events" wdcae-pssw01v - Dec 17, 2012 11:42:16 AM,OFF NORMAL,Universal,High Capacity is in alarm 0.0.
As stated, every trap will be .1.3.6.1.4.1.7061.0.0. The severity will be in the data (i.e. OFF NORMAL), any idea how I can handle that and tell snmptt.conf the proper severity or the snmptraphandling.py script how to handle that and assign the proper severity? I'm lost here
Thanks
Re: More SNMP Questions
Posted: Mon Dec 17, 2012 1:21 pm
by BanditBBS
Ok, I think I figured out how to handle this mess!
I made a copy of the snmptraphandling.py script and named it snmptraphandlingss.py. I modified the snmptt.conf file to call that script when dealing with the particular OID.
Now I just need to learn python and modify the script to split the variable using "," and set severity=3rd field.
Anyone familiar with python enough to write the couple lines?
Re: More SNMP Questions
Posted: Mon Dec 17, 2012 2:30 pm
by BanditBBS
In the py script there is this secton that sets the severity to whatever was passed from snmptt;
Code: Select all
try:
severity = sys.argv[3]
except:
printusage
Well, I'm wanting to do something like this, but just can't figure out the proper syntax or if I can even do it in the script where I am trying to:
Code: Select all
try:
splitstring = sys.argv[3].split(',')
severity = splitstring[3]
except:
printusage
I've never messed with python, am trying to google, but coming up stumped on exact syntax.
Re: More SNMP Questions
Posted: Mon Dec 17, 2012 4:30 pm
by BanditBBS
Just FYI for anyone else ever doing this kind of stuff. I got it working!!
I did just change that section of code and also added to the If Else statements concerning the severity section. Working great and I can now properly alert from a system that sends everything as one OID.
Re: More SNMP Questions
Posted: Fri Dec 21, 2012 2:51 pm
by jwelch
I was going to say you could just point the trap to your own handler using perl or whatever, process the parameters, then call the 'real' handler and pass the modified parameters to it. But since you've got it working it's probably not worth the trouble this time.
Re: More SNMP Questions
Posted: Fri Dec 21, 2012 3:14 pm
by sreinhardt
Thanks for posting your answer! Glad it's working.