Nagios-install-configure-manual-script-use-case

Nagios install & configure- manual script use case

Server Setup:

[root@nagios ~]#yum install gd gd-devel gcc glibc glibc-common
[root@nagios ~]# yum install nagios*
[root@nagios ~]# grep "Allow from" /etc/httpd/conf.d/nagios.conf
Allow from 192.168.233.0/24
[root@nagios ~]# grep email /etc/nagios/objects/contacts.cfg
email vrk@sysadminslab.com ;
[root@nagios ~]#htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Updating password for user nagiosadmin
[root@nagios ~]#service nagios start
[root@nagios ~]#service httpd start

nagios1

Client Side:

[root@nginx1 ~]#yum install nrpe nagios-plugins-all openssl
[root@nginx1 ~]#grep allowed_hosts /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1 192.168.233.213
[root@nginx1 ~]#service nrpe start

Server Side :

[root@nagios ~]#grep cfg_dir /etc/nagios/nagios.cfg
cfg_dir=/etc/nagios/servers
[root@nagios ~]# cat /etc/nagios/servers/nginx1.cfg
define host{
use linux-server
host_name nginx1
alias nginx1
address 192.168.233.210
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
define service {
 use generic-service
 host_name nginx1
 service_description PING
 check_command check_ping!100.0,20%!500.0,60%
 }
define service {
 use generic-service
 host_name nginx1
 service_description SSH
 check_command check_ssh
 notifications_enabled 0
 }
[root@nagios ~]#service nagios restart

nagios2

Manual Script :

[root@nagios-client]# cat /usr/local/nagios/libexec/check_port_8087
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

PORT_CHECK=`netstat -antlp|grep LISTEN|grep 8087|wc -l`
case “${PORT_CHECK}” in
0) echo “Port 8087 is not running.”; exit ${STATE_CRITICAL}
;;
1) echo “Port 8087 is running.”; exit ${STATE_OK}
;;
*) echo “More than one crond process detected / crond is in an unknown state.”; exit ${STATE_WARNING}
;;
esac
unset PORT_CHECK
[root@nagios-client]#


[root@nagios ~]# cat /etc/nagios/objects/commands.cfg |tail -5
define command{
 command_name test_alert
 command_line /bin/sh /usr/lib64/nagios/plugins/test.sh
}
[root@nagios ~]#
[root@nagios ~]# cat /usr/lib64/nagios/plugins/test.sh
if [ -f /tmp/hello ]
then
#echo Yes > /tmp/hello
echo "OK - Yes"
exit 0
else
#echo No > /tmp/hello
echo "CRITICAL - No"
exit 1
fi
[root@nagios ~]# tail /etc/nagios/servers/nginx1.cfg
define service{
 host_name nginx1
 service_description TestService
 check_command test_alert
 notifications_enabled 0
 use generic-service
 }
[root@nagios ~]#

—-client side—-

[root@nginx1 ~]#cat /usr/lib64/nagios/plugins/test.sh
if [ -f /tmp/hello ]
then
#echo Yes > /tmp/hello
echo "OK - Yes"
exit 0
else
#echo No > /tmp/hello
echo "CRITICAL - No"
exit 1
fi
[root@nginx1 ~]# grep test /etc/nagios/nrpe.cfg
command[test_alert]=/usr/lib64/nagios/plugins/test.sh
[root@nginx1 ~]# /etc/init.d/nrpe restart
[root@nginx1 ~]# cd /usr/local/nagios/etc/
[root@nginx1 ~]# grep check_port nrpe.cfg
command[check_port]=/usr/local/nagios/libexec/check_port
command[check_port_8087]=/usr/local/nagios/libexec/check_port_8087
command[check_port_8083]=/usr/local/nagios/libexec/check_port_8083
[root@nginx1 ~]#
[root@nginx1 ~]# /etc/init.d/nrpe restart

Custom warning and critical for disk check

[root@nagios ~]# vi /etc/nagios/objects/commands.cfg
-----------------------------------------------------------------------
# 'check_nrpe' command defintion
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
-----------------------------------------------------------------------
[root@nagios ~]# tail -6 /etc/nagios/servers/nginx1.cfg
define service {
 use generic-service
 host_name nginx1
 service_description check_remote_disk
 check_command check_nrpe!check_remote_disk
 }
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
[root@nginx1 ~]# grep check_remote_disk  /etc/nagios/nrpe.cfg
command[check_remote_disk]=/usr/lib64/nagios/plugins/check_disk -w 60% -c 30% -p /
[root@nginx1 ~]#

nagios3