Monitoring Windows Machines from Nagios


Here we are going to see how to monitor windows machines using Nagios tools. Please follow the below steps to add the windows hosts in nagios.

Nagios server
Operating System: Centos release 6.4
Hostname: sever.local
IP Address: 192.168.1.5

Windows Machine
Operating System: Windows 7
Hostname: winserver
IP Address: 192.168.1.22

Step 1: Install Prerequisites Package on Windows machine

NSClinet++ Agent is act as proxy agent between windows and nagios.

== Download the latest stable version of the NSClient++ addon from http://files.nsclient.org/legacy/NSClient%2B%2B-0.3.9-x64.zip

== Unzip the NSClient++ files into a new C:\NSClient++ directory

== Open a command prompt and execute the below commads to install the NSClient++ agent

C:\>cd "NSClient++"
C:\NSClient++>
C:\NSClient++>nsclient++ /install
C:\NSClient++>nsclient++ SysTray
C:\NSClient++>services.msc

== Now right click on NSClient go to Properties and in ‘Log On‘ tab and click the check box “Allow service to interact with the desktop“ and click “Apply” and “Ok”.

Step 2: NSClient++ configuration

Edit the NSC.INI file (located in the C:\NSClient++ directory) and make the following changes:

1. In [modules] section, uncomment all the modules, except for CheckWMI.dll and RemoteConfiguration.dll

2. In [Settings] section, uncomment the ‘allowed_hosts’ option and add the IP address of the Nagios server address

3. In [NSClient] seciton, make sure the ‘port’ option is uncommented and set to ‘12489’

4. Optionally require a password for clients by changing the ‘password’ option in the [Settings] section

To start the NSClient++ service run the following command.

C:\NSClient++>nsclient++ /start

If you made above changes properly, a new icon should appear in your system tray. It will be a yellow circle with a black ‘M’ inside.

Step 3: Configuring Nagios host and service

Uncomment the Windows Configuration in nagios configuration file

[root@server.local ~]# vi /usr/local/nagios/etc/nagios.cfg

Search for windows string and uncommment the below line

# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

[root@server.local ~]# vi /usr/local/nagios/etc/objects/windows.cfg

Make the changes accoring to your setup

define host{
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias Windows Server ; A longer name associated with the host
address 192.168.1.22 ; IP address of the Windows host
}

In service definition, make changes according to your need, here i have kept remaining setting as it is.

Save and exit (:wq!)

Step 4: Define the command for check_nt

If you specified a password in the NSClient++ configuration file on the Windows machine, then you need to modify the check_nt command definition.

[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg

define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s PASSWORD -v $ARG1$ $ARG2$
}

Save and exit (:wq!)

Step 5: Restart the nagios daemon

[root@server.local ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If everything is ok then restart the nagios service

[root@server.local ~]# /etc/init.d/nagios restart

Now open your web browser and type http://ipaddress-of-nagios-server/nagios and provide nagiosadmin credentials. Check our newly added windows machine is listed or not.

That’s it.

Nagios Alert via SMS


In our previous post, we have seen how to configure sms gateway server on your environment. With the help of the sms gateway server, we can able to receive the nagios alert. Please follow the below steps.

Assumption:

– Nagios server and clients are configured and running
– Mobile tethering is enabled and support unlimited SMS
– Ozeki NG SMS gateway server is running

All above three assumptions have been explained in this blog previously. Kindly do visit and start monitoring your infrastructure efficiently.

Step 1: Install SMS plugin in nagios server

[root@server.local ~]# vi /usr/local/nagios/libexec/nagios_sms.sh

Copy and paste the below lines

#!/bin/bash
url1="http://127.0.0.1:9501/api?action=sendmessage&username=admin&password= abc123&recipient=0123456789&messagetype=SMS:TEXT&messagedata="
url2="$@"
url2+=$(php -r "echo rawurlencode('$(sed "s/'/\\\\'/g" <<< )');")
url=$url1+$url2
wget -O- "$url"

where,

http://127.0.0.1:9501 — the computer Ozeki NG SMS Gateway has been installed
username=admin — username you use to log into Ozeki NG SMS Gateway
password=abc123 — password of the user
recipient=0123456789 — recipient’s phone number

Step 2: Define command for nagios sms plugin

[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg

Copy and paste the below lines

# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Service Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$ Service $SERVICEDESC$ Description: $SERVICESTATE$ Time: $LONGDATETIME$"

}

# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Host Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$, Time: $LONGDATETIME$"
}

Save and Exit (:wq!)

Step 3: Define contacts

[root@server.local ~]# vi /usr/local/nagios/etc/objects/contacts.cfg

Copy and insert the below lines in nagiosadmin template

service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms

It looks like below changes;

define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
email nagios@localhost
}

Save and Exit (:wq!)

Step 4: Restart the nagios

[root@server.local ~]# /etc/init.d/nagios restart

That’s it.. Now nagios alerts are triggered to SMS gateway server and finally recipient start receiving alerts.

Cool 🙂

Nagios upgrade 3.x to 4.x


It is recommended to keep your nagios server up-to-date. Below steps explain how to upgrade your existing nagios core.

Let’s assume your current nagios core release is 3.5.1 and you want to upgrade to 4.0.8 release.

Step 1: Download the latest nagios core stable release

[root@server.local ~]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz

Step 2: Remove old files

Removed the following old HTML files that were used by the web frontend. They have been replaced by PHP equivalents.

[root@server.local ~]# rm /usr/local/nagios/share/{main,side,index}.html

Step 3: Stop nagios services

[root@server.local ~]# /etc/init.d/naigos stop

Step 4: Install the latest nagios release

[root@server.local ~]# tar –zxvf nagios-4.0.8.tar.gz
[root@server.local ~]# cd nagios-4.0.8
[root@server.local ~]#./configure --with-command-group=nagcmd
[root@server.local ~]# make all
[root@server.local ~]# make install

Step 5: Start nagios services

Before starting nagios services, verify your configuration files. Correct any errors shown here before proceeding with the next step.

[root@server.local ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@server.local ~]# /etc/init.d/nagios start

Setup Nagios Checker – Firefox/Chrome


Just by looking the browser status bar, we can keep track on what is going on with your servers and applications by using the nagios checker browser addon.

It is available on both Mozilla Firefox and Google Chrome browser.

– Mozilla Firefox

Click on Tools -> Add-ons -> Select ‘Nagios Checker’ -> Options, now settings dialog box will display on screen.

Click “Add New”, In general tab, specify the nagios server name. Click “Nagios Web Interface”, enter nagios server link address (http://<nagios-ipaddress/nagios/cgi-bin/status.cgi) with nagios username and password.

Click Ok, it will displays a nagios icon in the status bar at the bottom.

We can also right click on this icon and jump the nagios web UI directly.

– Google Chrome

Download and Install Nagios checker from google and restart the browser.

Go to Tools -> Extensions -> Click ‘Options’ -> Click ‘Server Tab’, now enter nagios web url (http://<nagios-ipaddress/nagios/cgi-bin/status.cgi)

Enter nagios username and password in next text box.

Now nagios icon will display ( next to address bar). Click on the icon to see additional information.

HP ProLiant Server – Hardware monitor using SNMP & Nagios


Manually installing HP SIM

Verify that SNMP & hp-snmp-agent is installed by executing the following command

[root@client.local ~]# rpm -qa | grep snmp
[root@client.local ~]# rpm -qa | grep hp-snmp

If above packages are not installed, please install it before proceeding the HP SIM Installation

Step 1: HP SNMP Agent

Previously, this was known as hpasm, but now HP renamed it to

• hp-health
• hp-snmp-agents

Step 2: HP Yum Repositories

There is a dedicated Redhat Repository by HP, which is configured like the following.

[root@client.local ~]# vim /etc/yum.repos.d/hp.repo
[HP-Proliant]
name=HP Proliant Red Hat Enterprise Linux $releasever - $basearch
#baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
baseurl=http://downloads.linux.hp.com/SDR/downloads/ProLiantSupportPack/RedHat/$releasever/$basearch/current/
#http://downloads.linux.hp.com/SDR/downloads/ProLiantSupportPack/RedHat/5/x86_64/current/
enabled=1
gpgcheck=1
gpgkey=http://downloads.linux.hp.com/SDR/downloads/ProLiantSupportPack/GPG-KEY-ProLiantSupportPack

Step 3: Installation

yum remove hpasm is required, as it is deprecated, and will cause conflicts!

[root@client.local ~]# yum install hp-snmp-agents hp-health hpacucli

Step 4: SNMP Configuration

Do not forget to stop the SNMP services before making the changes.

Save the old configuration file and make sure the new configuration file have the correct permissions

[root@client.local ~]# cd /etc/snmp/
[root@client.local ~]# cp snmpd.conf snmpd.conf.old
[root@client.local ~]# vi snmpd.conf

Add the following in first line of snmpd.conf file

rocommunity TEST-Server
trapsink 192.168.1.5

Configure Linux to start SNMP services on each reboot with the chkconfig

[root@client.local ~]# chkconfig snmpd on
[root@client.local ~]# /etc/init.d/snmpd start

Test whether SNMP can read the system and interface MIBs using the snmpwalk command.

[root@client.local ~]# snmpwalk -v 1 TEST-Server -c localhost system
[root@client.local ~]# snmpwalk -v 1 TEST-Server -c localhost interface

Test the snmp is working from any other linux machine.

[root@server.local ~]# snmpwalk -v 1 TEST-Server -c client.local system
[root@server.local ~]# snmpwalk -v 1 TEST-Server -c client.local interface
[root@server.local ~]# snmpwalk -v 1 TEST-Server -c client.local .1.3.6.1.4.1.232

Step 5: Nagios Configuration

1. Download and install check_hpasm plugin

[root@client.local ~]# wget http://labs.consol.de/download/shinken-nagios-plugins/check_hpasm-4.6.3.2.tar.gz
[root@client.local ~]# tar zxvf check_hpasm-4.6.3.2.tar.gz
[root@client.local ~]# cd check_hpasm-4.6.3.2
[root@client.local ~]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl --with-noinst-level=ok --enable-perfdata --enable-hpacucli
[root@client.local ~]# make
[root@client.local ~]# make install

2. Check whether check_hpasm plugin working

[root@client.local libexec]# ./check_hpasm
OK - System: 'proliant dl360 g5', S/N: 'AAAAAAAAAA', ROM: 'P58 10/11/2009', hardware working fine

3. Sudo configuration changes

[root@client.local ~]# visudo

Add the following lines in EOF

nagios ALL=(ALL) NOPASSWD: /sbin/hpasmcli
nagios ALL=(ALL) NOPASSWD: /usr/local/nagios/libexec/check_hpasm
Defaults:nagios !requiretty

4. Now execute step 2 as nagios user, if everything is working fine

[nagios@client.local libexec]$ /usr/local/nagios/libexec/check_hpasm
OK - System: 'proliant dl360 g5', S/N: 'AAAAAAAAAA', ROM: 'P58 10/11/2009', hardware working fine