AMP AMP

How to add Host into Nagios Server

To add Host into Nagios Server

In this article we will learn the procedures to add Host into Nagios server.

Nagios Server IP - 192.168.5.147
Nagils Host IP   - 192.168.5.146


To install NRPE Services and Nasgios Plugins

Utilize the below command to install the NRPE Service and nagios plugins on Host machine.

root@linuxhelp:~# apt-get install nagios-nrpe-server nagios-plugins -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libntdb1 python-ntdb
Use ' apt-get autoremove'  to remove them.
The following extra packages will be installed:
  libdbi1 libldb1 libmysqlclient18 libnet-snmp-perl libpq5 libsmbclient libtirpc1 libwbclient0 mysql-common nagios-plugins-basic nagios-plugins-common
  nagios-plugins-standard python-ldb python-samba rpcbind samba-common samba-common-bin samba-libs smbclient snmp whois
.
.
.
Selecting previously unselected package nagios-plugins-common.
Preparing to unpack .../nagios-plugins-common_1.5-3ubuntu1_amd64.deb ...
Unpacking nagios-plugins-common (1.5-3ubuntu1) ...
Processing triggers for man-db (2.7.4-1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (225-1ubuntu9) ...
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-common_5.6.31-0ubuntu0.15.10.1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

After installing the dependencies, Open and add the Nagios server IP address into the configuration file.

root@linuxhelp:~# vim /etc/nagios/nrpe.cfg
server_address=192.168.5.147

Then restart NRPE services to make the changes active.

root@linuxhelp:~# service nagios-nrpe-server restart

Make sure that the above change is applied on the host machine.

To configure Nagios server

After configuring the host, login to Nagios Server and do the following steps.
Create new configuration file for host that is to be added into Nagios.

root@linuxhelp:~# vim /usr/local/nagios/etc/servers/host.cfg

Add the following entry in to the newly created file.

# Ubuntu Host configuration file

define host {
        use                          linux-server
        host_name                    linuxhelp
        alias                        Ubuntu Host
        address                      192.168.1.10
        register                     1
}

define service {
      host_name                       linuxhelp
      service_description             PING
      check_command                   check_ping!100.0,20%!500.0,60%
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       linuxhelp
      service_description             Check Users
      check_command           check_local_users!20!50
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       linuxhelp
      service_description             Local Disk
      check_command                   check_local_disk!20%!10%!/
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       linuxhelp
      service_description             Check SSH
      check_command                   check_ssh
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       linuxhelp
      service_description             Total Process
      check_command                   check_local_procs!250!400!RSZDT
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

After adding the entry, test Nagios configuration

root@linuxhelp:~# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

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 13 services.
    Checked 2 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 2 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

Then restart the services.

root@linuxhelp:~# service nagios-nrpe-server restart
root@linuxhelp:~# service apache2 restart
root@linuxhelp:~# service nagios restart

Access the browser and click hosts to view the status of the hosts that is appended to the Nagios

Comment
muhammadehtisham
Nov 18 2020
plz tell me how to check cpu and ram resource.
Add a comment
FAQ
Q
What type of notifications does Nagios support?
A
It supports Email, SMS, and anything you can script on your own.
Q
How to change sender in host-notify-by-sendmailhost and notify-by-sendmailservices commands ?
A
Modify FROM variable in /usr/lib/nagios/plugins/sendmailservices.pl and /usr/lib/nagios/plugins/sendmailhost.pl plugins : my $FROM = 'nagios@localhost.localdomain';
Q
How to restore nagiosadmin password?
A
Change centreon password from console. The default login nagiosadmin/nagiosadmin

# mysql centreon2
mysql> update contact set contact_passwd='426d184e674e6c3020d38bde1d7ed35d' where contact_a
Q
How can I add hosts and services in Centreon, why I have nothing in the monitoring view?
A
You have to export your configuration, go to

Configuration > Monitoring Engines > Generate
Select a poller
Check “Move Export Files” and “Restart Monitoring Engine”
Click on
Q
How to change the default password ?
A
Go to the Centreon web interface. Select Configuration >Users> nagiosadmin then you can change the password Launch this command on the FAN server : # htpasswd -c /etc/nagios/htpassw