nagios snmp

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: nagios snmp

Post by sreinhardt »

/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:

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
EDESC
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:

Code: Select all

EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$1" "$@" "$-*" "A room-alert-4e-snmp-trap indicates that an alarm $*"
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.

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_code
We need to add two elif statements after the elif severity == "MINOR": line like so:

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"
    elif severity == "0":
        return_code = "0"
    elif severity == "1":
        return_code = "1":
    else:
        printusage()
    return return_code
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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked