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
Checking Apache on remote server
Re: Checking Apache on remote server
I'm willing to bet that your nagios user on the remote host (the user that runs NRPE) is not allowed to execute the "service" command. In other words, you need to add the nagios user to your sudeors file.
-
- Posts: 19
- Joined: Thu Jun 05, 2014 12:53 pm
Re: Checking Apache on remote server
Thanks for the speedy reply.
You were right I missed that when setting it up, I'm still learning my way around Nagios. I added it as seen below. I pretty much mimicked the check_coldfusion because that works as expected. I now get (No output returned from plugin) through the web interface.
Thanks,
Allan
-----/etc/sudoers
nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/check_coldfusion.sh
nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/check_apache.sh
----nrpe.cfg
command[check_coldfusion]=sudo /usr/local/nagios/libexec/check_coldfusion.sh -p /opt/coldfusion8/bin
command[check_apache]=sudo /usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
--------permissions
-rwxrwxrwx 1 nagios nagios 2932 Sep 16 16:40 check_coldfusion.sh
-rwxr-xr-x 1 nagios nagios 892 Sep 18 16:21 check_apache.sh
---running the command on the host:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.55 -c check_apache
CRITICAL -
--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...
You were right I missed that when setting it up, I'm still learning my way around Nagios. I added it as seen below. I pretty much mimicked the check_coldfusion because that works as expected. I now get (No output returned from plugin) through the web interface.
Thanks,
Allan
-----/etc/sudoers
nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/check_coldfusion.sh
nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/check_apache.sh
----nrpe.cfg
command[check_coldfusion]=sudo /usr/local/nagios/libexec/check_coldfusion.sh -p /opt/coldfusion8/bin
command[check_apache]=sudo /usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
--------permissions
-rwxrwxrwx 1 nagios nagios 2932 Sep 16 16:40 check_coldfusion.sh
-rwxr-xr-x 1 nagios nagios 892 Sep 18 16:21 check_apache.sh
---running the command on the host:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.55 -c check_apache
CRITICAL -
--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...
Re: Checking Apache on remote server
Are you running this command as root? I'll bet you are. Try "su - c nagios" first and running the command as nagios. If it still fails (and I expect it will) walk through your script and copy/paste each command to your shell prompt (still as nagios) and see which one is your problem child.
---running the command on the client
/usr/local/nagios/libexec/check_apache.sh -p /etc/init.d/
-
- Posts: 19
- Joined: Thu Jun 05, 2014 12:53 pm
Re: Checking Apache on remote server
You were write I was indeed running it as root instead of nagios. I finally got it to work by rewriting the script to get it to work. I have the service httpd hard coded in a variable but it would be easy to pass this in and use it for any service I suppose. If anyone can you it feel free.
Thanks for your guidance I appreciate it.
Allan
#!/bin/sh
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
SERVICE='httpd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
statusok="$SERVICE service running, everything is fine"
echo "OK - ${statusok}"
exit $ST_OK
else
statusbad="$SERVICE is not running"
echo "CRITICAL - ${statusbad}"
#echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
exit $ST_CR
fi
Thanks for your guidance I appreciate it.
Allan
#!/bin/sh
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
SERVICE='httpd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
statusok="$SERVICE service running, everything is fine"
echo "OK - ${statusok}"
exit $ST_OK
else
statusbad="$SERVICE is not running"
echo "CRITICAL - ${statusbad}"
#echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
exit $ST_CR
fi
Re: Checking Apache on remote server
You may have recreated the wheel, since there is already a "check_init_services" which does this very thing.
Re: Checking Apache on remote server
On the client:
In nrpe.cfg
In sudoers:
Test from nagios server:
In nrpe.cfg
Code: Select all
command[check_init_service]=sudo /usr/local/nagios/libexec/check_init_service $ARG1$
Code: Select all
# NEEDED TO ALLOW NAGIOS TO CHECK SERVICE STATUS
Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_init_service
Code: Select all
./check_nrpe -H <client ip> -p 5666 -c check_init_service -a httpd
Be sure to check out our Knowledgebase for helpful articles and solutions!