Re: nagios snmp
Posted: Fri Feb 21, 2014 12:27 pm
/var/spool/snmptt should be empty, provided snmptt is reaping files properly, so this is good! As for your dynamic statuses, this is something I am writing a doc on, but is no where near completion. Take a look at the example below, and see if it makes sense to you. Otherwise ask away!
Given an snmptrap mib that looks like:
The EXEC line shows what text actually ends up being passed to nagios via the few spinning wheels that this passes through. Specifically the "$s" is our status message which is provided in the EVENT line as NORMAL. However we can change this to something in the variables section, in this case we only have option 1, which is just fine.
I noticed that your alarm cleared messages have a value of 0 and alarm on have a value of 1. With that, we can alter snmptraphandling.py, which is passed the result from snmptt expanding the EXEC line variables and finally passes it to nagios.cmd as a passive result. If we were to alter the EXEC line to have $1 instead of $s such as:
Instead of normal being passed as the status, we will pass 0 or 1. We then need to modify the python file to handle our new status messages and set the return code appropriately.
We need to add two elif statements after the elif severity == "MINOR": line like so:
You could also change the second elif where it looks for 1 to have a return code of 2 if you wanted critical instead of warning.
Given an snmptrap mib that looks like:
Code: Select all
EVENT room-alert-4e-snmp-trap .1.3.6.1.4.1.20916.1.6.0.2 "Status Events" Normal
FORMAT A room-alert-4e-snmp-trap indicates that an alarm $*
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "$-*" "A room-alert-4e-snmp-trap indicates that an alarm $*"
SDESC
A room-alert-4e-snmp-trap indicates that an alarm
condition has occurred on the sensor indicated
by the alarmmessage variable.
Variables:
1: alarmmessage
EDESCI noticed that your alarm cleared messages have a value of 0 and alarm on have a value of 1. With that, we can alter snmptraphandling.py, which is passed the result from snmptt expanding the EXEC line variables and finally passes it to nagios.cmd as a passive result. If we were to alter the EXEC line to have $1 instead of $s such as:
Code: Select all
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$1" "$@" "$-*" "A room-alert-4e-snmp-trap indicates that an alarm $*"Code: Select all
def get_return_code(severity):
severity = severity.upper()
if severity == "INFORMATIONAL":
return_code = "0"
elif severity == "NORMAL":
return_code = "0"
elif severity == "SEVERE":
return_code = "2"
elif severity == "MAJOR":
return_code = "2"
elif severity == "CRITICAL":
return_code = "2"
elif severity == "WARNING":
return_code = "1"
elif severity == "MINOR":
return_code = "1"
else:
printusage()
return return_codeCode: Select all
def get_return_code(severity):
severity = severity.upper()
if severity == "INFORMATIONAL":
return_code = "0"
elif severity == "NORMAL":
return_code = "0"
elif severity == "SEVERE":
return_code = "2"
elif severity == "MAJOR":
return_code = "2"
elif severity == "CRITICAL":
return_code = "2"
elif severity == "WARNING":
return_code = "1"
elif severity == "MINOR":
return_code = "1"
elif severity == "0":
return_code = "0"
elif severity == "1":
return_code = "1":
else:
printusage()
return return_code