Category Archives: Nagios Core

Pnp4nagios Pi – Integrate With Nagios Web Interface

Pnp4nagios Pi – Integrate With Nagios Web Interface

Define pnp4nagios host and service definitions

Pnp4nagios can be integrated in to Nagios using the action_url directive in host and service definitions to add an icon / link to graphs.

The first step to integrate pnp4nagios with the Nagios web interface is to define host and service definitions by performing the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • Backup the existing  /usr/local/nagios/etc/objects/template.cfg file (Optional step)
cp /usr/local/nagios/etc/objects/templates.cfg /usr/local/nagios/etc/objects/templates.cfg-beforepnp4nagios
  • Next edit /usr/local/nagios/etc/objects/templates.cfg using the editor of your choice
  • Go to the end of the file and add the host and services definitions below:
define host {
   name host-pnp
   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=HOST
   register 0
}

define service {
   name service-pnp
   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
   register 0
}

Update the Nagios generic definitions

  • Next locate the generic-host definition and add in the line shown below in bold:
define host{
        name            generic-host ; The name of this host template
        use             host-pnp
  • FInally locate the generic-service definition and add in the line shown below in bold:
define service{
    name                generic-service ; The 'name' of this service template
    use                 service-pnp
  • Save and exit the file
  • Following the modifications to the templates.cfg file Nagios needs to be restarted by executing the following command:
systemctl restart nagios

PHP 7 Modification

Following the installation and configuration of pnp4nagios I encountered the error shown in the screen shot below:

A quick google turned up the following article https://github.com/lingej/pnp4nagios/issues/148 which gave the solution below for me as my Pi is running PHP 7:

  • Edit the /usr/local/pnp4nagios/share/application/models/data.php file
  • Go to line 979 and change if(sizeof($pages) > 0 ){ to if(is_arrary($pages) && sizeof($pages) > 0 ){
  • Save and exit the file

Pnp4nagios Pi – Configuring Nagios Commands

Pnp4nagios Pi – Configuring Nagios Commands

Configure Nagios to process performance data

Following the successful installation of pnp4nagios the next step is to configure Nagios to process performance data as well as send the data to pnp4nagios. The configuration for this piece is performed by editing the main nagios.cfg file to first enable processing of performance data, then configure the performance data file settings for hosts and services.

To modify configure Nagios to process performance data and configure the performance data file settings for hosts and services perform the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • Backup the existing /usr/local/nagios/etc/nagios.cfg file (Optional step)
cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/nagios.cfg using the editor of your choice
  • Locate the line process_performance_date=0 to process_performance_date=1 as shown below:
# PROCESS PERFORMANCE DATA OPTION
# This determines whether or not Nagios will process performance
# data returned from service and host checks. If this option is
# enabled, host performance data will be processed using the
# host_perfdata_command (defined below) and service performance
# data will be processed using the service_perfdata_command (also
#defined below). Read the HTML docs for more information on
#performance data.
#Values: 1 = process performance data, 0 = do not process performance data

process_performance_data=1
  • Next locate the line starting with #host_perfdata_file= and add in the two lines in bold as shown below to set the performance data file locations to pnp4nagios:
# HOST AND SERVICE PERFORMANCE DATA FILES
# These files are used to store host and service performance data.
# Performance data is only written to these files if the
# enable_performance_data option (above) is set to 1.

#host_perfdata_file=/usr/local/nagios/var/host-perfdata
#service_perfdata_file=/usr/local/nagios/var/service-perfdata

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
  • Next locate the line starting with #host_perfdata_file_template= and add in the two lines in bold as shown below to set the data file templates:
# HOST AND SERVICE PERFORMANCE DATA FILE TEMPLATES
# These options determine what data is written (and how) to the
# performance data files. The templates may contain macros, special
# characters (\t for tab, \r for carriage return, \n for newline)
# and plain text. A newline is automatically added after each write
# to the performance data file. Some examples of what you can do are
# shown below.

#host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
#service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
  • Next locate the line starting with #host_perfdata_file_mode=a and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE MODES
# This option determines whether or not the host and service
# performance data files are opened in write ("w") or append ("a")
# mode. If you want to use named pipes, you should use the special
# pipe ("p") mode which avoid blocking at startup, otherwise you will
# likely want the default append ("a") mode.

#host_perfdata_file_mode=a
#service_perfdata_file_mode=a

host_perfdata_file_mode=a
service_perfdata_file_mode=a
  • Next locate the line starting with #host_perfdata_file_processing_interval= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING INTERVAL
# These options determine how often (in seconds) the host and service
# performance data files are processed using the commands defined
# below. A value of 0 indicates the files should not be periodically
# processed.

#host_perfdata_file_processing_interval=0
#service_perfdata_file_processing_interval=0

host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
  • Next locate the line starting with #host_perfdata_file_processing_command= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING COMMANDS
# These commands are used to periodically process the host and
# service performance data files. The interval at which the
# processing occurs is determined by the options above.

#host_perfdata_file_processing_command=process-host-perfdata-file
#service_perfdata_file_processing_command=process-service-perfdata-file

host_perfdata_file_processing_command=process-host-perfdata-file-bulk-npcd
service_perfdata_file_processing_command=process-service-perfdata-file-bulk-npcd
  • Save and exit the file

Configure the Nagios commands

The next step in the process is to add the commands to Nagios which will be used to process the performance data with pnp4nagios by performing the following steps:

  • Backup the existing /usr/local/nagios/etc/objects/commands.cfg file (Optional step)
cp /usr/local/nagios/etc/objects/commands.cfg /usr/local/nagios/etc/objects/commands.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/objects/commands.cfg using the editor of your choice
  • Go to the end of the file and add the command definitions below:
define command {
    command_name    process-service-perfdata-file-bulk-npcd
    command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
    }

define command {
    command_name    process-host-perfdata-file-bulk-npcd
    command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
    }
  • Save and exit the file

Validate the Nagios config and restart Nagios

Once the configuration has been applied to Nagios it needs to be validated and restarted by performing the following steps:

  • Validate the Nagios configuration by executing the following command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  • Next restart Nagios by executing the following command:
systemctl restart nagios

Next, proceed on to the next article in the series to integrate with the Nagios Core Web Interface.

Pnp4nagios Pi – Installing pnp4nagios

Pnp4nagios Pi – Installing pnp4nagios

Introduction

This article explains how to implement pnp4nagios on a Raspberry Pu running Raspian Buster Lite and Nagios Core 4.4.5.

pnp4nagios is an add-on for Nagios Core which analyzes performance data provided by plugins and stores them automatically into RRD-databases. This data can then be displayed as graphs for host and service checks.

Prerequisites

In order to implement pnp4nagios on a Raspberry Pi running Raspian Buster Lite and Nagios 4.4.5 the following pre-requisites must be met:

  • Nagios Core installed

Preparing to install pnp4nagios

Before installing pnp4nagios the prerequisite packages need to be installed and the software downloaded

To prepare for the installation of pnp4nagios perform the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • The next step is to install the pre-requisite packages by executing the following commands:
apt-get update
apt-get -y install rrdtool librrds-perl php-gd php-xml
  • Once the prerequisite packages have been installed download and unpack the source code by executing the following commands:
cd /tmp
wget -O pnp4nagios-0.6.26.tar.gz https://sourceforge.net/projects/pnp4nagios/files/latest
tar -zxf pnp4nagios-0.6.26.tar.gz

Compiling and installing pnp4nagios

Once the system has been prepared and the software downloaded, perform the following steps to compile and install pnp4nagios:

  • To configure pnp4nagios execute the following commands:
cd pnp4nagios-0.6.26/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
  • To install pnp4nagios once it has been compiled execute the following commands:
make install
make install-webconf
make install-config
make install-init

Configure and start / restart daemons

The last part of the installation process for pnp4nagios is to configure and start / restart daemons on the server by performing the following steps:

  • To configure and start the npcd daemon execute the following commands:
systemctl daemon-reload
systemctl enable npcd.service
systemctl start npcd
  • The final step is to restart Apache on the server by executing the following command:
systemctl restart Apache

Next, proceed on to the next article in the series to configure Nagios commands.

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