You are currently viewing Nagios: A Comprehensive Guide to Installation and Configuration

Nagios: A Comprehensive Guide to Installation and Configuration

  • Post author:
  • Post category:IT

Table of Contents

Nagios: An Open Source Monitoring Tool for Comprehensive IT Infrastructure Health

Nagios is an open-source monitoring tool that empowers you to oversee the availability and well-being of your entire IT infrastructure, encompassing servers, applications, network devices, and more. It excels in system monitoring, categorizing it into two primary areas:

Hosts: Covering servers, routers, switches, and more.
Services: Monitoring various services and applications.

Nagios excels in several monitoring aspects, including:
Server monitoring
Application monitoring
SNMP monitoring
Log monitoring

Nagios server-agent architecture

  • Nagios server is installed on a host
  • Plugins are installed on hosts to be monitored

Nagios Plugin Architecture

Four states in Nagios = Ok, Warning, Critical and Unknown

Soft and Hard States:

When the status of a host/service changes, it’s taken as a soft state in Nagios.

Rechecks performed a couple times are required to identify the state as a hard state. Configure Nagios to send notification only to send a hard state and not soft states notifications.

Nagios Installation

Ubuntu – on the Nagios Server

  1. create a shell script – nagiosinstall.sh and copy the code below and save it. Internet connection is required to use this method.
  2. chmod +x nagiosinstall.sh
  3. execute the scrip ./nagiosinstall.sh
apt-get update
apt-get install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.4 libgd-dev
apt-get install -y openssl libssl-dev
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
tar xzf nagioscore.tar.gz
cd /tmp/nagioscore-nagios-4.4.6/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
make install-groups-users
usermod -a -G nagios www-data
make install
make install-daemoninit
make install-commandmode
make install-config
make install-webconf
a2enmod rewrite
a2enmod cgi
ufw allow Apache
ufw reload
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
systemctl restart apache2.service
systemctl start nagios.service
systemctl status nagios.service

RedHat: on the Nagios Server

dnf install -y gcc glibc glibc-common perl httpd php wget gd gd-devel
dnf install openssl-devel
dnf update -y

#Downloading the Source
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz

#Compile
cd /tmp/nagioscore-nagios-4.4.14/
./configure
make all

#Add user and groupcd /tm  
make install-groups-users
usermod -a -G nagios apache

#Install Binaries
make install

#Install Service/Daemon
make install-daemoninit
systemctl enable httpd.service

#Install Commandmode
make install-commandmode

#Install Configuration Files
make install-config

#Install Apache Config Files
make install-webconf

#Configure Firewall
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent

#Create nagiosadmin User Account
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

#Start Apache Web Server
systemctl start httpd.service

#systemctl start httpd.service
systemctl start nagios.service

Test Nagios Installation

Access the Nagios dashboard http://<IP of Nagios Server>/nagios

Install Nagios Plugin

Nagios plugin needs to be installed separately as it does not come with Nagios Core installation package.

  • Plugins are standalone extensions to Nagios Core
  • binaries or executable scripts

Frequently used plugins

  • Email Server monitoring plugins – check_pop, check_imap
  • Database monitoring plugins – check_mysql, check_pgsql
  • Storage space monitoring plugins – check_swap, check_disk
  • Resource monitoring plugins – check_load, check_procs

On the Nagios Server:

  1. create a shell script – nagiosplugininstall.sh and copy the code below and save it. Internet connection is required to use this method.
  2. chmod +x nagiosplugininstall.sh
  3. execute the scrip ./nagiosplugininstall.sh
VER=2.4.6
#Download Nagios Plugins
wget https://nagios-plugins.org/download/nagios-plugins-$VER.tar.gz
tar xzf nagios-plugins-${VER}.tar.gz
#configure the Nagios Plugins
cd nagios-plugins-${VER}
./configure
#Compile the Nagios Plugins
make
#install Nagios Plugins
make install
#verify
ls /usr/local/nagios/libexec/

Nagios Upgrade

Check the Nagios dashboard for the version, if the version is lower than what is availble perform the Nagios upgrade.

  1. create a shell script – nagiosupgrade.sh and copy the code below and save it. Internet connection is required to use this method.
  2. chmod +x nagiosupgrade.sh
  3. execute the scrip ./nagiosupgrade.sh
#!/bin/sh
#stop the Nagios Service
systemctl stop nagios.service
cd /tmp
wget -O nagioscore.tar.gz  https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.9.tar.gz
tar xzf nagioscore.tar.gz
cd /tmp/nagioscore-nagios-4.4.9/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
make install
make install-daemoninit
systemctl start nagios.service
systemctl status nagios.service

Preflight check: Check compatibility issues after making any changes

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

Default Host in Nagios

  • default host monitored is localhost where Nagios is installed
  • configuration file for localhost at /usr/local/nagios/etc/objects/localhost.cfg

Example: Creating host template, host and services

Host Template : linux-server.cfg

# Linux host definition template - This is NOT a real host, just a template!

define host{
        name                   linux-server            ; The name of this host template
        use                     generic-host            ; Inherit default values from the generic-host template
        check_period            24x7                    ; By default, Windows servers are monitored round the clock
        check_interval          5                       ; Actively check the server every 5 minutes
        retry_interval          1                       ; Schedule host check retries at 1 minute intervals
        max_check_attempts      10                      ; Check each server 10 times (max)
        check_command           check-host-alive        ; Default command to check if servers are "alive"
        notification_period     24x7                    ; Send notification out at any time - day or night
        notification_interval   30                      ; Resend notifications every 30 minutes
        notification_options    d,u,r,s                 ; Only send notifications for specific host states
        contact_groups          admins                  ; Notifications get sent to the admins by default
        hostgroups             linux-servers   ; Host groups that Linux servers should be a member of
        register                0                       ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }

Host configuration file nagiosclient.cfg

define host {
      use          linux-server
      host_name    NagiosClient
      alias        NgClient
      address      10.0.0.6
}

define hostgroup  {
        hostgroup_name      linux-server
        alias                lsg
        members              NagiosClient
}

define service {

    use                     local-service           ; Name of service template to use
    host_name               NagiosClient
    service_description     PING
    check_command           check_ping!100.0,20%!500.0,60%
}

Add the new host file to nagios.cfg file

Everytime we create the files that we want Nagios to use, we must tell Nagios the file paths.

cfg_file=/usr/local/nagios/etc/objects/nagiosclient.cfg
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
systemctl restart nagios.service

For the plugins to work, we need to make sure the following three files are located in the /usr/loca/nagios/objects are properly configured:

hosts.cfg
services.cfg
commands.cfg

Nagios Objects

  • Commands: Command definitions describe how host/service checks should be done. They are also used to specify how notifications about problems or event handlers should work. Commands defined in Nagios tell how it can perform checks, such as what commands to run to check if a database is working properly, how to check if SSH, SMTP, or FTP servers are properly working, or if the DHCP server is assigning IP addresses correctly.
  • Time Periods : Time periods are definitions of dates and times during which an action should be performed or specific people should be notified. These describe ranges of days and times and can be reused across various operations.
  • Host and host groups : Host definition also specifies when and how the system should be monitored, as well as who will be contacted regarding any problem related to this host. It also describes how often the host should be checked, how retrying the checks should be handled, and details regarding how the notifications about problems should be sent out. Nagios offers the hostgroup objects that are a group of one or more machines. This allows managing hosts or adding services to groups or hosts more efficiently.
  • Services : Services are objects that describe a functionality that a particular host provides. This can be virtually anything—network servers such as NFS or FTP, resources such as storage space, or CPU load. A service is always tied to a host that it is running.
  • Contact and Contact Groups : Contacts define people who can either be owners of specific machines or people who should be contacted in case of problems.
  • Notifications : Notifications notify you about the alerts, whereas alerts only let you know about the changes in the host or service state. Not all alerts are to be notified.
  • Escalations: Happen when there are problems that persist for a longer duration – hostescalation, serviceescalation

Monitor Remote Host using NRPE plugin

Nagios Remote Plugin Executor (NRPE) is a plugin that allows you to remotely execute Nagios plugins on other Linux/Unix machines.

  • NRPE for Linux Systems
  • NSClient for Windows Systems

Components running on:
Nagios Server: Nagios + check_nrpe
Remote Monitored Host: NRPE

1. On the Nagios Server – install check_nrpe plugin

install_nrpe.sh

#!/bin/sh
useradd nagios
curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.0/nrpe-4.1.0.tar.gz
sudo tar zxf nrpe-4.1.0.tar.gz
cd nrpe-4.1.0/
./configure
make check_nrpe
make install-plugin

2. Define commands used in the check_nrpe plugin. Access the command.cfg

#defind the check_nrpe command
define command {
  comand_name  check_nrpe
  command_line  $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ $ARG2$
}

3. On the Remote Monitored Host (Monitored Server):Setup the NRPE daemon on the monitored/remote host

Install NRPE: Ensure that NRPE is installed and configured on the remote host. You can typically install it using your operating system’s package manager. For example, on a Red Hat-based system:

install_nrpe_daemon.sh

#!/bin/sh
apt-get update
apt-get install -y autoconf gcc libc6 libmcrypt-dev make \
	libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl \
	gettext
useradd nagios
curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.0/nrpe-4.1.0.tar.gz
sudo tar zxf nrpe-4.1.0.tar.gz
cd nrpe-4.1.0/
./configure
make nrpe
make install-daemon
make install-config
make install-init
sysemctl start nrpe.service
systemctl status nrpe.service

4. In the configuration file for the NRPE nrpe.cfg available at /usr/local/nagios/etc, provide the Nagios Server details as one of the allowed hosts for the NRPE daemon.

allowed_hosts=127.0.0.1,::1,10.0.0.5
systemctl start nrpe.servic

NRPE must explicitly enable every command its allowed to execute on behalf of the Nagios server. The nrpe.cfg lists command that are authorized to run. If a client asks NRPE to run a command it does not know about, NRPE will simply refuse to execute it.NRPE is configure this way by default to prevent injection attack.

cat /etc/nrpe.cfg
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 10 -c 5
command[check_boot]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /boot
command[check_devshm]=/usr/lib64/nagios/plugins/check_disk -w 5% -c 3% -p /dev/shm
command[check_home]=/usr/lib64/nagios/plugins/check_disk -w 10% -c 5% -p /home
command[check_opt]=/usr/lib64/nagios/plugins/check_disk -w 10% -c 5% -p /opt
command[check_root]=/usr/lib64/nagios/plugins/check_disk -w 10% -c 5% -p /
command[check_tmp]=/usr/lib64/nagios/plugins/check_disk -w 10% -c 5% -p /tmp
command[check_var]=/usr/lib64/nagios/plugins/check_disk -w 10% -c 5% -p /var


5. Example on the Nagios Server , create a service check for the remote host that monitors the average load on the system. Access nagiosclient.cfg (configuration file of our remote monitored host)

define service {
  use                generic-service
  host_name          nagiosclient
  service_description  Load
  check_command        check_nrpe!check_load!-n
}
  • use: Refers to predefined templates like linux-server or generic-service. Modify them according to your configuration.
  • host_name: Should match the host_name defined in the remote host’s NRPE configuration.
  • check_command: Specifies the check you defined in the remote host’s nrpe.cfg. In this example, it’s check_nrpe!check_load.
  • the check_command check_nrpe!check_load!-n tells Nagios to use the NRPE mechanism to execute the check_load plugin on the remote host. The -n flag is specific to the check_load plugin and instructs it to provide performance data as part of the check results. This allows Nagios to collect and display performance data for system load monitoring.

Nagios Custom Plugin

Creating a custom shell plugin for Nagios to monitor the percentage of space used on a specific mount point is a common task. You can use the df command to retrieve disk space information and then parse the output to calculate the percentage used.

1. Script that measures the percentage of space used on any mount point and provide you with a status. Place the script on the remote monitored server.

#!/bin/bash

calculate_disk_usage() {
    # Calculate disk usage
    USED_DISK_SPACE=$(df -h "$MOUNT_PATH" | awk 'NR > 1 { sub(/%/, "", $5); print $5 }')

    if [ "$USED_DISK_SPACE" -lt 80 ]; then
        echo "OK - $USED_DISK_SPACE% of disk space used."
        exit 0
    elif [ "$USED_DISK_SPACE" -ge 80 ] && [ "$USED_DISK_SPACE" -le 90 ]; then
        echo "WARNING - $USED_DISK_SPACE% of disk space used."
        exit 1
    elif [ "$USED_DISK_SPACE" -gt 90 ] && [ "$USED_DISK_SPACE" -le 100 ]; then
        echo "CRITICAL - $USED_DISK_SPACE% of disk space used."
        exit 2
    else
        echo "UNKNOWN - $USED_DISK_SPACE% of disk space used."
        exit 3
    fi
}

if [ -z "$1" ]; then
    echo "Missing parameters!"
    exit 3
else
    MOUNT_PATH="$1"
fi

calculate_disk_usage

2. Save the script:

Save the script to a location on the target server where NRPE is installed, typically in the NRPE plugin directory. For example, save it as /usr/lib/nagios/plugins/check_disk_space.sh. Ensure it’s executable:

chmod +x /usr/lib/nagios/plugins/check_disk_space.sh

2. Access the nrpe.cfg configuration file and a new command that uses our new plugin script, along with the mount.

command[check_disk_usage]=/usr/local/nagios/libexec/check_disk_usage.sh 
systemctl restart nrpe.service

3. Configure Nagios

Add a service definition in your Nagios configuration to use the custom script. You can do this in your nagiosclient.cfg files.

On Nagios Server, access the remote host configuration file nagiosclient.cfg and add a new service – provide the command that checks for the disk usage using NRPE.

Example service definition in nagiosclient.cfg:

define service {
  use                local-service
  host_name          nagiosclient
  service_description  Disk Usage a /
  check_command        check_nrpe!check_disk_usage
}
systemctl restart nagios.service

Creating Maintainable Configurations

For optimal configuration management, it is advisable to employ a compartmentalized structure by storing distinct object types within dedicated folders. This approach ensures that configurations for similar objects are logically grouped together. To achieve this, it is recommended to create folders for each object type as outlined below:

objects
│   ├── commands
│   │   └── local
│   │       └── check_local_disk.cfg
│   ├── commands.cfg
│   ├── contacts
│   │   ├── generic-contact.cfg
│   │   ├── groups
│   │   │   └── admins.cfg
│   │   └── users
│   │       └── nagiosadmin.cfg
│   ├── generic-contact.cfg
│   ├── hostgroups
│   │   ├── virtual-linux-server.cfg
│   │   ├── windows-servers.cfg
│   │   └── windows-workstations.cfg
│   ├── network
│   │   ├── customer-endpoint.cfg
│   │   ├── customer-endpoint-template.cfg
│   │   └── generic-network-template.cfg
│   ├── nodes
│   │   ├── linux
│   │   │   ├── ipa01.bomzan.net.cfg
│   │   │   ├── ipa-client.bomzan.net.cfg
│   │   │   ├── mongo-db1.bomzan.net.cfg
│   │   │   └── mongo-db2.bomzan.net.cfg
│   │   └── windows
│   │       ├── servers
│   │       │   ├── w219-apps.bomzan.net.cfg
│   │       │   ├── w2k19-dc02.bomzan.net.cfg
│   │       │   ├── w2k19-dc03.bomzan.net.cfg
│   │       │   ├── w2k19-exch.bomzan.net.cfg
│   │       │   ├── w2k19-sfb.bomzan.net.cfg
│   │       │   ├── w2k19-sp.bomzan.net.cfg
│   │       │   └── w2k19-sql.bomzan.net.cfg
│   │       └── workstations
│   │           ├── win10-01.bomzan.net.cfg
│   │           └── win10-02.bomzan.net.cfg
│   ├── services
│   │   ├── generic-service-template.cfg
│   │   ├── ping-service-template.cfg
│   │   └── remote-service-template.cfg
│   ├── templates
│   │   ├── generic-host-template.cfg
│   │   ├── virtual-linux-server-template.cfg
│   │   ├── windows-server-template.cfg
│   │   └── windows-workstation-template.cfg

You will have to tell Nagios to process all configuration files in a particular directory as follow. Add the following to nagios.cfg located at /usr/loca/nagios/etc

cfg_dir=/usr/local/nagios/etc/objects/hostgroups
cfg_dir=/usr/local/nagios/etc/objects/nodes
cfg_dir=/usr/local/nagios/etc/objects/services
cfg_dir=/usr/local/nagios/etc/objects/contacts
cfg_dir=/usr/local/nagios/etc/objects/templates

Creating single definition per file

example – if you want to create an admin user – create a contacts folder and then create single definition file or separate configuration file for your admin contact. admin.cfg

/user/local/nagios/etc/objects/contacts/admin.cfg
define contact  {
  contact_name      admin  
  use                generic-contact
  alias              Nagios Admin
  email              admin@nagios
}

define contactgroup  {
  contractgroup_name      admin  
  alias                    Nagios Administrators  
  members                  nagiosadmin,admin
}

Sample .cfg files

/contacts/users/nagiosadmin.cfg

define contact{
        contact_name    nagiosadmin
        use             generic-contact
        alias           Nagios Admin
        email           admin@bomzan.net
}

/hostgroups/lvirtual-linux-server.cfg

define hostgroup {
        hostgroup_name  virtual-linux-servers ;
        alias           Linux Virtual Servers ;
}

/network/customer-endpoint.cfg

define host {
        use             customer-endpoint
        host_name       abcd
        address         64.187.239.229
}

define service{
        use                     ping-service
        host_name               abcd dns
        service_description     PING
        check_command           check_ping!200.0,20%!600.0,60%
}

/nodes/ipa01.bomzan.com

define host{
        use                     virtual-linux-server
        host_name               mongo-db1.bomzan.net
        alias                   mongo-db1.bomzan.net
        address                 192.168.10.145
        notes                   Rocky Linux Server
        host_groups             virtual-linux-servers
}

#define service{
#       use                     generic-service
#       host_name               mongo-db1.bomzan.net
#       service_description     CPU Load
#       check_command           check_nrpe!check_load!-n
#}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     Swap Usage
        check_command           check_nrpe!check_swap!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     CPU Load
        check_command           check_nrpe!check_load!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     root Space
        check_command           check_nrpe!check_root!-n

}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     boot space
        check_command           check_nrpe!check_boot!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     home space
        check_command           check_nrpe!check_home!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     tmp space
        check_command           check_nrpe!check_tmp!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     var space
        check_command           check_nrpe!check_var!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     opt space
        check_command           check_nrpe!check_opt!-n
}


define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     Check Users
        check_command           check_nrpe!check_users!-n
}

define service{
        use                     generic-service
        host_name                mongo-db1.bomzan.net
        service_description     PING
        check_command           check_ping!200.0,20%!600.0,60%
        check_interval          5
        retry_interval          1
}

/nodes/windows/serverss/w219-apps.bomzan.net

# Windows host definition template - This is NOT a real host, just a template!

define host{
        use                     windows-server          ; Inherit default values from the generic-host template
        host_name               w2k19-apps.bomzan.net
        alias                   w2k19-apps.bomzan.net
        address                 192.168.10.6
        notes                   Kriti's workstation
        }

define service{
        use                     ping-service
        host_name               w2k19-apps.bomzan.net
        service_description     PING
        check_command           check_ping!200.0,20%!600.0,60%
}

/services/remote-service-template.cfg

# Generic service definition template - This is NOT a real service, just a template!
define service{
        name                            remote-service            ; The 'name' of this service template
        use                             generic-service
        max_check_attempts              2                       ; Re-check the service up to 3 times in order to determine its final (hard) state
        check_interval                  4
        retry_interval                  1
        register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }

/templates/virtual-linux-template.cfg

# Linux host definition template - This is NOT a real host, just a template!
define host{
        name                    virtual-linux-server            ; The name of this host template
        use                     generic-host            ; Inherit default values from the generic-host template
        check_period            24x7                    ; By default, Windows servers are monitored round the clock
        check_interval          5                       ; Actively check the server every 5 minutes
        retry_interval          1                       ; Schedule host check retries at 1 minute intervals
        max_check_attempts      10                      ; Check each server 10 times (max)
        check_command           check-host-alive        ; Default command to check if servers are "alive"
        notification_period     24x7                    ; Send notification out at any time - day or night
        notification_interval   30                      ; Resend notifications every 30 minutes
        notification_options    d,u,r,s                 ; Only send notifications for specific host states
        contact_groups          admins                  ; Notifications get sent to the admins by default
        hostgroups              virtual-linux-servers   ; Host groups that Windows servers should be a member of
        register                0                       ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }

/templates/windows-server-templage.cfg

# Windows host definition template - This is NOT a real host, just a template!
define host{
        name                    windows-server          ; The name of this host template
        use                     generic-host            ; Inherit default values from the generic-host template
        check_period            24x7                    ; By default, Windows servers are monitored round the clock
        check_interval          5                       ; Actively check the server every 5 minutes
        retry_interval          1                       ; Schedule host check retries at 1 minute intervals
        max_check_attempts      10                      ; Check each server 10 times (max)
        check_command           check-host-alive        ; Default command to check if servers are "alive"
        notification_period     24x7                    ; Send notification out at any time - day or night
        notification_interval   30                      ; Resend notifications every 30 minutes
        notification_options    d,u,r,s                 ; Only send notifications for specific host states
        contact_groups          admins                  ; Notifications get sent to the admins by default
        hostgroups              windows-servers         ; Host groups that Windows servers should be a member of
        register                0                       ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }

if you are grouping services associated with multiple hosts, define them in a separate folder, ideally with the name services, and name the configuration files with the service name. Services that re specific to a single host could be store in the same file as the host definition.

Monitoring Nagios Process

check_nagios plugin – checks the log entries in the Nagios Status files, and if the log entries are within an expected time interval then the Nagios is working perfectly fine because the status file will have the up-to-date status details of the Nagios monitored host and services. It also reads process status command to know the status of the Nagios

check_nagios -h

To monitor the Nagios process:

1. Define the command in the command.cfg along with the arguments and the parameters.

define command {
  comand_name  check_nagios
  command_line  $USER1$/check_nagios -F /usr/local/nagios/var/status.dat -C /usr/local/nagios/bin/nagios -e 5
# if the entries are older than 5 minutes,we assume the status file is stale and the nagios process is not working correctly

2. Access the configuration file of the local machine wherever nagios in running – localhost.cfg

define service {
  use                local-service
  host_name          localhost
  service_description  Nagios Service
  check_command        check_nagios
}
systemctl restart nagios.service

Important Nagios File Paths

Nagios Server

Main Configuration File : /usr/local/nagios/etc/nagios.cfg
Object Configuration Files: /usr/local/nagios/etc/objects/
Plugins:                  /usr/local/nagios/libexec
Binaries:                 /usr/local/nagios/bin/nagios
Log Files:                usr/local/nagios/var/nagios.log

NRPE

NRPE Daemon Binary:  /usr/local/nagios/bin/nrpe
Config:              /etc/nagios/nrpe.cfg
Plugins:             /usr/local/nagios/libexec