Nov 11, 2016

How to Install Nagios 4.2.0 on Red Hat, CentOS or Fedora Linux


Nagios is an amazing Open Source monitoring tool which provides you pretty much comprehensive monitoring environment to always keep an eye on your all Workstations, Servers and Network devices whether you want to monitor a data center or just a small business server room.






Using Nagios, you can monitor network enabled devices and their services remotely on a single window. It shows warnings and alerts if something goes wrong within on premises datacenter or DR Site which eventually helps us to predict failure before they occur. It also help us to reduce downtime during peak business hours.

Recently, Nagios released its latest versions of Nagios 4.2.0 and its latest stable release of Nagios plugins 2.1.2 on August 01, 2016.

This Nagios Guide with step by step instructions on how to install latest Nagios 4.2.0 from source (tarball) on RHEL 7.x/6.x/5.x, CentOS 7.x/6.x/5.x and Fedora 24-19 distributions.

The below steps was performed on CentOS 7.2 Linux distribution during the time when this particular article was being written.

How to Install Nagios 4.2.0 and Nagios Plugin 2.1.2

If you follow below mentioned guideline correctly, you will end up with following information.
  1. Nagios and its plugins will be installed under /usr/local/nagios directory.
  2. Nagios will be configured to monitor few services of your local machine (Disk Usage, CPU Load, Current Users, Total Processes, etc.)
  3. Nagios web interface will be available at http://localhost/nagios

 

Install Required Dependencies

You need to install prerequisites Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.2.0 using source. To install these packages, you can use yum default package installer.

yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

 
 
If you are on Fedora then use the following command.

dnf install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

 

Create Nagios User and Group

Create a new nagios user and nagcmd group account and set a password.

useradd nagios
groupadd nagcmd

Now add both the nagios user and the apache user to the nagcmd group.

usermod -G nagcmd nagios
usermod -G nagcmd apache

 

Download Nagios Core 4.2.0 and Nagios Plugin 2.1.2

Create a directory for your Nagios installation and all its future downloads.

mkdir /root/nagios
cd /root/nagios

Now download latest Nagios Core 4.2.0 and Nagios plugins 2.1.2 packages with wget command.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz 

wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

 

Extract Nagios Core and its Plugins

We need to extract downloaded package with tar command as follows.

tar -xvf nagios-4.2.0.tar.gz
tar -xvf nagios-plugins-2.1.2.tar.gz

When you extract these tarballs with tar command, two new folders will appear in that directory.

ls -l
total 13528
drwxrwxr-x. 18 root root     4096 Aug 20  2015 nagios-4.2.0
-rw-r--r--.  1 root root 11142182 Aug 20  2015 nagios-4.2.0.tar.gz
drwxr-xr-x. 15 root root     4096 Aug  1 21:58 nagios-plugins-2.1.2
-rw-r--r--.  1 root root  2695301 Aug  1 21:58 nagios-plugins-2.1.2.tar.gz

 

Configure Nagios Core

First we will configure Nagios Core. We need to go to Nagios directory and run configure command with required prefix as show below.

nagios~]# cd nagios-4.2.0
nagios-4.2.0 ]# ./configure --with-command-group=nagcmd
Sample output:
Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.2.0 08-01-2016 ***:
General Options:
-------------------------
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Install ${includedir}:  /usr/local/nagios/include/nagios
Lock file:  ${prefix}/var/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /bin/mail
Host OS:  linux-gnu
IOBroker Method:  epoll
Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /usr/bin/traceroute
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Now, after configuring we need to Compile and install all the binaries with make command and make install command will install all the needed libraries in your machine and we can proceed further.

make all
make install

Sample output:

*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make[1]: Leaving directory '/root/nagios/nagios-4.2.0'
make install-basic
make[1]: Entering directory '/root/nagios/nagios-4.2.0'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory '/root/nagios/nagios-4.2.0'

Following command will install the init scripts for Nagios.

make install-init

To make nagios work from command line we need to install command-mode.

make install-commandmode

Next, install sample nagios files, please run following command.

make install-config

Sample output:

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

 

Customizing Nagios Configuration

Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.

# vi /usr/local/nagios/etc/objects/contacts.cfg

Sample Output

############################################################################### ############################################################################### # # CONTACTS # ############################################################################### ############################################################################### # Just one contact defined by default - the Nagios admin (that's you) # This contact definition inherits a lot of default values from the 'generic-contact' # template which is defined elsewhere. define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email support@infosbird.com ; *** CHANGE THIS TO YOUR EMAIL ADDRESS **** } 

 

Install and Configure Web Interface for Nagios

We are done with all configuration in the backend, now we will configure Web Interface For Nagios with following command. The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”.

make install-webconf

In this step, we will be creating a password for “nagiosadmin”. After executing this command, please provide a password twice and keep it remember because this password will be used when you login in the Nagios Web interface.

htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin


Restart Apache to make the new settings take effect.

service httpd start                    [On RHEL/CentOS 6/5 and Fedora]
systemctl start httpd.service     [On RHEL/CentOS 7 and Fedora 19 Onwards]

 

Compile and Install Nagios Plugin

We have downloaded nagios plugins in /root/nagios, Go there and configure and install it as directed below.

cd /root/nagios
cd nagios-plugins-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

 

Verify Nagios Configuration Files

Now we are all done with Nagios configuration and its time to verify it and to do so please insert following command. If everything goes smooth it will show up similar to below output.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Sample Output

Nagios Core 4.2.0
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-01-2016
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight check

 

Add Nagios Services to System Startup

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig and systemctl command.

 

On RHEL/CentOS 6/5 and Fedora

chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --add httpd
chkconfig --level 35 httpd on

On RHEL/CentOS 7 and Fedora 19-24

systemctl enable nagios
systemctl enable httpd

Restart Nagios to make the new settings take effect.

service nagios start                [On RHEL/CentOS 6/5 and Fedora]
systemctl start nagios.service    [On RHEL/CentOS 7 and Fedora 19-24]

 

Login to the Nagios Web Interface

Your nagios is ready to work, please open it in your browser with “http://server-ip-address/nagios” or “http://hostname/nagios” and Provide the username “nagiosadmin” and password.

Nagios Web Dashboard


Nagios Host View

Nagios Monitoring Overview

Service View

Process View
Here we have successfully installed and configured Nagios and its Plugins and its ready to monitor your network enabled devices.

 

Upgrade Nagios 3.x to Nagios 4.2.0

If you are already running an older version of Nagios, you can upgrade it anytime. To start upgrade process, you just need to download the latest tar archive of Nagios and configure it through the following commands.

service nagios stop
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz
tar -zxvf nagios-4.2.0.tar.gz
cd nagios-4.2.0
./configure
make all
make install
service nagios start

 

Conclusion

We have completed Nagios installation and configuration process. Now I'll walk you through the steps to add Linux, Windows, Printers, Switches, Routers, Firewalls and other network enabled Devices to your Nagios monitoring Server.

How to Add Linux Host to Nagios Monitoring Server Using NRPE Plugin

Nagios Remote Plugin Executor (NRPE ) allows you to monitor any remote Linux/Unix services or network devices. The NRPE add-on allows Nagios to monitor any local resources like CPU load, Swap, Memory usage, Online users, etc. on remote Linux machines. These local resources are not mostly exposed to external machines,  so that NRPE agent must be installed and configured on the remote machines.

Note: The NRPE addon requires that Nagios Plugins must be installed on the remote Linux machine. Without these, the NRPE daemon will not work and will not monitor anything.

 

Installation of NRPE Plugin

To use the NRPE, you will need to do some additional tasks on both the Nagios Monitoring Host and Remote Linux Host that the NRPE installed on. I will be covering the both installation parts separately.

I assume that you are installing the NRPE on a host that supports TCP wrappers and Xinted daemon installed on it. Most of the modern Linux distributions have these two installed by default. If not, we will install it later during the installation when required.

On a Remote Linux Host
Please use the following instructions to install Nagios Plugins and NRPE daemon on the Remote Linux Host.

 

Install Required Dependencies

We need to install required libraries like gcc, glibc, glibc-common and GD and its development libraries before installing.

yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel





If you are using Fedora 22+ or later version
dnf install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel 

 

Create Nagios User

Create a new nagios user account and set a password.

useradd nagios
passwd nagios

 

Install the Nagios Plugins

Create a directory for installation and all its future downloads.

cd /root/nagios

Now download latest Nagios Plugins 2.1.2 package with wget command.

wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

 

Extract Nagios Plugins

Run the following tar command to extract the source code tarball. tar -xvf nagios-plugins-2.1.2.tar.gz After, extracting one new folder will appear in that directory.

nagios ~]# ls -l
total 2640
drwxr-xr-x. 15 root root    4096 Aug  1 21:58 nagios-plugins-2.1.2
-rw-r--r--.  1 root root 2695301 Aug  1 21:58 nagios-plugins-2.1.2.tar.gz

 

Compile and Install Nagios Plugins

Next, compile and install using following commands

cd nagios-plugins-2.1.2
./configure 
make
make install

Set the permissions on the plugin directory.

chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec


 

Install Xinetd

Most of the systems, its by default installed. If not, install xinetd package using following yum command.

yum install xinetd

If you are on Fedora 22+ or later

dnf install xinetd

 

Install NRPE Plugin

Download latest NRPE Plugin 3.0 packages with wget command.

cd /root/nagios
wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz

Unpack the NRPE source code tarball.

tar xzf nrpe-3.0.tar.gz
cd nrpe-3.0




Compile and install the NRPE addon.

./configure
make all


Next, install the NRPE plugin daemon, and sample daemon config file.

make install-plugin
make install-daemon
make install-daemon-config


Install the NRPE daemon under xinetd as a service.

make install-xinetd
OR
make install-inetd


Now open /etc/xinetd.d/nrpe file and add the localhost and IP address of the Nagios Monitoring Server.

only_from = 127.0.0.1 localhost <nagios_ip_address>

Next, open /etc/services file add the following entry for the NRPE daemon at the bottom of the file.

nrpe            5666/tcp                 NRPE

Restart the xinetd service.

service xinetd restart

 

Verify NRPE Daemon Locally

Run the following command to verify the NRPE daemon working correctly under xinetd.

netstat -at | grep nrpe
tcp        0      0 *:nrpe                      *:*                         LISTEN


If you get output similar to above, means it working correctly. If not, make sure to check the following things.

    Check you’ve added nrpe entry correctly in /etc/services file
    The only_from contains an entry for “nagios_ip_address” in the /etc/xinetd.d/nrpe file.
    The xinetd is installed and started.
    Check for the errors in the system log files for about xinetd or nrpe and fix those problems.

Next, verify the NRPE daemon is functioning properly. Run the “check_nrpe” command that was installed earlier for testing purposes.

/usr/local/nagios/libexec/check_nrpe -H localhost

You will get a following string on the screen, it shows you what version of NRPE is installed:

NRPE v3.0

 

Configure Firewall Rules

Make sure that the Firewall on the local machine will allow the NRPE daemon to be accessed from remote servers. To do this, run the following iptables command.

On RHEL/CentOS 6/5 and Fedora
iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

On RHEL/CentOS 7 and Fedora 19 or later
firewall-cmd --permanent --zone=public --add-port=5666/tcp

Run the following command to Save the new iptables rule so it will survive at system reboots.

On RHEL/CentOS 6/5 and Fedora
service iptables save

 

Customize NRPE commands

The default NRPE configuration file that got installed has several command definitions that will be used to monitor this machine. The sample configuration file located at.

vi /usr/local/nagios/etc/nrpe.cfg

The following are the default command definitions that are located at the bottom of the configuration file. For the time being, we assume you are using these commands. You can check them by using the following commands.

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0


# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 3.90, 4.37, 3.94|load1=3.900;15.000;30.000;0; load5=4.370;10.000;25.000;0; load15=3.940;5.000;20.000;0;


# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1
DISK OK - free space: /boot 154 MB (84% inode=99%);| /boot=29MB;154;173;0;193


# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
PROCS CRITICAL: 297 processes


# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
PROCS OK: 0 processes with STATE = Z


You can edit and add new command definitions by editing the NRPE config file. Finally, you’ve successfully installed and configured NRPE agent on the Remote Linux Host. Now it’s time to install a NRPE component and add some services on your Nagios Monitoring Server.

On Nagios Monitoring Server

Now login into your Nagios Monitoring Server. Here you will need to do following things:
  • Install the check_nrpe plugin.
  • Create a Nagios command definition using the check_nrpe plugin.
  • Create Nagios host and add service definitions for monitoring the remote Linux host.

 

Install NRPE Plugin

Go to the nagios download directory and download latest NRPE Plugin with wget command.

cd /root/nagios
wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz

Unpack the NRPE source code tarball.

tar xzf nrpe-3.0.tar.gz
cd nrpe-3.0

Compile and install the NRPE addon.

./configure
make all
make install-daemon

 

Verify NRPE Daemon Remotely

Make sure that the check_nrpe plugin can communicate with the NRPE daemon on the remote Linux host. Add the IP address in the command below with the IP address of your Remote Linux host.

/usr/local/nagios/libexec/check_nrpe -H <remote_linux_ip_address>

You will get a string back that shows you what version of NRPE is installed on the remote host, like this:

NRPE v3.0

If your receive a plugin time-out error, then check the following things.
  • Make sure your firewall isn’t blocking the communication between the remote host and the monitoring host.
  • Make sure that the NRPE daemon is installed correctly under xinetd.
  • Make sure that the remote Linux host firewall rules blocking the monitoring server from communicating to the NRPE daemon.

Adding Remote Linux Host to Nagios Monitoring Server

To add a remote host you need to create a two new files “hosts.cfg” and “services.cfg” under “/usr/local/nagios/etc/” location.

cd /usr/local/nagios/etc/
touch hosts.cfg
touch services.cfg

Now add these two files to main Nagios configuration file. Open nagios.cfg file with any editor.

vi /usr/local/nagios/etc/nagios.cfg

Now add the two newly created files as shown below.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg

Now open hosts.cfg file and add the default host template name and define remote hosts as shown below. Make sure to replace host_name, alias and address with your remote host server details.

vi /usr/local/nagios/etc/hosts.cfg

## Default Linux Host Template ##
define host{
name                            linux-box               ; Name of this template
use                             generic-host            ; Inherit default values
check_period                    24x7       
check_interval                  5      
retry_interval                  1      
max_check_attempts              10     
check_command                   check-host-alive
notification_period             24x7   
notification_interval           30     
notification_options            d,r    
contact_groups                  admins 
register                        0                       ; DONT REGISTER THIS - ITS A TEMPLATE
}
## Default
define host{
use                             linux-box               ; Inherit default values from a template
host_name                       tecmint                ; The name we're giving to this server
alias                           CentOS 6                ; A longer name for the server
address                         5.175.142.66            ; IP address of Remote Linux host
}

Next open services.cfg file add the following services to be monitored.

vi /usr/local/nagios/etc/services.cfg

define service{
use                     generic-service
host_name               tecmint
service_description     CPU Load
check_command           check_nrpe!check_load
}
define service{
use                     generic-service
host_name               tecmint
service_description     Total Processes
check_command           check_nrpe!check_total_procs
}
define service{
use                     generic-service
host_name               tecmint
service_description     Current Users
check_command           check_nrpe!check_users
}
define service{
use                     generic-service
host_name               tecmint
service_description     SSH Monitoring
check_command           check_nrpe!check_ssh
}
define service{
use                     generic-service
host_name               tecmint
service_description     FTP Monitoring
check_command           check_nrpe!check_ftp
}

Now NRPE command definition needs to be created in commands.cfg file.

vi /usr/local/nagios/etc/objects/commands.cfg

Add the following NRPE command definition at the bottom of the file.

#########################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
##########################################################
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Finally, verify Nagios Configuration files for any errors.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0

Restart Nagios:

service nagios restart

Now go to Nagios Monitoring Web interface at “http://server-ip-address/nagios” or “http://hostname/nagios” and Provide the username “nagiosadmin” and password. Check that the Remote Linux Host was added and is being monitored.


Now, in the next step I'll be showing you how to add Windows host to Nagios monitoring Server.

To add and monitor a Windows Machines you will have follow the below mentioned guideline.
  1. Install NSClient++ addon on the Windows Machine.
  2. Configure Nagios Server for monitoring Windows Machine.
  3. Add new host and service definitions for Windows machine monitoring.
  4. Restart the Nagios Service.
To make this pretty simple and easier, a few steps of configuration we have already done in the Nagios installation.
  1. A check_nt command definition already added to the command.cfg file. This definition command is used by check_nt plugin to monitor Windows services.
  2. A windows-server host template already created in the templates.cfg file. This template allows you to add new Windows host definitions
These two files “command.cfg” and “templates.cfg” files can be found at /usr/local/nagios/etc/objects/ directory. You can modify and add your own definitions that suits your requirement.

 

Installing NSClient++ Agent on Windows Machine

Lets install NSClient++ Agent on the Remote Windows Host. First download the latest stable version NSClient++ 0.3.1 addon source files, which can be obtained from http://sourceforge.net/projects/nscplus/

Once you’ve downloaded latest stable version, unzip the NSClient++ files into a new C:\NSClient++ directory.

Now open a MS-DOS command prompt from the Start Screen –> Run –> type ‘cmd‘ and press enter and change to the C:\NSClient++ directory.

C:\NSClient++

Next, register the NSClient++ service on the system with the following command.

nsclient++ /install

Finally, install the NSClient++ systray with the following command.

nsclient++ SysTray

Go to the Windows Services Manager and right click on NSClient go to Properties and then ‘Log On‘ tab and click the check box that says “Allow service to interact with the desktop“. If it isn’t already allowed, please check the box to allow it to.


Open NSC.INI file located at C:\NSClient++ directory and uncomment all the modules defined in the “modules” section, except for CheckWMI.dll and RemoteConfiguration.dll.

[modules]
;# NSCLIENT++ MODULES
;# A list with DLLs to load at startup.
;  You will need to enable some of these for NSClient++ to work.
; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
; *                                                               *
; * N O T I C E ! ! ! - Y O U   H A V E   T O   E D I T   T H I S *
; *                                                               *
; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
;
; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS!
;RemoteConfiguration.dll
; NSCA Agent is a new beta module use with care!
;NSCAAgent.dll
; LUA script module used to write your own "check deamon" (sort of) early beta.
;LUAScript.dll
; Script to check external scripts and/or internal aliases, early beta.
;CheckExternalScripts.dll
; Check other hosts through NRPE extreme beta and probably a bit dangerous! :)
;NRPEClient.dll


Uncomment the “allowed_hosts” in the “Settings” section and define the IP address of your Nagios Monitoring Server or leave it blank to allow any hosts to connect.

[Settings]
;# ALLOWED HOST ADDRESSES
;  This is a comma-delimited list of IP address of hosts that are allowed to talk to the all daemons.
;  If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password).
;  The syntax is host or ip/mask so 192.168.0.0/24 will allow anyone on that subnet access
allowed_hosts=172.16.27.41

Uncomment the “port” in the “NSClient” section and set to default port ‘12489‘. Make sure to open ‘12489‘ port on Windows Firewall.

[NSClient]
;# NSCLIENT PORT NUMBER
;  This is the port the NSClientListener.dll will listen to.
port=12489


Finally start the NSClient++ service with the following command.

nsclient++ /start

If your properly installed and configured, you should see a new icon in the system tray in yellow circle with a black ‘M‘ inside.

 

Configuring Nagios Server and Add Windows Hosts

Now Login into Nagios Server and add some object definitions in Nagios configuration files to monitor new Windows machine. Open windows.cfg file for editing with Vi editor.

vi /usr/local/nagios/etc/objects/windows.cfg

A sample Windows host definition already defined for the Windows machine, you can simply change the host definition like host_name, alias, and address fields to appropriate values of your Windows machine.

##########################################################
##########################################################
#
# HOST DEFINITIONS
#
##########################################################
##########################################################
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
use             windows-server  ; Inherit default values from a template
host_name       winserver       ; The name we're giving to this host
alias           My Windows Server       ; A longer name associated with the host
address         172.31.41.53    ; IP address of the host
}

Following services are already added and enabled in windows.cfg file. If you wish to add some more other service definitions that needs to be monitored, you can simple add those definitions to same configuration file. Make sure to change the host_name for these all services with host_name defined in the above step.

define service{
use            generic-service
host_name        winserver
service_description    NSClient++ Version
check_command        check_nt!CLIENTVERSION
}


Add the following service definition to monitor the uptime of the Windows server.

define service{
use            generic-service
host_name        winserver
service_description    Uptime
check_command        check_nt!UPTIME
}


Add the following service definition to monitor the CPU utilization on the Windows server and generate a CRITICAL alert if the 5-minute CPU load is 90% or more or a WARNING alert if the 5-minute load is 80% or greater.

define service{
use            generic-service
host_name        winserver
service_description    CPU Load
check_command        check_nt!CPULOAD!-l 5,80,90
}

Add the following service definition to monitor memory usage on the Windows server and generate a CRITICAL alert if memory usage is 90% or more or a WARNING alert if memory usage is 80% or greater.

define service{
use            generic-service
host_name        winserver
service_description    Memory Usage
check_command        check_nt!MEMUSE!-w 80 -c 90
}

Add the following service definition to monitor usage of the C:\ drive on the Windows server and generate a CRITICAL alert if disk usage is 90% or more or a WARNING alert if disk usage is 80% or greater.

define service{
use            generic-service
host_name        winserver
service_description    C:\ Drive Space
check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}

Add the following service definition to monitor the W3SVC service state on the Windows machine and generate a CRITICAL alert if the service is stopped.

define service{
use            generic-service
host_name        winserver
service_description    W3SVC
check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}

Add the following service definition to monitor the Explorer.exe process on the Windows machine and generate a CRITICAL alert if the process is not running.

define service{
use            generic-service
host_name        winserver
service_description    Explorer
check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}

Lastly, uncomment the windows.cfg file in /usr/local/nagios/etc/nagios.cfg.

vi /usr/local/nagios/etc/nagios.cfg

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

Finally, verify the Nagios configuration files for any erros.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors:   0

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

If the verification process throws any error messages, fix those errors until the verification process completes without any error messages. Once’ you fix those errors, restart the Nagios service.

service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.



Now go to Nagios Monitoring Web interface at “http://server-ip-address/nagios” or “http://hostname/nagios” and Provide the username “nagiosadmin” and password. Check that the Remote Windows Host was added and is being monitored.


 

Configuring Nagios Server and Add Network Switch or Router

Post a Comment

 
TECH SUPPORT © 2012 - Designed by INFOSBIRD