Page 1 of 1

Check if OID exists

Posted: Tue Aug 30, 2016 11:18 am
by ray.holtz
I'd like to do a check on my Juniper SRX firewalls to see what the static route is. I know the OID is .1.3.6.1.4.1.2636.3.38.1.1.1.0.0.0.0.0.0.0.0.0.x.x.x.x (where x.x.x.x is my default route IP).

When I run a check_snmp on that OID, it comes back as OK. If I change the IP in the check to simulate the actual static route changing, the check comes back with:

Code: Select all

External command error: Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.3.6.1.4.1.2636.3.38.1.1.1.0.0.0.0.0.0.0.0.0.x.x.x.x
which is status:unknown

If I add -w 0 -c 0 to the command, it says No valid data returned.

Is there a way to have this give me a Critical status so I get an notification?

Thanks,
Ray

Re: Check if OID exists

Posted: Tue Aug 30, 2016 2:13 pm
by rkennedy
It sounds like it can't find the OID, what is the result if you run a SNMPwalk against the machine for that OID?

Code: Select all

snmpwalk -c nagiosprivate -v 2c ip .1.3.6.1.4.1.2636.3.38.1.1.1.0.0.0.0.0.0.0.0.0.x.x.x.x
(adjust as needed)

Re: Check if OID exists

Posted: Tue Aug 30, 2016 2:28 pm
by ray.holtz
I actually want it to not find the OID. In the case that the default static route on the firewall has changed, I would like to get a critical notification.

If it can find the OID, all is good and static route is good and the status should be OK
If it can not find the OID, that means the static route has changed, and I'd like it to be Critical instead of Unknown.

Thanks,
Ray

Re: Check if OID exists

Posted: Tue Aug 30, 2016 3:17 pm
by rkennedy
Ah, I misunderstood at first. I was wondering how a dynamic OID would change within as well. Anyways, you'll want to use the negate plugin.

Here's a working check -

Code: Select all

[root@localhost libexec]# ./check_snmp -H 192.168.5.41 -C nagiosprivate -o IF-MIB::ifIndex.1
SNMP OK - 1 | IF-MIB::ifIndex.1=1
[root@localhost libexec]# echo $?
0
Now, changing it to an invalid MIB -

Code: Select all

[root@localhost libexec]# ./check_snmp -H 192.168.5.41 -C nagiosprivate -o IF-MIB::ifIndex.0
External command error: IF-MIB::ifIndex.0: Unknown Object Identifier (Index out of range: 0 (ifIndex))
[root@localhost libexec]# echo $?
3
Now, run it through negate. I'm using -u OK to change UNKNOWN -> OK.

Code: Select all

[root@localhost libexec]# ./negate -u OK ./check_snmp -H 192.168.5.41 -C nagiosprivate -o IF-MIB::ifIndex.0
External command error: IF-MIB::ifIndex.0: Unknown Object Identifier (Index out of range: 0 (ifIndex))
[root@localhost libexec]# echo $?
0
So, for you, we need to use -u CRITICAL.

Code: Select all

[root@localhost libexec]# ./negate -u CRITICAL ./check_snmp -H 192.168.5.41 -C nagiosprivate -o IF-MIB::ifIndex.0
External command error: IF-MIB::ifIndex.0: Unknown Object Identifier (Index out of range: 0 (ifIndex))
[root@localhost libexec]# echo $?
2
Hopefully that helps illustrate it for you, let us know if you have any questions.

Re: Check if OID exists

Posted: Wed Aug 31, 2016 8:16 am
by ray.holtz
Thanks, that might help. But how do I get that to work in a service check? I have the service defined as:

Code: Select all

define service{
        hosts                                   host
        servicegroups                           ALL_DefaultRoutes
        service_description                     SRX Default Route
        contact_groups                          Network
        check_command                           check_snmp!-C community -o .1.3.6.1.4.1.2636.3.38.1.1.1.0.0.0.0.0.0.0.0.0.x.x.x.x
        use                                     service
        }
and the command as:

Code: Select all

define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }
Would the command be:

Code: Select all

define command{
        command_name    check_snmp
        command_line    $USER1$/negate -u CRITICAL $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }

Re: Check if OID exists

Posted: Wed Aug 31, 2016 9:15 am
by rkennedy
Yep, I believe that will work for you after reviewing your command definition. Are you running into issues?

Re: Check if OID exists

Posted: Wed Aug 31, 2016 10:54 am
by ray.holtz
Thanks a lot @rkennedy.

That negate command works great!

Re: Check if OID exists

Posted: Wed Aug 31, 2016 12:52 pm
by rkennedy
Awesome! It's pretty handy for things like this that you expect to fail, but know it's not critical.

Are we good to mark this thread as resolved?