https://github.com/rkidambi11/Docker-Nagios.git
docker pull jasonrivers/nagios:latest
Run with the example configuration with the following:
docker run --name nagios4 -p 0.0.0.0:8080:80 jasonrivers/nagios:latest
alternatively you can use external Nagios configuration & log data with the following:
docker run --name nagios4 \
-v /path-to-nagios/etc/:/opt/nagios/etc/ \
-v /path-to-nagios/var:/opt/nagios/var/ \
-v /path-to-custom-plugins:/opt/Custom-Nagios-Plugins \
-v /path-to-nagiosgraph-var:/opt/nagiosgraph/var \
-v /path-to-nagiosgraph-etc:/opt/nagiosgraph/etc \
-p 0.0.0.0:8080:80 jasonrivers/nagios:latest
Note: The path for the custom plugins will be /opt/Custom-Nagios-Plugins, you will need to reference this directory in your configuration scripts.
Credentials:
The default credentials for the web interface is nagiosadmin
/ nagios
Now login into your Nagios Monitoring Server. Here you will need to do following things:
Step 1: Install NRPE Plugin
docker exec -it nagios4 /bin/bash
# [root@nagiosserver] sudo apt-get update
[root@nagiosserver] sudo apt-get install nagios-nrpe-server nagios-plugins
OR
[root@nagiosserver] sudo ap-get update
[root@nagiosserver] wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
[root@nagiosserver] tar -xvf nagios-plugins-2.1.2.tar.gz
[root@nagiosserver] ls -ltr
[root@nagiosserver] cd nagios-plugins-2.1.2
[root@nagiosserver] ls -ltr
[root@nagiosserver] ./configure
[root@nagiosserver] make all
[root@nagiosserver] find / -name check_nrpe
In NRPE configuration, first we need to nrpe to which nagios servers it accepts requests, For example your nagios server ip is 192.168.1.100, then add this ip to allowed hosts list. Edit NRPE configuration file /etc/nagios/nrpe.cfg and make changes like
/etc/nagios/nrpe.cfg -- vi to this file.
allowed_hosts=127.0.0.1, 192.168.1.100 --->> ### It should be in client machine and allow nagios server ip.
we can add more Nagios servers in allowed hosts by comma separated list.
Now restart NRPE service. Now its ready to listen to requests from Nagios server
sudo /etc/init.d/nagios-nrpe-server restart
Let’s verify the connection between the Nagios server and NRPE client machine. Login to your Nagios server and check the Nagios server can communicate with NRPE service properly.
Use check_nrpe command on Nagios server under plugins directory. The command will be like as below here 192.168.1.11 is the IP address of client machine.
/opt/nagios/libexec/check_nrpe -H 10.128.0.15 ## client IP
NRPE v2.15 #### You will get this response from client.
The output “NRPE v2.15” shows that the Nagios server successfully communicated with NRPE.
All the services check commands with the nagios plugins packages, which is by default installed in /usr/lib/nagios/plugins/ for 32 bit systems. Default installation adds few commands in configuration file. Add more commands as per your requirements like below
vim /etc/nagios/nrpe.cfg ### this is from master.
/etc/nagios/nrpe.cfg
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_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
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
Use following commands to start, stop or restart NRPE service. Each time we make any changes in configuration file required to restart service
sudo /etc/init.d/nagios-nrpe-server stop
sudo /etc/init.d/nagios-nrpe-server start
sudo /etc/init.d/nagios-nrpe-server restart
Note : If you are not able to see the hosts and service stop and start the nexus container. Also please allow 5666 port from AWS security group or GCP firewall group.
To add a remote host you need to create a two new files “hosts.cfg” and “services.cfg” under “/opt/nagios/etc/” location.
[root@nagiosserver]# touch hosts.cfg
[root@nagiosserver]# touch services.cfg
STEP7:-
Now add these two files to main Nagios configuration file. Open nagios.cfg file with any editor.
[root@nagiosserver]# vi /opt/nagios/etc/nagios.cfg
# You can specify individual object config files as shown below:
cfg_file=/opt/nagios/etc/hosts.cfg
cfg_file=/opt/nagios/etc/services.cfg
STEP8:-
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@nagiosserver]# vi /opt/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
}
STEP9:-
Next open services.cfg file add the following services to be monitored.
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
}
STEP10 :-
Now NRPE command definition needs to be created in commands.cfg file.
[root@nagiosserver]# vi /opt/nagios/etc/objects/commands.cfg
STEP11:-
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.
/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg
URL Details : https://www.tecmint.com/how-to-add-linux-host-to-nagios-monitoring-server/