Install and Configure Monit


=== From Wiki ===

Monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. It’s a daemon that wakes up every once in a while, goes through a list of things it is configured to check, and if something is not as it should be, takes a corrective action.

Monit tool is available in EPEL repository. Here i have already installed EPEL repository, if you need to install then please type epel in search box and follow the steps to perform the same.

Operating System: CentOS 6.4
Hostname: server
IP Address: 192.168.1.6

Step 1: Install prerequisites package

[root@server ~]# yum install -y monit httpd

Step 2: Monit configuration

[root@server ~]# vi /etc/monit.conf

Uncomment the following lines
....
....
set daemon 120
....
....
set httpd port 2812 and
use address localhost
allow localhost
allow admin:monit
....
....

Save and exit (:wq!)

Step 3: Start the monit and apache daemon

[root@server ~]# /etc/init.d/monit start
Starting monit: [ OK ]

[root@server ~]# /etc/init.d/httpd start

[root@server ~]# chkconfig --level 35 monit on
[root@server ~]# chkconfig --level 35 httpd on

Now open your web browser and type http://localhost:2812 or http://ipaddress:2812, you will be asked to enter the username and passowrd.

Username: admin
Password: monit

Check the monit log for more details.

[root@server ~]# tail -f /var/log/monit
[IST Apr 17 10:14:48] info : Starting monit HTTP server at [localhost:2812]
[IST Apr 17 10:14:48] info : monit HTTP server started
[IST Apr 17 10:14:48] info : Monit started
[IST Apr 17 10:15:48] info : Monit has not changed

Step 4: Add service to the monit

Now it’s the time to add your critical service to monitor. Here i am going to use my apache server and this will be monitor by monit tool for every 2 mins.

[root@server ~]# vi /etc/monit.conf

Add the below lines in EOF

check process apache with pidfile /var/run/httpd.pid
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"

Save and exit (:wq!)

Now check your monit web interface, the newly added apache service is start monitor by monit.

Step 5: Monit Testing

Stop the apache daemon to test our monit tool is working or not.

[root@server ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]

[root@server ~]# /etc/init.d/httpd status
httpd is stopped

[root@server ~]# tail -f /var/log/monit
[IST Apr 17 10:30:15] info : Starting monit HTTP server at [localhost:2812]
[IST Apr 17 10:30:15] info : monit HTTP server started
[IST Apr 17 10:30:15] info : Monit started
[IST Apr 17 10:31:15] info : Monit has not changed
[IST Apr 17 10:32:15] error : 'apache' process is not running

Check the same in web interface, the apache will show the “Does not exist” status. Wait for 2 mins our monit tool will automatically start the apache service.

After 2 mins check the apache status and log

[root@server ~]# /etc/init.d/httpd status
httpd (pid 1704) is running...

[root@server ~]# tail -f /var/log/monit
[IST Apr 17 10:30:15] info : Starting monit HTTP server at [localhost:2812]
[IST Apr 17 10:30:15] info : monit HTTP server started
[IST Apr 17 10:30:15] info : Monit started
[IST Apr 17 10:31:15] info : Monit has not changed
[IST Apr 17 10:32:15] error : 'apache' process is not running
[IST Apr 17 10:32:15] info : 'apache' trying to restart
[IST Apr 17 10:32:15] info : 'apache' start: /etc/init.d/httpd
[IST Apr 17 10:33:15] info : 'apache' process is running with pid 1704

That’s it!! Monit has started the apache services automatically without any human intervention.

Hope you enjoy this post…. Thanks 🙂

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

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

Installation of Nagios Mobile


We are able to access the nagios core from mobile itself. For that we need to do some nagios configuration changes on the server end.

Follow the below steps to access to mobile Nagios interface.

Prerequisites

Nagios Core already installed and running
Php 5.1 or greater

Downloading and Unpacking

[root@server.local ~]# cd /tmp
[root@server.local ~]# wget http://assets.nagios.com/downloads/exchange/nagiosmobile/nagiosmobile.tar.gz
[root@server.local ~]# tar zxf nagiosmobile.tar.gz
[root@server.local ~]# cd nagiosmobile

Apache configuration

By default Nagios Mobile will be installed to /usr/local/nagiosmobile. If you want a different target directory for the installer, update the INSTALL.php file:

//target directory where nagiosmobile's web files will be stored
define('TARGETDIR',"/usr/local/nagiosmobile");

If your installation is not on a CentOS / RHEL distribution, then you’ll also need to update the file location for your apache configurations directory.

//target directory where your current apache configuration directory is located
define('APACHECONF',"/etc/httpd/conf.d");
//default for ubuntu/debian installs
//define('APACHECONF',"/etc/apache2/conf.d");

Run the installation script

[root@server.local naigosmobile]# ./INSTALL.php
Copying apache configuration file...
Creating web directory...
Copying files...
Cleaning up...
Restarting apache...
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
Checking for file locations...
Script Complete

Access Nagios Mobile

After successful installation, you can access the Nagios Mobile interface through address in a browser

http://localhost/nagiosmobile