Category Archives: Nagios Core

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 – Resolving a HTTP Service Warning HTTP/1.1 403 Forbidden

Nagios – Resolving a HTTP Service Warning  HTTP/1.1 403 Forbidden

This article provides details on how to resolve a HTTP Warning for the the HTTP service on the Nagios server when running on CentOS 7.

To resolve the warning so that it shows as OK perform the following steps:

  • Login to the Nagios server
  • Edit the file /usr/local/nagios/etc/objects/localhost.cfg
  • Locate the HTTP service and change the check_command to the following:
define service {
  use                      local-service
  host_name                NAG-REMOTE
  service_description      HTTP
  check_command            check_http!--expect="403"
  notifications_enabled    0
}
  • Save and exit the file
  • Restart the Nagios service by executing the following:
systemctl restart nagios

The changed command will now expect the 403 forbidden message and now give a result of OK rather than a WARNING.

Nagios – Changing The Default Page

Nagios – Changing The Default Page

Whilst playing with Nagios Core over the past couple of weeks again I got annoyed with it returning to the main page every time I refreshed it.

A quick google turned up a few articles and I found that it’s an easy change to the index.php file.  Now my Nagios servers default to the Host Groups page which is much more useful !

Continue reading Nagios – Changing The Default Page

Nagios – Changing The Default Page

Nagios – Changing The Default Page

This article explains how to change the default page displayed in Nagios Core at logon and when refreshed.

To change the default page for Nagios Core perform the following steps:

  • Edit the file /usr/local/nagios/share/index.php by executing the command below:
vi /usr/local/nagios/share/index.php
  • At the top of the file their will be a line beginning with $url as line shown below:
$url = 'main.php';
  • Change it to the page you want the home page to be, for example changing the $url line to the text below will default Nagios to showing the Service Overview For All Host Groups page as default:
$url = 'cgi-bin/status.cgi?hostgroup=all&style=overview';
  • Save and exit the file
  • Restart Nagios by executing the following command:
systemctl restart nagios
  • Log on to the Nagios web page and confirm that the default page has been changed

Getting The URL For A Page

You can get the URL for the page which you would like to open as the default page by right-clicking on the link you would like for example, Host Groups and selecting “Open link in new tab”.  When the page opens it will show the URL which can then be entered in to the index.php page as shown above.

Below are the URL settings for the common pages on the Nagios menu:

Menu Link URL
Tactical Overview cgi-bin/tac.cgi
Map map.php?host=all
Hosts cgi-bin/status.cgi?hostgroup=all&style=hostdetail
Services cgi-bin/status.cgi?host=all
Host Groups cgi-bin/status.cgi?hostgroup=all&style=overview
Host Groups – Summary cgi-bin/status.cgi?hostgroup=all&style=summary
Host Groups – Grid cgi-bin/status.cgi?hostgroup=all&style=grid
Service Groups cgi-bin/status.cgi?servicegroup=all&style=overview
Service Groups – Summary cgi-bin/status.cgi?servicegroup=all&style=summary
Service Groups – Grid cgi-bin/status.cgi?servicegroup=all&style=overview
Problems – Services cgi-bin/status.cgi?host=all&servicestatustypes=28

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 – 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 WMI 2 – Creating A Perl WMI Script

Nagios WMI 2 – Creating A Perl WMI Script

This section of the installation articles provides the information for creating a simple Perl script to interrogate whether a Windows Service is running over WMI from Nagios.

It is by no means an approved script by Nagios standards but is written using some of the guidelines found here.  The script does achieve the simple result of if the service is Running then it returns an OK to Nagios and for any other reason it returns a CRITICAL.

Of course it could be expanded out so that things like Starting are shown as a WARNING but for the purposes of this script a simple Running / Not Running result was required.

The script:
#!/usr/bin/perl
use strict;

use Getopt::Long;
use lib "/usr/lib64/nagios/plugins";
use utils qw (%ERRORS);

my ($opt_u, $opt_p, $opt_H, $opt_s);

Getopt::Long::Configure('bundling');
GetOptions (
        "u=s" => \$opt_u, "username" => \$opt_u,
        "p=s" => \$opt_p, "password" => \$opt_p,
        "H=s" => \$opt_H, "hostname" => \$opt_H,
        "s=s" => \$opt_s, "service" => \$opt_s);

my $cmd = `wmic -U wonderland/$opt_u%"$opt_p" //$opt_H "select DisplayName,State,StartMode FROM Win32_Service where DisplayName = '$opt_s'"`;
my $output = $cmd;

if (substr($output, 0, 20) ne "CLASS: Win32_Service")
        {
         print "ERROR: Cannot connect to WMI or service not found\n";
         exit $ERRORS{'CRITICAL'};
        }
my @result = split(/\n/, $output);

my @status = split(/\|/, $result[2]);

if (@status[3] ne "Running")
        {
         print "CRITICAL: " . $opt_s . " Is Not Running\n";
         exit $ERRORS{'CRITICAL'};
        }
else
        {
         print "OK: " . $opt_s . " Is Running\n";
         exit $ERRORS{'OK'};
        }

Nagios WMI 1 – Installing The WMI Client

Nagios WMI 1 – Installing The WMI Client

Adding WMI To The Linux Host

The first step in configuring Nagios to monitor a Remote Windows Server through WMI is to install the WMI client.  The following sections provide details on how to add the Atomic Repository, install the WMI client, and finally test that it is working and communicating with the Windows Server.

Adding The Atomic Repository

The first part of installing the WMI client on to the server is to add the Atomic repository repository to the server.  To add the Atomic repository to the server perform the following steps :-

  • In the command line execute the following command :-

wget -q -O – http://www.atomicorp.com/installers/atomic | sh

  • When prompted accept the agreement
  • When prompted select OK to install the package

Installing The WMI Client

The next part is to install the WMI client package from the Atomic Repository and to do this perform the step below :-

  • In the command prompt execute the following command :-

yum install wmi

  • When prompted select OK to install the package

Testing The WMI Client

To test that the WMI client is installed and working perform the following steps :-

  • In the command prompt execute the following command :-

wmic -U {Domain Name}/{Admin User}%{Admin Password //{Host} “select * from Win32_ComputerSystem”

E.G. wmic -U Example/Administrator%password //examplehost “select * from Win32_ComputerSystem”

  • Replace the {Domain Name}. {Admin User}, {Admin Password}, and {Host} with your relevant settings
  • The command will return a list of WMI information it can enumerate from the Win32_ComputerSystem Class on the host server.

Nagios WMI – Introduction And Pre-Requisites

Nagios WMI – Introduction And Pre-Requisites

This article explains how to set up basic monitoring of a Windows server through Nagios using WMI (Windows Management Instrumentation).

Using WMI has the advantage over using the NSClient++ Software as it requires no additional software to be installed on the Windows server in order for Nagios to monitor it.

A user account on the Windows Server or Domain is needed to allow Nagios to talk to WMI which can be configured but this is outside the scope of this article.

Pre-Requisites

In order to monitor a Windows server through Nagios using WMI the following pre-requisites must be met :-

  1. A configured and working Nagios server
  2. A user account on the Windows Server or Domain with rights to communicate with WMI