Configuration
DB-Instance
Install Prerequirement
apt update
apt install -y autoconf gcc libmcrypt-dev make libssl-dev dc build-essential gettext libdbd-mysql-perl
Download Source
cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.6.tar.gz
tar zxf nagios-plugins.tar.gz
Install and compile
cd nagios-plugins-release-2.4.6/
./tools/setup
./configure
make
make install
Install NRPE Daemon on Agent
apt install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev
Download NRPE (nrpe-4.1.0)
cd /tmp
wget --no-check-certificate -O nagios-nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.0/nrpe-4.1.0.tar.gz
tar zxf nagios-nrpe.tar.gz
Configure script and compile NRPE
cd nrpe-4.1.0/
./configure --enable-command-args
sudo make all
sudo make install-groups-users
sudo make install
sudo make install-config
sudo make install-init
Update Agent NRPE Configuration\
nano /usr/local/nagios/etc/nrpe.cfg
line 61 : add ip 0.0.0.0
line 106 : add the NMS Nagios private server ip
line 306 : add the script
## check_nrpe script for DB-Instance
command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_ping]=/usr/local/nagios/libexec/check_ping -H <ip-private-host> -w 100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 <ip-private-host>
#command[check_http]=/usr/local/nagios/libexec/check_http <ip-private-host>
command[check_apt]=/usr/local/nagios/libexec/check_apt
Start service NRPE
systemctl start nrpe.service
systemctl enable nrpe.service
systemctl status nrpe.service
Install mysql_health Plugin
cd
wget https://labs.consol.de/assets/downloads/nagios/check_mysql_health-2.2.2.tar.gz
tar xzf check_mysql_health-2.2.2.tar.gz
cd check_mysql_health-2.2.2/
./configure
make
cp plugins-scripts/check_mysql_health /usr/local/nagios/libexec
Create Database
mysql -u root -p
create user 'nagiosrizwan'@'%' identified by 'pass123';
GRANT SELECT, PROCESS, SUPER ON *.* to 'nagiosrizwan'@'%';
flush privileges;
NMS-Nagios
Install pre-requisites package
apt -y install libdbd-mysql-perl
Install mysql_health Plugin
cd
wget https://labs.consol.de/assets/downloads/nagios/check_mysql_health-2.2.2.tar.gz
tar xzf check_mysql_health-2.2.2.tar.gz
cd check_mysql_health-2.2.2/
./configure
make
cp plugins-scripts/check_mysql_health /usr/local/nagios/libexec
Test the check_mysql_health plugin
cd plugins-scripts/
./check_mysql_health -H <ip-private-DB> --user <db-user> --password <db-pass> --mode uptime
Edit File commands.cfg
nano /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_mysql_health
command_line $USER1$/check_mysql_health -H $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
}
Add the following script to the bottom line.
Edit file hosts.cfg
nano /usr/local/nagios/etc/hosts.cfg
## Define Host - DB Instance
define host {
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name <linux-host2>
alias mysql_server
address <ip-private-db>
notification_interval 1
notification_options d,u,r,f,s
check_interval 1
retry_interval 1
contact_groups admins
notifications_enabled 1
notification_period 24x7
}
<linux-host2> = db-instance
<ip-private-db> = 10.10.2.196
Edit File services.cfg
nano /usr/local/nagios/etc/services.cfg
define service{
use generic-service
host_name host-linux1, host-linux2
service_description Root
check_command check_nrpe!check_root
}
define service{
use generic-service
host_name host-linux1, host-linux2
service_description APT
check_command check_nrpe!check_apt
}
define service{
use generic-service
host_name host-linux1, host-linux2
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name host-linux1, host-linux2
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service
host_name host-linux1, host-linux2
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name host-linux1, host-linux2
service_description SSH Monitoring
check_command check_nrpe!check_ssh
}
add the db-instance host_name next to the web server hostname so that check_nrpe is carried out simultaneously on two linux_hosts.
host-linux1 = webserver
host-linux2 = db-instance
define service {
host_name <linux-host2>
service_description MySQL Connections
check_command check_mysql_health!<ipadd-db>!3306!<user-db>!<pass-db>!threads-connected
notification_interval 1
notification_options w,u,c,r,f,s
check_interval 1
retry_interval 1
contact_groups admins
notifications_enabled 1
notification_period 24x7
max_check_attempts 3
check_period 24x7
}
define service {
host_name <host_name-db>
service_description MySQL Uptime
check_command check_mysql_health!<ipadd-db>!3306!<user-db>!<pass-db>!uptime
check_interval 1
retry_interval 1
contact_groups admins
notifications_enabled 1
notification_period 24x7
notification_options w,u,c,r,f,s
notification_interval 1
max_check_attempts 3
check_period 24x7
}
host-name-db = db-instance
ip-addr-db = 10.10.2.196
user-db = nagiosrizwan
pass-db = pass123
Check the Nagios configuration
Check the Nagios configuration file to see if there are errors.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Restart Service Nagios
systemctl restart nagios.service
Configuration is Completed
Open Browser
http://<ip-addr-pub-nagios>/nagios
username : nagiosadmin
password : nagiosadmin
Last updated