View Full Version : Shown Invalid Service Status Value in Nagios network application
sureshkumar.repaka
19th April 2007, 14:10
Hi
Iam using nagios network application when i trying to found service status value.But finally it shown invalid status value in nagios application. I wrote a code as mentioned below
#!/bin/sh
host="$1"
service="$2"
/etc/init.d/$service status | while read t
echo $t
do
if [[ "$t" == *running* ]]
then
echo "Service is running "
else
echo "Service is stopped"
fi
done
But as mentioned above code running in command prompt on fedora linux,it shown a correct service status value.But when i trying from nagios.It shows a invalid status value.
If any plugins for checking a service status value or any modification. Please suggest to me on this issue.
DonKiShoot
19th April 2007, 15:25
do you try your script under nagios user or under root ?
sureshkumar.repaka
19th April 2007, 15:46
This script excuting in "root"
Iralein
20th April 2007, 13:02
Hi,
I'm not really sure if I understand what you want to do, but here is my view:
You want this script beeing used as a check with Nagios ?!
If so, then you made a HUGE mistake. Every Plugin/Check-Script MUST return status as descripted in the nagios documentation. (Exit-Value of the Script must be: 0, 1, 2, 3 which means for Nagios: 0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN) If your Check doesn't return these values (your script returns 0 everytime - no matter if there are services running), nagios can't treat it right. The data which service is running of not, can be outputted as text or perfdata.
Please read the section about plugins in the nagios documentation.
Yours,
Ira
sureshkumar.repaka
20th April 2007, 13:52
Thanks Iralein.After some modifcations,I trying to excuted as below code
#!/bin/sh
host="$1"
service="$2"
t=$(/etc/init.d/$service status)
if echo "$t" |grep -q running; then
echo "OK - $service service is running."
exit 0
else
echo "Critical - $service service is stopped."
exit 2
fi
return 0 while running a service from command prompt and configure in nagios as mentioned below code
define command{
command_name check_localhost_service
command_line $USER1$/check_service_status localhost $ARG1$
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description acpid service status
normal_check_interval 1
check_command check_localhost_service!acpid
}
But the same script is excuting in nagios and it returns a "Critical - $service service is stopped." while running a service.In nagios doesn't excute the "/etc/init.d/$service status" command.Please any solution on this issue.
Iralein
20th April 2007, 18:23
Hi,
I've tested your script, but it has one fault.
In my system nagios is not root and only root can run /etc/init.d/acpid status. (s-Bit will change nothing, because s-Bit on scripts are not allowed)
So you have to change the permissions of acpid which isn't very good, or you find an other solution with checkproc or something like that.
Bye,
Ira