Check if OID exists

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.
Locked
ray.holtz
Posts: 9
Joined: Tue Aug 25, 2015 11:24 am

Check if OID exists

Post 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
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check if OID exists

Post 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)
Former Nagios Employee
ray.holtz
Posts: 9
Joined: Tue Aug 25, 2015 11:24 am

Re: Check if OID exists

Post 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
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check if OID exists

Post 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.
Former Nagios Employee
ray.holtz
Posts: 9
Joined: Tue Aug 25, 2015 11:24 am

Re: Check if OID exists

Post 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$
        }
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check if OID exists

Post by rkennedy »

Yep, I believe that will work for you after reviewing your command definition. Are you running into issues?
Former Nagios Employee
ray.holtz
Posts: 9
Joined: Tue Aug 25, 2015 11:24 am

Re: Check if OID exists

Post by ray.holtz »

Thanks a lot @rkennedy.

That negate command works great!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check if OID exists

Post 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?
Former Nagios Employee
Locked