Checking Apache on remote server
Posted: Fri Sep 19, 2014 7:05 am
Hi All,
I have slowly been implementing Nagios across all the servers in the company I work for and I love this product, that being said I have hit a few road blocks along the way and have been impressed by the willingness of people to help when encountering problems. My latest trouble has me completely stymied: I created a script to check to see if Apache is running. It works on the client I'm trying to check but for some reason it doesn't work through the host. I included the commands I ran and the output. The Service Definition, the command line from the nrpe.cfg file, the actual script and an image cut from the web interface. Any help or ideas would be greatly appreciated.
Thanks,
Allan
----------------------Running the command on the Host
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.55 -c check_apache
httpd is stopped
httpd is stopped
CRITICAL - httpd is stopped
---------------------Running the command on the Client
/usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
httpd (pid 17777 17776 17775 17774 17773 17772) is running...
httpd (pid 17777 17776 17775 17774 17773 17772) is running...
OK - httpd (pid
17777 17776 17775 17774 17773 17772) is running...
-----------------------template.cfg
Service definition
define service {
name tlecentos7-service-apache
use tlecentos7-service
servicegroups tlecentos7-web-services
service_description Check Apache
check_command check_nrpe!check_apache
register 0
}
nrpe.cfg (Command)
command[check_apache]=/usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
----- check_apache.sh
#! /bin/bash
#
# Author : Allan Hillier
# Desc : Plugin to verify Apache is running
#
#
PROGNAME=`basename $0`
VERSION="Version 1.0,"
AUTHOR="Allan Hillier"
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
statustextok="httpd (pid"
pathtoapache=/etc/init.d
get_vals() {
if [ -f $pathtoapache/httpd ]; then
statustext=`service httpd status`
echo $statustext
m=`expr substr "$statustext" 1 10`
b=`expr substr "$statustextok" 1 10`
#echo $statustext
#echo $statustextok
#echo $m
#echo $b
# echo "Length is ${#m}"
# echo "Length is ${#b}"
else
echo "UNKNOWN - could not find apache! check the --path- argument!"
exit $ST_UK
fi
}
do_output() {
output="$statustext"
echo $output
}
# Here we go!
get_vals
do_output
if [ "$m" = "$b" ]; then
echo "OK - ${output}"
exit $ST_OK
else
echo "CRITICAL - ${output}"
exit $ST_CR
fi
I have slowly been implementing Nagios across all the servers in the company I work for and I love this product, that being said I have hit a few road blocks along the way and have been impressed by the willingness of people to help when encountering problems. My latest trouble has me completely stymied: I created a script to check to see if Apache is running. It works on the client I'm trying to check but for some reason it doesn't work through the host. I included the commands I ran and the output. The Service Definition, the command line from the nrpe.cfg file, the actual script and an image cut from the web interface. Any help or ideas would be greatly appreciated.
Thanks,
Allan
----------------------Running the command on the Host
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.55 -c check_apache
httpd is stopped
httpd is stopped
CRITICAL - httpd is stopped
---------------------Running the command on the Client
/usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
httpd (pid 17777 17776 17775 17774 17773 17772) is running...
httpd (pid 17777 17776 17775 17774 17773 17772) is running...
OK - httpd (pid
17777 17776 17775 17774 17773 17772) is running...
-----------------------template.cfg
Service definition
define service {
name tlecentos7-service-apache
use tlecentos7-service
servicegroups tlecentos7-web-services
service_description Check Apache
check_command check_nrpe!check_apache
register 0
}
nrpe.cfg (Command)
command[check_apache]=/usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
----- check_apache.sh
#! /bin/bash
#
# Author : Allan Hillier
# Desc : Plugin to verify Apache is running
#
#
PROGNAME=`basename $0`
VERSION="Version 1.0,"
AUTHOR="Allan Hillier"
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
statustextok="httpd (pid"
pathtoapache=/etc/init.d
get_vals() {
if [ -f $pathtoapache/httpd ]; then
statustext=`service httpd status`
echo $statustext
m=`expr substr "$statustext" 1 10`
b=`expr substr "$statustextok" 1 10`
#echo $statustext
#echo $statustextok
#echo $m
#echo $b
# echo "Length is ${#m}"
# echo "Length is ${#b}"
else
echo "UNKNOWN - could not find apache! check the --path- argument!"
exit $ST_UK
fi
}
do_output() {
output="$statustext"
echo $output
}
# Here we go!
get_vals
do_output
if [ "$m" = "$b" ]; then
echo "OK - ${output}"
exit $ST_OK
else
echo "CRITICAL - ${output}"
exit $ST_CR
fi