Tag Archives: Nagios

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

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:

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

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
  • 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 !

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

Nagios CentOS Remote 2 – Configuring The Nagios Server

Nagios CentOS Remote 2 – Configuring The Nagios Server

The next part in the installation is to configure the nagios server to monitor the remote host.  To configure the nagios server to monitor the remote server perform the following sections.

Confirming Communiction With The Client

The first step in the nagios server configuration is to confirm that it is able to communicate with the remote host.  To confirm communications with the remote host perform the following steps :-

  • In the command prompt on the nagios server execute the following command :-

/usr/lib64/nagios/plugins/check_nrpe -H {Remote Host IP}

E.G. – /usr/lib64/nagios/plugins/check_nrpe -H 10.20.30.40

  • The command will execute and if it is able to communicate with the client machine return something along the lines shown below :-

NRPE v2.12
N.B. The version number shown may be different if a newer version of nrpe has been installed on the remote host

Defining The Host

The next part of the configuration is to define the host to nagios.  To define the host to nagios perform the following steps :-

  • On the nagios server create a new file under/etc/nagios/objects named linux-servers.cfg
  • Edit the newly created file /etc/nagios/objects/linux-servers.cfg and add the text below :-

define host {
 use linux-server
 host_name {Remote Server FQDN Hostname}
 alias {Friendly Remote Server Name}
 address {Remote Server IP Address}
 }

  • Next add in the following text below to create a basic Ping check of the server :-

define service {
 use local-service
 host_name {Remote Server FQDN Hostname}
 service_description check_ping!100.0,20%!500.0,60%
 }

  • Save and Exit the file

Adding The Config File To The Nagios Config File

In order for nagios to utilise the newly created linux-servers.cfg created in the section above it needs adding to the nagios.cfg on the nagios server.  To add the linux-servers.cfg file to the nagios.cfg file perform the following steps: –

  • On the nagios server edit the file under /etc/nagios/nagios.cfg
  •  Locate the line cfg_file=/etc/nagios/objects/localhost.cfg and then add the text below as a new line :-

cfg_file=/etc/nagios/objects/linux-servers.cfg

  • Save and  Exit the file

Adding The Check_nrpe Command

In order to run commands on the remote host the check_nrpe command needs to be defined on the nagios server.  To define the check_nrpe command on the nagios server perform the following steps :-

  • On the nagios server edit the file/etc/nagios/objects/commands.cfg
  • At the bottom of the file add the section of text below :-

define command {

 command_name check_nrpe

 command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

 }

  • Save and Exit the file

Verify The Configuration And Restart Nagios

The next step is to verify that the changes in the previous sections have been made correctly on the server.  To verify the nagios configuration changes perform the following steps :-

  • In the command line of the remote host execute the command below :-

nagios -v /etc/nagios/nagios.cfg

  • The command should return the lines below if the files have been written correctly :-

Total Warnings: 0

Total Errors:   0

Things look okay – No serious problems were detected during the pre-flight check

  • Finally Restart nagios on the server by executing the command below :-

service nagios restart