Nagios custom scripts
Create Nagios Plugins With Bash On CentOS
Step :1 - Install RPMForge Repository and NRPE on client VPS
#rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
#yum -y install nagios-nrpe
#useradd nrpe && chkconfig nrpe on
Step :2 - Create your Bash Script
#cd /usr/lib64/nagios/plugins/
# cat check_warnings.sh
#!/bin/bash
countWarnings=$(df -h / | grep -v Filesystem | awk '{print $5}' | sed 's/%//g')
if (($countWarnings<=5)); then
echo "OK - Usage of / $countWarnings services in Warning state"
exit 0
elif ((6<=$countWarnings && $countWarnings<=9)); then
# This case makes no sense because it only adds one warning.
# It is just to make an example of all possible exits.
echo "WARNING - Usage of / $countWarnings services in Warning state"
exit 1
elif ((10<=$countWarnings && $countWarnings<=99)); then
echo "CRITICAL - Usage of / $countWarnings services in Warning state"
servername=nagios.example.com filesystem=/
echo "$servername $filesystem"
curl -D - \
-X "POST" -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Rundeck-Auth-Token: 8h7eFvQ1Nb5JrhulUdYrHvAKzwWw18gp" \
-d "{\"argString\":\"-servername $servername -filesystem $filesystem \"}" \
http://192.168.1.10:4440/api/16/job/2ed8d8c9-3f46-46d3-ba5f-e71d3211a40c/executions
exit 2
else
echo "UNKNOWN - $countWarnings"
exit 3
fi
#chmod +x check_warnings.sh
Step 3 - Add Script to NRPE configuration on client host
#vi /etc/nagios/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe/nrpe.pid
server_port=5666
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=198.211.117.251
dont_blame_nrpe=1
debug=0
command_timeout=60
connection_timeout=300
include_dir=/etc/nrpe.d/
command[usedspace_bash]=/usr/lib64/nagios/plugins/usedspace.sh
#service nrpe restart
Step 4 - Add New Command to Nagios Checks on Nagios Monitoring Server
#vi /usr/local/nagios/etc/objects/commands.cfg
# Custom plugins commands...
define command{
command_name check_warnings
command_line $USER1$/check_warnings.sh
}
#vi /usr/local/nagios/etc/server/jira.cfg
define service {
use generic-service
host_name jira.example.com
service_description Centos.Example.com Disk usage
check_command usedspace_bash
}
Restart Nagios:
#service nagios restart
Relevant Blogs:
configuration Nagios adding Linux and windows nodes
Recent Comments
No comments
Leave a Comment
We will be happy to hear what you think about this post