Tag Archives: SNMP

Nagios Pi – Implementing SNMP Monitoring

Nagios Pi – Implementing SNMP Monitoring

This article explains how to implement SNMP Monitoring through Nagios on a Raspberry Pu running Raspian Buster Lite.

The check_snmp plugin is part of the Nagios Core Plugins and can be used to monitor various network devices.

This article will not cover configuring SNMP on the target devices but will provide details of the configuration set up on a Cisco SG300-10 switch.

Pre-Requisites

In order to implement SNMP Monitoring through Nagios the following pre-requisites must be met:

  • Nagios Core installed
  • SNMP configured on the target device(s)

Installing SNMP

For the purposes of this article only the SNMP agent was installed on the Raspberry Pi as I do not intend to monitor itself through SNMP but monitor network devices. To install SNMP perform the following steps:

  • Logon to the Raspberry Pi and execute the following commands:
sudo apt-get update
sudo apt-get install snmp
  • The next step is to install the MIBs using the snmp-mibs-downloader package by executing the following command:
sudo apt-get install snmp-mibs-downloader
  • The package will install and download various SNMP MIB files to the device, including the IF-MIB which will be used in this article.
  • Once the installations have completed test that an snmpwalk can contact and enumerate your target device. For the purposes on this article I am using a Cisco SG300-10 switch with the following configuration:
    • IP Address – 192.168.0.254
    • SNMP Version – V2
    • Community String – readonlyv2
  • The command below will execute an snmpwalk to IP Address 192.168.0.254 using SNMP V2, a community string of readonlyv2, instruct snmpwalk to only load the IF-MIB, and finally grep for ifOper to find out the status of the switch ports:
snmpwalk -v2c -c readonlyv2 192.168.0.254 -m IF-MIB | grep ifOper
IF-MIB::ifOperStatus.49 = INTEGER: up(1)
IF-MIB::ifOperStatus.50 = INTEGER: up(1)
IF-MIB::ifOperStatus.51 = INTEGER: up(1)
IF-MIB::ifOperStatus.52 = INTEGER: up(1)
IF-MIB::ifOperStatus.53 = INTEGER: up(1)
IF-MIB::ifOperStatus.54 = INTEGER: up(1)
IF-MIB::ifOperStatus.55 = INTEGER: up(1)
IF-MIB::ifOperStatus.56 = INTEGER: up(1)
IF-MIB::ifOperStatus.57 = INTEGER: up(1)
IF-MIB::ifOperStatus.58 = INTEGER: down(2)
  • From the above example we are able to snmpwalk the switch and find the ifOperStatus for the 10 switch ports (ifOperStatus.49 to ifOperStatus.58)

Installing the Net-SNMP Perl Module

The next step is to install the Net-SNMP Perl Module using the apt-file command by performing the following steps:

  • Execute the following command to install the Net-SNMP module:
sudo apt-get install libnet-snmp-perl

Testing it works

Once SNMP, MIBs, and the Net-SNMP Perl module have been successfully installed you can test the check_snmp plugin from the command line by performing the following steps:

  • Change directory to /usr/local/nagios/libexec and execute the check_snmp.pl script for the first interface of the switch (ifOperStatus.49 in my case):
./check_snmp -H 192.168.0.254 -C readonlyv2 -o ifOperStatus.49 -r 1 -m IF-MIB
SNMP OK - up(1) |
  • The example above uses the -r 1 to inform the plugin to return OK if the interface is UP and uses the IF-MIB file

Adding a Host and Service definition to Nagios

The next step is to add a Host and Service Definition to Nagios to allow monitoring of the Cisco Switch by performing the following steps:

  • Create a new Host definition for Nagios. The example below has been created for the Cisco SG300-10 switch used for this article:
define host {
use           generic-switch 
host_name     cisco-kid 
alias Cisco   SG300-10 Switch 
address       192.168.0.254
hostgroups    switches
}
  • Add a Service definition for Nagios. The example below has been created to check that Port 1 of the SG300-10 switch is UP:
define service {
use                   generic-service
host_name             cisco-kid
service_description   IF1-Uplinks 
check_command check_snmp!-C lost-it-local-read -o ifOperStatus.49 -r 1 -m IF-MIB check_interval 5 retry_interval 1
}
  • Once the Host and Service definitions have been added restart Nagios by executing the following command:
sudo systemctl restart nagios

Confirm Nagios is working

Once the Host and Service definitions have been added and Nagios restarted you will be able to see the Interface check results as shown in the screen shot below:

In the example above I have also added a check for Port 10 of the switches which are currently unplugged to show the results for both an up and down interface.