How to Monitor and Configure a Windows Server Using Nagios

In this post, i will guide you on how to configure windows machine using and will be monitor via nagios server.

Steps:
1. Download the latest stable version of the NSClient++ addon from http://nsclient.org/nscp/downloads
2. There are two alternate ways to install the NSClient++ on windows server.
a) Double click the file if you downloaded the .msi installer. Set the NSClient to ‘nagiospassword‘.
b) Go to this URL and read the manual properly:

    https://webhostinggeeks.com/howto/docs/nagios/monitoring-windows.html
    

3. Modify the nagios.cfg and add server1.cfg line under windows.cfg line.

    [root@server ~]# vi /etc/nagios/nagios.cfg
    
    # Definitions for monitoring a Windows machine
    #cfg_file=/etc/nagios/objects/windows.cfg
    cfg_file=/etc/nagios/objects/server1.cfg
    

4. Make a copy the original windows.cfg config file and rename it to server1.cfg, which is the preferred server name.

    [root@server ~]# cp /etc/nagios/objects/windows.cfg /etc/nagios/objects/server1.cfg
    

5. Define windows services that should be monitored.

    [root@server ~]# vi /etc/nagios/objects/server1.cfg
    
    # 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	server1	; The name we're giving to this host
    	alias		My Windows Server	; A longer name associated with the host
    	address		192.168.2.2	; IP address of the host
    	}
    
    # HOST GROUP DEFINITIONS
    
    # Define a hostgroup for Windows machines
    # All hosts that use the windows-server template will automatically be a member of this group
    
    define hostgroup{
    	hostgroup_name	windows-servers	; The name of the hostgroup
    	alias		Windows Servers	; Long name of the group
    	}
    
    # Create a service for monitoring the version of NSCLient++ that is installed
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	NSClient++ Version
    	check_command		check_nt!CLIENTVERSION
    	}
    
    # Create a service for monitoring the uptime of the server
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	Uptime
    	check_command		check_nt!UPTIME
    	}
    
    # Create a service for monitoring CPU load
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	CPU Load
    	check_command		check_nt!CPULOAD!-l 5,80,90
    	}
    
    # Create a service for monitoring memory usage
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	Memory Usage
    	check_command		check_nt!MEMUSE!-w 80 -c 90
    	}
    
    # Create a service for monitoring C:\ disk usage
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	C:\ Drive Space
    	check_command		check_nt!USEDDISKSPACE!-l c -w 80 -c 90
    	}
    
    # Create a service for monitoring the W3SVC service
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	W3SVC
    	check_command		check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
    	}
    
    # Create a service for monitoring the Explorer.exe process
    # Change the host_name to match the name of the host you defined above
    
    define service{
    	use			generic-service
    	host_name		server1
    	service_description	Explorer
    	check_command		check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
    	}
    

6. Enable Password protection for NSClient. Set the password same as ‘2.a)‘.

    # 'check_nt' command definition
    define command{
            command_name    check_nt
            command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s nagiospassword -v $ARG1$ $ARG2$
            }
    

7. Verify the configuration

    [root@server ~]# /usr/bin/nagios -v /etc/nagios/nagios.cfg
    
    Nagios Core 3.2.3
    Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 10-03-2010
    License: GPL
    
    Website: http://www.nagios.org
    Reading configuration data...
       Read main config file okay...
    Processing object config file '/etc/nagios/objects/commands.cfg'...
    Processing object config file '/etc/nagios/objects/contacts.cfg'...
    Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
    Processing object config file '/etc/nagios/objects/templates.cfg'...
    Processing object config file '/etc/nagios/objects/localhost.cfg'...
    Processing object config file '/etc/nagios/objects/server1.cfg'...
       Read object config files okay...
    
    Running pre-flight check on configuration data...
    
    Checking services...
            Checked 15 services.
    Checking hosts...
            Checked 2 hosts.
    Checking host groups...
            Checked 2 host groups.
    Checking service groups...
            Checked 0 service groups.
    Checking contacts...
            Checked 1 contacts.
    Checking contact groups...
            Checked 1 contact groups.
    Checking service escalations...
            Checked 0 service escalations.
    Checking service dependencies...
            Checked 0 service dependencies.
    Checking host escalations...
            Checked 0 host escalations.
    Checking host dependencies...
            Checked 0 host dependencies.
    Checking commands...
            Checked 24 commands.
    Checking time periods...
            Checked 5 time periods.
    Checking for circular paths between hosts...
    Checking for circular host and service dependencies...
    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
    

8. Restart the Nagios service.

    [root@server ~]# /etc/init.d/nagios restart
    Stopping nagios:                                           [  OK  ]
    Starting nagios:                                           [  OK  ]
    

How to Install and Configure Nagios NRPE

In the previous article, i have guide you on how to install Nagios Core, mainly for network and services monitoring. In this post, i will guide you on how to install Nagios NRPE. Nagios Remote Plugin Executor (NRPE) is a Nagios agent that allows to remotely execute Nagios plugins on other Linux/Unix machines. NRPE can also communicate with Windows agent addons like NSClient++. It allows for monitoring resources such as disk usage, CPU load, etc. Please follow the following steps to install Nagios NRPE on your Nagios server.

Prerequisites
How to Install Nagios on CentOS 5.5

Steps:
1. Install the Nagios NRPE and Nagios-devel. For your information, Nagios-devel is a header files, libraries and development documentation for nagios.

    [root@server ~]# yum --enablerepo=rpmforge install nagios-nrpe nagios-devel
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * addons: ossm.utm.my
     * base: ossm.utm.my
     * epel: ftp.cuhk.edu.hk
     * extras: ossm.utm.my
     * rpmforge: fr2.rpmfind.net
     * updates: ossm.utm.my
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package nagios-devel.i386 0:3.2.3-3.el5.rf set to be updated
    ---> Package nagios-nrpe.i386 0:2.12-1.el5.rf set to be updated
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =====================================================================================
     Package               Arch          Version                 Repository         Size
    =====================================================================================
    Installing:
     nagios-devel          i386          3.2.3-3.el5.rf          rpmforge           42 k
     nagios-nrpe           i386          2.12-1.el5.rf           rpmforge           35 k
    
    Transaction Summary
    =====================================================================================
    Install       2 Package(s)
    Upgrade       0 Package(s)
    
    Total download size: 76 k
    Is this ok [y/N]: y
    Downloading Packages:
    (1/2): nagios-nrpe-2.12-1.el5.rf.i386.rpm                     |  35 kB     00:00
    (2/2): nagios-devel-3.2.3-3.el5.rf.i386.rpm                   |  42 kB     00:00
    -------------------------------------------------------------------------------------
    Total                                                 23 kB/s |  76 kB     00:03
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing     : nagios-nrpe                                                   1/2
      Installing     : nagios-devel                                                  2/2
    
    Installed:
      nagios-devel.i386 0:3.2.3-3.el5.rf         nagios-nrpe.i386 0:2.12-1.el5.rf
    
    Complete!
    

2. Set nrpe to start at boot and start nrpe

    [root@server ~]# chkconfig nrpe on
    [root@server ~]# /etc/init.d/nrpe start
    Starting Nagios NRPE daemon (nrpe):                        [  OK  ]
    

3. Update the /etc/services. At the following line at the bottom of the page.

    [root@server ~]# vi /etc/services
    
    nrpe            5666/tcp                        # NRPE
    

4. Test NRPE daemon install

    [root@server ~]# netstat -at |grep nrpe
    tcp        0      0 server.intranet.local:nrpe  *:*                         LISTEN
    

How to Install Nagios on CentOS 5.5

Nagios is a popular open source system and network monitoring software application. It monitor hosts and services and then alerting users when something wrong has been triggered. It is the powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Below is the steps to install Nagios on CentOS 5.5 server. This tutorial assume that you already installed LAMP (Linux CentOS, Apache, Mysql and PHP) server.

Prerequisites
How to Install Apache Httpd Web Server on Linux
Install or updates the prerequisites. Make sure that all of these packages already installed and properly configured.

    [root@server ~]# yum -y --enablerepo=rpmforge install httpd php gcc glibc glibc-common gd gd-devel
    

Steps :
1. Download and install the rpmforge repository.

For x86 (32-bit) systems

    [root@server ~]# rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
    

For x64 (64-bit) systems

    [root@server ~]# rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
    

2. Install Nagios and Plugins using yum command

    [root@server ~]# yum -y --enablerepo=rpmforge install nagios nagios-plugins nagios-plugins-setuid
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * addons: centos.maulvi.net
    * base: centos.maulvi.net
    * epel: ftp.cuhk.edu.hk
    * extras: centos.maulvi.net
    * rpmforge: fr2.rpmfind.net
    * updates: mirror.yourconnect.com
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package nagios.i386 0:3.2.3-3.el5.rf set to be updated
    ---> Package nagios-plugins.i386 0:1.4.15-2.el5.rf set to be updated
    --> Processing Dependency: fping for package: nagios-plugins
    --> Processing Dependency: perl(Net::SNMP) for package: nagios-plugins
    ---> Package nagios-plugins-setuid.i386 0:1.4.15-2.el5.rf set to be updated
    --> Running transaction check
    ---> Package fping.i386 0:2.4b2-7.el5 set to be updated
    ---> Package perl-Net-SNMP.noarch 0:5.2.0-1.2.el5.rf set to be updated
    --> Processing Dependency: perl(Crypt::DES) for package: perl-Net-SNMP
    --> Running transaction check
    ---> Package perl-Crypt-DES.i386 0:2.05-3.2.el5.rf set to be updated
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =====================================================================================
    Package                    Arch        Version                  Repository     Size
    =====================================================================================
    Installing:
    nagios                     i386        3.2.3-3.el5.rf           rpmforge      3.7 M
    nagios-plugins             i386        1.4.15-2.el5.rf          rpmforge      1.6 M
    nagios-plugins-setuid      i386        1.4.15-2.el5.rf          rpmforge      122 k
    Installing for dependencies:
    fping                      i386        2.4b2-7.el5              epel           30 k
    perl-Crypt-DES             i386        2.05-3.2.el5.rf          rpmforge       37 k
    perl-Net-SNMP              noarch      5.2.0-1.2.el5.rf         rpmforge       96 k
    
    Transaction Summary
    =====================================================================================
    Install       6 Package(s)
    Upgrade       0 Package(s)
    
    Total download size: 5.6 M
    Downloading Packages:
    (1/6): fping-2.4b2-7.el5.i386.rpm                             |  30 kB     00:02
    (2/6): perl-Crypt-DES-2.05-3.2.el5.rf.i386.rpm                |  37 kB     00:00
    (3/6): perl-Net-SNMP-5.2.0-1.2.el5.rf.noarch.rpm              |  96 kB     00:02
    (4/6): nagios-plugins-setuid-1.4.15-2.el5.rf.i386.rpm         | 122 kB     00:03
    (5/6): nagios-plugins-1.4.15-2.el5.rf.i386.rpm                | 1.6 MB     00:28
    (6/6): nagios-3.2.3-3.el5.rf.i386.rpm                         | 3.7 MB     01:07
    -------------------------------------------------------------------------------------
    Total                                                 53 kB/s | 5.6 MB     01:48
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Installing     : fping                                                         1/6
    Installing     : perl-Crypt-DES                                                2/6
    Installing     : nagios-plugins-setuid                                         3/6
    Installing     : nagios                                                        4/6
    Installing     : perl-Net-SNMP                                                 5/6
    Installing     : nagios-plugins                                                6/6
    
    Installed:
    nagios.i386 0:3.2.3-3.el5.rf                 nagios-plugins.i386 0:1.4.15-2.el5.rf
    nagios-plugins-setuid.i386 0:1.4.15-2.el5.rf
    
    Dependency Installed:
    fping.i386 0:2.4b2-7.el5                   perl-Crypt-DES.i386 0:2.05-3.2.el5.rf
    perl-Net-SNMP.noarch 0:5.2.0-1.2.el5.rf
    
    Complete!
    

3. Create the default Nagios user and set a password using htpasswd:

    [root@server ~]# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
    New password:
    Re-type new password:
    Adding password for user nagiosadmin
    

4. Verify default config files using below command :

    [root@server ~]# nagios -v /etc/nagios/nagios.cfg
    
    Nagios Core 3.2.3
    Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 10-03-2010
    License: GPL
    
    Website: http://www.nagios.org
    Reading configuration data...
    Read main config file okay...
    Processing object config file '/etc/nagios/objects/commands.cfg'...
    Processing object config file '/etc/nagios/objects/contacts.cfg'...
    Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
    Processing object config file '/etc/nagios/objects/templates.cfg'...
    Processing object config file '/etc/nagios/objects/localhost.cfg'...
    Read object config files okay...
    
    Running pre-flight check on configuration data...
    
    Checking services...
    Checked 8 services.
    Checking hosts...
    Checked 1 hosts.
    Checking host groups...
    Checked 1 host groups.
    Checking service groups...
    Checked 0 service groups.
    Checking contacts...
    Checked 1 contacts.
    Checking contact groups...
    Checked 1 contact groups.
    Checking service escalations...
    Checked 0 service escalations.
    Checking service dependencies...
    Checked 0 service dependencies.
    Checking host escalations...
    Checked 0 host escalations.
    Checking host dependencies...
    Checked 0 host dependencies.
    Checking commands...
    Checked 24 commands.
    Checking time periods...
    Checked 5 time periods.
    Checking for circular paths between hosts...
    Checking for circular host and service dependencies...
    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
    

5. Configure nagiso service to start at boot

    [root@server ~]# chkconfig nagios on
    

6. Start the nagios service

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

7. Restart apache server

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

8. To login, navigate your browser to http://servername/nagios