Category Archives: Raspberry Pi

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.

Nagios Pi Part Four

Nagios Pi Part Four

Since my last post I decided to concentrate on looking in to setting up distributed monitoring with Nagios Core servers and using my Nagios Pi installation as the central server.  I looked around at the various options and went for using NRDP (Nagios Remote Data Protocol) as it enables me to use passive checks on the central server.

Continue reading Nagios Pi Part Four

Nagios Pi – Integrating With Exim4

Nagios Pi – Integrating With Exim4

This article explains how to install Exim4 on to a Raspberry Pi running Raspian Buster Lite and integrate it with Nagios for email notifications.

Exim4 is a Message Transfer Agent (MTA) developed at the University of Cambridge for use on Unix systems connected to the internet.

Installing Exim4

The first part of integrating Nagios Core with Exim4 is to install and configure Exim4. To do this perform the following steps:

  • Install Exim4 by executing the command below
sudo apt-get install exim4
  • Once installed perform the initial configuration by executing the following command
sudo dpkg-reconfigure exim4-config

Nagios Pi Part Three

Nagios Pi Part Three

Since my last post I’ve been mostly looking at how to start and shut down my environment at a certain times with success in starting but failure in shutting down.

The starting of my environment was an easy enough task with a simple bash script to send WOL packets to my hosts and using a For loop to fire it off five times for good measure.

Continue reading Nagios Pi Part Three

Nagios Pi – Implementing check_vmware_esx.pl

Nagios Pi – Implementing check_vmware_esx.pl

This article explains how to implement the check_vmware_esx.pl Nagios plugin on to a Raspberry Pi running Raspian Buster Lite.

The check_vmware_esx plugin has been developed by Martin Fuerstenau to monitor VMware through Nagios and is available on github here

Pre-Requisites

In order to implement the check_vmware_esx.pl script the following pre-requisites must be met:

  • The following Perl modules installed:
    • File::Basename
    • HTTP::Date
    • Getopt::Long
    • Time::Duration
    • Time::HiRes
  • VMware Perl SDK is installed

VMware Perl SDK Installation

For this article I used the VMware Perl SDK 6.5 and rather than using the vmware-installer.pl I had to download the i386 version of the SDK and then followed the solution steps from stumpr which I found on the VMware communities site here.

Note: As stated in the thread VMware will not support the SDK installed in by this method.

tar zxf VMware-vSphere-Perl-SDK-6.5.0-4566394.i386.tar.gz
  • Copy the vmware-vsphere-cli-distrib/lib/VMware/share/VMware folder to /usr/share/perl5 using the following command
sudo cp -r /tmp/vmware-vsphere-cli-distrib/lib/VMware/share/VMware /usr/share/perl5/.
  • Download the check_vmware_esx-master .zip zip file from github and copy it to /tmp
  • Unzip the file using the following command:
unzip check_vmware_esx-master.zip
  • Copy the check_vmware_esx.pl script to /usr/local/nagios/libexec using the following command:
sudo cp check_vmware_esx.pl /usr/local/nagios/libexec/.
  • Copy the modules folder to  /usr/share/perl5/VMware using the following command:
sudo cp -r modules /usr/share/perl5/VMware/.

At this point when I tried to run the script I encountered the error error “Can’t locate help.pm in @inc (you may need to install the help module)” when running check_vmware_esx.pl

To resolve this error perform the following steps.

  • Edit the check_vmware_esx.pl script and find the line below:
#use lib "/usr/lib/nagios/vmware/modules";
  • Edit the line and change it to the line below:
#use lib "/usr/share/perl5/VMware/modules";
  • Save and exit the script

Testing it works

Once installed successfully you can test it from the command line by performing the following steps:

  • Change directory to /usr/local/nagios/libexec and execute the script to check the CPU on an ESXi host as follows:
sudo ./check_vmware_esx.pl -H 192.168.0.100 -f authfile -S cpu

Note: I’m using an authfile for the authentication to my ESXi hosts but you can use the -u and -p options to provide a username and a password.

  • If all works then it should return something similar to the line below:
OK: CPU wait=317534.00 ms - CPU ready=554.00 ms - CPU usage=2.89%|'cpu_wait'=317534.00ms;;;; 'cpu_ready'=554.00ms;;;; 'cpu_usage'=2.89%;;;;

Nagios Pi Part Two

Nagios Pi Part Two

Since putting Nagios Core on my Pi the other day and getting it to monitor my basic network environment for a start I then looked at the monitoring my Public IP for if it changes.  Almost straight away I found a Python plugin called check_public_ip which does the trick and now Nagios checks the Public IP every hour and alerts if it changes.

Continue reading Nagios Pi Part Two

Nagios – Putting My Pi To Good Use !

Nagios – Putting My Pi To Good Use !

As with a lot of people it seems, I’ve had a Raspberry Pi knocking around for ages now which has really been doing anything.

This weekend I decided to start a project to rebuild it with Raspian Buster Lite and turn it in to a monitoring box using Nagios for my home network and maybe even look in to adding temperature and humidity probes at some point.

Continue reading Nagios – Putting My Pi To Good Use !