Nagios Server and NRPE Installation
Nagios is an open source host, service and network monitoring tool. This page talks about how to install and configure Nagios Server and Nagios Remote Plugin Executor Server (NRPE).
This guide works just fine for Ubuntu 12.04 64 bit.
Nagios 3 Server Setup
Step 1:
Install Nagios 3 from the Ubuntu main repository.sudo apt-get install nagios3
sudo apt-get install openssl
This command will install and configure Nagios 3 along with the following required dependencies (Apache2, PHP, Postfix.....). You can ignore the email configuration during the installation process, then you will be prompted for the password to enter and confirm for user "nagiosadmin".
Remember this password, because you will be using this to login nagios web ui.
Use the below mentioned command to start, stop and restart nagios 3 server.
sudo service nagios3 restart
Step 2:
Install nrpe plugin from the Ubuntu main repository.sudo apt-get install nagios-nrpe-pluginThis command will install NRPE plugin on the server.
Remote Host Setup
Step 3:
Install NRPE server on the remote host from the Ubuntu main repository.sudo apt-get install nagios-nrpe-server
sudo apt-get install openssl
Use the netstat command to check if the nrpe server is running.
bash$ :/etc/nagios$ netstat -an | grep 5666 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
Step 4:
Install nrpe plugin from the Ubuntu main repository.sudo apt-get install --no-install-recommends nagios-nrpe-pluginThis command will install NRPE plugin on the remote host. The argument --no-install-recommends is required to avoid installing the entire dependent libraries.
Use the below mentioned command to start, stop and restart NRPE.
sudo service nagios-nrpe-server restart
Nagios Server Configuration
Step 5:
You need to register the nagios server IP address on the Nagios remote host by editing the following file.sudo vi /etc/nagios/nrpe.cfgand update allowed_hosts=127.0.0.1,<Nagios Server IP Address>
Don't forget to restart Nagios NRP server after making the changes.
sudo service nagios-nrpe-server restart
Execute the below mentioned command from Nagios Server to confirm the remote host is being configured properly.
bash$ /usr/lib/nagios/plugins/check_nrpe -H <Remote Host IP Address> NRPE v2.12
You now have a very basic working installation of Nagios on your system (login at http://<Nagios Server IP Address>/nagios3 with those nagiosadmin credentials). It has been configured to monitor your local machine.
Remote Service Configuration
Step 6:
Define all the required custom commands in the /etc/nagios/nrpe.cfg from remote host like below.
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10 command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -A -I /boot -I /dev/shm command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 command[check_cpu_stats]=/usr/lib/nagios/plugins/check_cpu_stats.sh -w 50 -c 75 command[check_if_traffic]=/usr/lib/nagios/plugins/check_ifutil.pl -i eth0 -w 70 -c 80 -p -b 1000M command[check_ssh]=/usr/lib/nagios/plugins/check_ssh localhost command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20 -c 10
Ensure no duplicate commands defined in this nrpe.cfg file. There may be already few commands exists in the nrpe.cfg.
Don't forget to restart NRPE after making the changes.
sudo service nagios-nrpe-server restart
Step 7:
Create a new file /etc/nagios3/conf.d/remote-host_nagios2.cfg on Nagios server like below. As per the below example, the host name is "remoe-host"define host{
name remote-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
check_command check-host-alive
max_check_attempts 10
notification_interval 0
notification_period 24x7
notification_options d,u,r
contact_groups admins
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
Create a new file /etc/nagios3/conf.d/remote-host_nagios2.cfg on Nagios server like below. As per the below example, the service name is "remote-service"
define service{
name remote-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_interval 0 ; Only send notifications on status change by default.
is_volatile 0
check_period 24x7
normal_check_interval 5 ; Update this value to change check interval
retry_check_interval 1
max_check_attempts 4
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
Create a new file /etc/nagios3/conf.d/rh_services_nagios2.cfg on Nagios server like below.
define host{
use <Host name created above> ; Name of the host template to use
host_name <Name of the remote host>
alias <Name of the remote host alias>
address <IP address of the remote host>
}
define service{ use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Disk Space check_command check_nrpe_1arg!check_disks
}
define service{
use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Current Users check_command check_nrpe_1arg!check_users
}
define service{
use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Total Processes check_command check_nrpe_1arg!check_procs
}
define service{
use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Current Load check_command check_nrpe_1arg!check_load
}
define service{ use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Zombie_procs check_command check_nrpe_1arg!check_zombie_procs } define service{ use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description CPU Stats check_command check_nrpe_1arg!check_cpu_stats } define service{ use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description If Traffic check_command check_nrpe_1arg!check_if_traffic } define service{ use <Service name created above> ; Name of service template to use host_name ubuntu service_description SSH check_command check_nrpe_1arg!check_ssh } define service{ use <Service name created above> ; Name of service template to use host_name <Name of the remote host> service_description Swap check_command check_nrpe_1arg!check_swap }
Note that the arguments are hardcoded in the remote host itself, there is no need of passing arguments.
Restart the Nagios server after making the above changes.
Open a webbrowser and launch the below URL
Open a webbrowser and launch the below URL
http://<Nagios Server IP Address>/nagios3
Miscellaneous
Install iostat if there is any error "UNKNOWN: iostat not found or is not executable by the nagios user." when you run the check_cpu_stats command
bash$ /usr/lib/nagios/plugins/check_cpu_stats.sh -w 50 -c 75 /usr/lib/nagios/plugins/check_cpu_stats.sh: line 1: PU: command not found UNKNOWN: iostat not found or is not executable by the nagios user.
bash$ sudo apt-get install sysstat
You may find /check_ifutil.pl and check_cpu_stats.sh from google.