Check snmp follow.pl

From Federal Burro of Information
Revision as of 14:13, 22 September 2016 by David (talk | contribs) (Created page with "== Introduction == /Check snmp follow.pl Use this script to look for a value in an snmp table. Suppose you have an snmp table called hardwarestatus that looks like this...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

/Check snmp follow.pl

Use this script to look for a value in an snmp table.

Suppose you have an snmp table called hardwarestatus that looks like this:

Table:

Index    name     status
1        cpu      good(1)
2        hdd1     good(1)
3        hdd2     good(1)
4        gpu      good(1)

Or if you did a walk you would see:

.1.2.1.1 = 1
.1.2.1.2 = 2
.1.2.1.3 = 3
.1.2.1.4 = 4
.1.2.2.1 = cpu
.1.2.2.2 = hdd1
.1.2.2.3 = hdd2
.1.2.2.4 = gpu
.1.2.3.1 = good(1)
.1.2.3.2 = good(1)
.1.2.3.3 = good(1)
.1.2.3.4 = good(1)

Now you want to monitor the temperature of the gpu. You figure the oid for the gpu is .1.2.3.4. So you whip up a nagios monitor that looks like this:

check_snmp.pl -H myhost -c public -o .1.2.3.4 -r 1

But then a hdd is added and the table looks like this:

Index(1) name(2)  status(3)
1        cpu      good(1)
2        hdd1     good(1)
3        hdd2     good(1)
4        hdd3     good(1)
5        gpu      good(1)

Now your gpu is in snmp index 5 and you have to go and update all your nagios monitors, BLEH.

What if you could say: find the entry that is called "gpu" and check it's status?

That is check_snmp_follow.pl.

use it like this:

  • oid1 is the column you should grep for a value , in this case oid1 should be .1.2.2 (name)
  • string is "gpu"
  • oid2 is the column you will find your interesting value in. In this case oid2 should be .1.2.3 (status)
  • r the value to go green, in this case 1 ( good )

the nagios command would be:

/usr/local/nagios/libexec/check_snmp_follow.pl -comm public -H 10.21.255.1 -oid1 .1.2.2 -string gpu -oid2 .1.2.3 -r 1

The result would be:

OK: 1

So now we don't care what snmp index the gpu shows up on, nagios will follow it around.

Here's an example I'm using to monitor an ipsec tunnel on the ASA.

/usr/local/nagios/libexec/check_snmp_follow.pl -comm XXX -H 10.21.255.1 -oid1 .1.3.6.1.4.1.9.9.171.1.2.3.1.7 -string 131.104.91.242 -oid2 .1.3.6.1.4.1.9.9.171.1.2.3.1.35 -r 1

no matter what index the "131.104.91.242" endpoint shows up in, we will examine it's "status" field ( .1.3.6.1.4.1.9.9.171.1.2.3.1.35.X )


Nagios Setup

in command.cfg

define command{
command_name    check_snmp_follow
command_line    $USER1$/check_snmp_follow.pl -comm $ARG1$ -H $HOSTADDRESS$ -oid1 $ARG2$ -oid2 $ARG3$ -string $ARG4$ -r $ARG5$
}

in z-sms-bell-asa-fw.cfg

define service{
use                     generic-service
host_name               tor1-asa1
service_description     3-22-d-cikeTunStatus-UofG
check_command           check_snmp_follow!eeTo3Zoo!.1.3.6.1.4.1.9.9.171.1.2.3.1.7!.1.3.6.1.4.1.9.9.171.1.2.3.1.35!131.104.91.242!1
}