Using nagios to monitor port status on ethernet switches
First, we need to identify the id of the ports we want to monitor. On the console of the machine you are running nagios, execute the following commands
snmpwalk -v 1 -c MySNMPCommunity my.switch.ip.address ifDescr
you will get something like this:
IF-MIB::ifDescr.509 = STRING: pfh-0/0/0 IF-MIB::ifDescr.510 = STRING: pfe-0/0/0 IF-MIB::ifDescr.511 = STRING: pfh-0/0/0.16383 IF-MIB::ifDescr.512 = STRING: pfh-0/0/0.16384 IF-MIB::ifDescr.513 = STRING: pfe-0/0/0.16383 IF-MIB::ifDescr.514 = STRING: ge-0/0/0 IF-MIB::ifDescr.515 = STRING: ge-0/0/1 IF-MIB::ifDescr.516 = STRING: ge-0/0/2 IF-MIB::ifDescr.517 = STRING: ge-0/0/3 ...(more stuff cut off for brevity)
two notes –
1. the interfaces are not always in order!!!
2. make note of the number after ifDescr. This references the interface(s) you are intersted in
For each port you want to monitor – create a service
define service { host_name My-Switch service_description ge-0-Switch-link use generic-service check_command check_snmp!-C MySNMPCommunity -m RFC1213-MIB -s "down(2)" -o ifOperStatus.514 register 1 }
If the switch port is supposed to be up – replace “down(2)” with “up(1)”
Replace MySNMPCommunity with your community name
In my situation – I am monitoring to see if someone plugs in unauthorized equpment – so this switch port is supposed to remain down.
Replace the 514 with the approriate id for the port you want to monitor based on the snmpwalk you ran at the start of this exersize.