Operating System - Linux
1753792 Members
7008 Online
108799 Solutions
New Discussion юеВ

Shown Invalid Service Status Value in Nagios network application

 
sureshkumar.repaka
New Member

Shown Invalid Service Status Value in Nagios network application

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.
9 REPLIES 9
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

The 'while read' part might be messing things up. Looks kinda strange to me.

This minor edit seems 'safer' to me already:

t=$(service $2 status)
if [[ "$t" == *running* ]]
then
echo "Service is running "
else
echo "Service is stopped"
fi

G'luck !
an engineer's aim in a discussion is not to persuade, but to clarify.
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

Sorry.. this complies more to your example (probably more clear):

#!/bin/bash
host="$1"
service="$2"

t=$(/etc/init.d/$service status)

if [[ "$t" == *running* ]]
then
echo "Service is running "
else
echo "Service is stopped"
fi

Still quick 'n dirty, though..
an engineer's aim in a discussion is not to persuade, but to clarify.
sureshkumar.repaka
New Member

Re: Shown Invalid Service Status Value in Nagios network application

Thanks.But this code is working command prompt and it is not working from nagios.This code is trying to excute from nagios.
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

Can you run it ok when you're su'd to the nagios user account ?
an engineer's aim in a discussion is not to persuade, but to clarify.
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

Asking the above because I just saw this on my OEL (that's pretty much a RedHat):

[root@orabox ~]# /etc/init.d/xinetd status
xinetd (pid 2660) is running...
[root@orabox ~]# su - user1
[user1@orabox ~]$ /etc/init.d/xinetd status
[user1@orabox ~]$

--> No output when running from the user account
an engineer's aim in a discussion is not to persuade, but to clarify.
sureshkumar.repaka
New Member

Re: Shown Invalid Service Status Value in Nagios network application

Thanks Wouter Jagers.How will i add nagios user account into "sudo" and how will i give persmissions for running "/etc/init.d/service status" command in sudo.Please help me.
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

Personally I would have my script check for the actual processes in a ps command, but if you want to you could add an entry like this in your sudoers file:

nagios ALL=NOPASSWD:/etc/init.d/service1 status, /etc/init.d/service2 status

This way, nagios should be able to run the scripts as root, and only with the 'status' option.

Cheers,
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.
Wouter Jagers
Honored Contributor

Re: Shown Invalid Service Status Value in Nagios network application

Thanks for also checking out http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward points to useful answers ;-)

Welcome to the forums !
an engineer's aim in a discussion is not to persuade, but to clarify.
sureshkumar.repaka
New Member

Re: Shown Invalid Service Status Value in Nagios network application

Thanks Wouter Jagers.your answers lot of help to us and we are found the solution for this issue.The some modification in script while running a command.once again thanks a lot.