Category Archives: Nagios

Nagios NRDP – Configuring Passive Checks

Nagios NRDP – Configuring Passive Checks

This following pages of this article explain how to set up the passive checks on the central Nagios server NAG-CENTRAL which will receive the host check results for NAG-REMOTE and also a service via send_nrdp.py.

To configure a passive host and check definition perform the following steps:

  • Edit the nagios.cfg configuration file /usr/local/nagios/etc/nagios.cfg by executing the command below:
vi /usr/local/nagios/etc/nagios.cfg
  • Find the object configuration file for localhost by searching for localhost.cfg
  • Add a new line as shown below to add a new object configuration file named passive-hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/passive-hosts.cfg
  • Save and exit the file
  • Create a new object configuration file named passive-hosts.cfg under /usr/local/nagios/etc/objects
vi /usr/local/nagios/etc/objects/passive-hosts.cfg
  • Add the text below to define NAG-REMOTE
define host {
  use            passive-host
  host_name      NAG-REMOTE
  alias          NAG-Remote
  address        10.100.100.200
  hostgroups     passive-hosts
}
  • Add the text below to define a passive service check for CPU Usage on NAG-REMOTE
define service {
   use                     passive_service_check
   host_name               NWO-REMOTE
   service_description     Current Load
   check_command           check_dummy!2!"No Passive Results Received"
   contact_groups          admins
   notification_period     24x7
   flap_detection_enabled  0
   event_handler_enabled   0
   notification_interval   1440
   notification_period     24x7
}
  • Save and exit the file
  • Restart the nagios service by executing the command below:
systemctl restart nagios
  • Go to the nagios web page http://NAG-CENTRAL/nagios and logon
  • Check under Hosts and there will now be new host named NAG-REMOTE showing a status of UNKNOWN.

Previous Page                                                                                                                                          Next Page

Nagios NRDP – Setting Up The Test Environment

Nagios NRDP – Setting Up The Test Environment

This following pages of this article explain how to set up the test environment used for this series of wiki pages. After installing and testing NRDP the next step is to set up a simple test environment where the remote Nagios server NAG-REMOTE and its services are configured for passive monitoring on the central Nagios server NAG-CENTRAL.

For the purposes of this article the hostname will be changed from localhost to NAG-REMOTE on the remote Nagios server NAG-REMOTE. This is being changed as otherwise the $HOSTNAME$ variable sent as part of the check results by the send_nrdp.py client will be localhost.

The following sections of this article will consist of the following:

  • Remote Server – Changing the hostname
  • Remote Server – Changing the initial state for hosts and services
  • Central Server – Configuring a passive host template
  • Central Server – Configuring a passive service template

Remote Server – Changing the hostname

The first step is to rename the Remote Nagios server’s hostname in the configuration file localhost.cfg to ensure that send_nrdp.py sends the correct hostname to the central Nagios server.

To change the hostname perform the following on the remote Nagios server NAG-REMOTE:

  • SSH to NAG-REMOTE as a normal user
  • Switch to root in by executing the command below:
su
  • Edit the localhost.cfg configuration file /usr/local/nagios/etc/objects/localhost.cfg by executing the command below:
vi /usr/local/nagios/etc/objects/localhost.cfg
  • Change the host_name value from localhost to NAG-REMOTE as shown below:
define host {
   use        linux-server
   host_name  NAG-REMOTE
   alias      NAG-Remote
   address    127.0.0.1
}
  • Change the host_name entries for the linux-servers hostgroup definition and all services by executing the following in vi:
:%s/localhost/NAG-REMOTE/
  • Save and exit the file
  • Restart the nagios service by executing the command below:
systemctl restart nagios

Remote Server – Changing the initial state for hosts and services

The next step is to change the initial state settings for hosts and services on the remote Nagios server NAG-REMOTE.  Changing these to Unreachable for Hosts and Unknown for Services will ensure that the first check the remote server does triggers the send_nrdp global event commands and updates the central Nagios server.  In the default configuration, the remote server will not send check results for the initial checks to the central server which means they will show as PENDING until a state change occurs on the remote Nagios server.

This could probably be achieved by setting the initial state on the central Nagios server so that they are presumed to be OK but I prefer for them to turn to the correct state when first checked on the remote Nagios server.

To change the initial states for the hosts and services on the remote Nagios server perform the following:

  • Edit the templates.cfg configuration file /usr/local/nagios/etc/objects/templates.cfg by executing the command below:
vi /usr/local/nagios/etc/objects/templates.cfg
  • Find the generic-host definition and add the line initial_state shown below to set hosts initial state to Unreacheable:
define host {
   name                          generic-host 
   notifications_enabled         1
   event_handler_enabled         1
   flap_detection_enabled        1 
   process_perf_data             1
   retain_status_information     0
   retain_nonstatus_information  1
   notification_period           24x7
   initial_state                 u
   register                      0
}
  • Find the generic-service definition and add the initial_state line shown below to set services initial state to Unknown:
define service {
   name                           generic-service
   active_checks_enabled          1 
   passive_checks_enabled         1 
   parallelize_check              1 
   obsess_over_service            1 
   check_freshness                0 
   notifications_enabled          1
   event_handler_enabled          1
   flap_detection_enabled         1
   process_perf_data              1
   retain_status_information      0
   retain_nonstatus_information   1
   is_volatile                    0
   check_period                   24x7
   max_check_attempts             3
   check_interval                 10
   retry_interval                 2
   contact_groups                 admins
   notification_options           w,u,c,r
   notification_interval          60
   notification_period            24x7
   initial_state                  u
   register                       0
}
  • Save and exit the file
  • Restart the nagios service by executing the command below:
systemctl restart nagios

Central Server – Configuring a passive host template

The next step is to create a passive host template on the central Nagios server NAG-CENTRAL which can then be used to create the host definition for NAG-REMOTE and receive the host check results via NRDP.

To configure a passive host template, perform the following on the central Nagios server NAG-CENTRAL:

  • SSH to NAG-CENTRAL as a normal user
  • Switch to root in by executing the command below:
su -i
  • Edit the template.cfg configuration file /usr/local/nagios/etc/objects/template.cfg by executing the command below:
vi /usr/local/nagios/etc/objects/template.cfg
  • Go to the end of the file and add the following text to configure a passive host definition template definition:
define host {
 name                              passive_host
 notifications_enabled             1
 event_handler_enabled             1
 retain_status_information         0
 retain_nonstatus_information      1
 flap_detection_enabled            1
 process_perf_data                 1
 active_checks_enabled             0
 passive_checks_enabled            1
 notification_period               24x7
 check_period                      24x7
 notification_interval             120
 notification_options              d,u,r
 contact_groups                    admins
 max_check_attempts                10
 check_interval                    5
 retry_interval                    1
 register                          0
}
  • Save and exit the file

Central Server – Configuring a passive service template

The next step is to create a passive service template on the central Nagios server NAG-CENTRAL which can then be used to create the service definitions for NAG-REMOTE and receive the service check results via NRDP.

To configure a passive service template, perform the following on the central Nagios server NAG-CENTRAL:

  • Edit the template.cfg configuration file /usr/local/nagios/etc/objects/template.cfg by executing the command below:
vi /usr/local/nagios/etc/objects/template.cfg
  • Go to the end of the file and add the following text to configure a passive service definition template definition:
define service {
 name                      passive_service_check
 register                  0
 max_check_attempts        1
 check_interval            1
 retry_interval            1
 active_checks_enabled     0
 passive_checks_enabled    1
 notifications_enabled     1
 check_freshness           1
 freshness_threshold       93600
 check_period              24x7
}
  • Save and exit the file

Previous Page                                                                                                                                          Next Page

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 NRDP – Installing and testing NRDP

Nagios NRDP – Installing and testing NRDP

This page of this series explains how to install and configure NRDP (Nagios Remote Data Protocol) on a central Nagios Core server and a remote Nagios Core server.

Full information can be found on the Nagios support site page NRDP – Installing NRDP From Source.

Central Nagios Server Install

The NRDP install on the Central Nagios server will be performed fully as this will be where the passive checks reside and the Remote Nagios server will send check results for processing.

To install NRDP on to the Central Nagios Server NAG-CENTRAL perform the following steps:

  • SSH to NAG-CENTRAL as a normal user
  • Switch to root in Raspian by executing the command below:
sudo -i
  • Update the software and install php-xml by executing the commands below:
apt-get update

apt-get install -y php-xml
  • Download the source and unpack by executing the commands below:
cd /tmp

wget -O nrdp.tar.gz https://github.com/NagiosEnterprises/nrdp/archive/1.5.1.tar.gz

tar xzf nrdp.tar.gz
  • Create the directory /usr/local/nrdp which will store the PHP files, copy the files, and change the permissions by executing the commands below:
cd /tmp/nrdp-1.5.1/

mkdir -p /usr/local/nrdp

cp -r clients server LICENSE* CHANGES* /usr/local/nrdp

chown -R nagios:nagios /usr/local/nrdp
  •  Edit the file /usr/local/nrdp/server/config.inc.php
vi /usr/local/nrdp/server/config.inc.php
  • Locate the section below:
$cfg['authorized_tokens'] = array(
 //"mysecrettoken", // <-- not a good token
 //"90dfs7jwn3", // <-- a better token (don't use this exact one, make your
 own)
);
  • Add the token (ThisIsMyTestNRDPToken) is the token used in this test environment) which is to be used to this section of the config file as shown below:
$cfg['authorized_tokens'] = array(
 "ThisIsMyTestNRDPToken",
 );
  • Save and exit the file
  • Copy the NRDP Apache config file by executing the command below:
cp nrdp.conf /etc/apache2/sites-enabled/
  • Restart Apache by executing the command below:
systemctl restart apache2.service

Remote Nagios Server Install

The NRDP install on the remote Nagios server will only be performed up to the copying of the client files as these are all that is needed on the remote Nagios server.

To install NRDP on to the remote Nagios server NAG-REMOTE perform the following steps:

  • SSH to NAG-REMOTE as a normal user
  • Switch to root in by executing the command below:
su
  • Update the software and install php-xml and php-json by executing the commands below:
yum update

yum install -y php-xml

yum install -y php-json
  • Download the source and unpack by executing the commands below:
cd /tmp

wget -O nrdp.tar.gz https://github.com/NagiosEnterprises/nrdp/archive/1.5.1.tar.gz

tar xzf nrdp.tar.gz
  • Create the directory /usr/local/nrdp which will store the PHP files, copy the files, and change the permissions by executing the commands below:
cd /tmp/nrdp-1.5.1/

mkdir -p /usr/local/nrdp

cp -r clients server LICENSE* CHANGES* /usr/local/nrdp

chown -R nagios:nagios /usr/local/nrdp

Testing NRDP

The final part of this page in the series is to test NRDP is working both locally on the central Nagios server and from the remote Nagios server also.

Central Nagios Server Testing

To test that NRDP is installed and configured correctly perform the following steps:

  • Navigate to NRDP page of the central Nagios server NAG-CENTRAL http://nag-central/nrdp
  • If it hasn’t opened to the Submit Check Result tab select it
  • Enter the token defined in the Central Nagios Server Install section which in this example was ThisIsMyTestNRDPToken.
  • Click on the Submit JSON Check Result button at the bottom of the page and it will show OK
  • SSH to NAG-CENTRAL as a normal user view the /var/log/messages log file by executing the following command:
tail /var/log/messages
  • In the log there should be two entries for the check result tests as shown below:
Dec 5 08:43:32 NAG-CENTRAL nagios: Error: Got host checkresult for '', but no such host can be found
Dec 5 08:43:32 NAG-CENTROL nagios: Error: Got host checkresult for '', but no such host can be found
  • These show that NRDP has received the test check results but cannot process them as no hostname was given.

Remote Nagios Server Testing

To test that NRDP is installed and configured correctly to send check results from the remote Nagios server perform the following steps:

  • SSH to NAG-REMOTE as a normal user
  • Switch to root in by executing the command below:
su
  • Go to the /usr/local/nrdp/clients directory and execute the command below substituting NAG-CENTRAL for your central Nagios server address and ThisIsMyTestNRDPToken with the token defined in the Central Nagios Server Install section :
./send_nrdp.py -u http://NAG-CENTRAL/nrdp/ -t ThisIsMyTestNRDPToken --host=another-host --service="PASSIVE-CPU-CHECK" --state=1 --output="Server is DOWN"
  • SSH to NAG-CENTRAL as a normal user view the /var/log/messages log file by executing the following command:
tail /var/log/messages
  • In the log there should be two entries for the check result tests as shown below:
Dec 5 09:36:02 frontroom nagios: Error: Got host checkresult for 'another-host', but no such host can be found
  • This shows that the remote Nagios server has sent a check result using the send_nrdp.py client script and that the central Nagios server has received the check result but cannot process it as there is no host defined named another-host.

Previous Page                                                                                                                            Next Page

Nagios NRDP – Introduction And Prerequisites

Nagios NRDP – Introduction And Prerequisites

Introduction

Nagios is a an open source monitoring solution for network devices and servers. Nagios NRDP (Nagios Remote Data Protocol) is designed to be a flexible data transport mechanism and processor for Nagios, built on top of web technologies which are becoming a more popular transport mechanism. It is designed with a simple and powerful architecture that allows for it to be easily extended and customized to fit individual users’ needs.

This following pages of this article explain how to configure distributed monitoring in Nagios using NRDP to send check results from a separate Nagios Core server to Passive Hosts and Services on a central Nagios Core server. This configuration is to simulate utilising a separate Nagios monitoring server for a separate data centre or customer data centre with the check results being fed back to a central NOC or managed service providers monitoring server.

Test Environment

The test environment for this set of articles consists of the following:

  • Central Nagios Core monitoring server
    • General Details
      • Name – NAG-CENTRAL
      • IP – 192.168.0.100
    •  Specification
      • Raspberry Pi Model 2
      • Raspian Buster Lite
    • Nagios Core 4.4.5 installed and basic configuration completed
    • Apache installed and nagios integration completed
  • Firewall
    • General Details
      • FIREWALL-REMOTE
      • External IP – 192.168.0.215
      • Internal IP – 10.100.100.215
  • Remote Nagios Core monitoring server
    • General Details
      • Name – NAG-REMOTE
      • IP – 10.100.100.200
    •  Specification
      • ESXi VM, 2vCPUS, 2GB RAM, 20GB Disk
      • CentOS 7 64-Bit
    • Nagios Core 4.4.5 installed and basic configuration completed
    • Apache installed and nagios integration completed

The NAG-REMOTE server sits behind the Remote Firewall with no access allowed from the NAG-CENTRAL server.  The FIREWALL-REMOTE is configured to allow outbound communication on TCP 80 from NAG-REMOTE to NAG-CENTRAL.

Installation Overview

The configuration is broken down in to the following steps which are explained in the subsequent sections of this article :-

  • Installing and testing NRDP
  • Setting up the test environment
  • Central Server – Configuring Passive checks
  • Remote Server – Configuring a send_nrdp Global Event Commands

Prerequisites

In order to install and configure NRDP for distributed monitoring the following pre-requisites must be met :-

Central Monitoring Server

  • Nagios Core 4.4.5 installed and base configuration performed
  • Apache installed and base Nagios configuration performed

Remote Monitoring Server

  • Nagios Core 4.4.5 installed and base configuration performed
  • Apache installed and base Nagios configuration performed

Previous Page                                                                                                                            Next Page

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 – Configuring Global Event Commands Using send_nrdp.py

Nagios – Configuring Global Event Commands Using send_nrdp.py

Today I finally worked out how to configure the send_nrdp.py script as a Global Event Command after scouring the web for the solution.  As with most things Nagios related, the documentation out there is a little light so I thought I’d put this up in case it helps others.

Continue reading Nagios – Configuring Global Event Commands Using send_nrdp.py

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