Page 1 of 1

check_init_service py script fails in XI, but works at CLI

Posted: Wed Dec 02, 2015 2:02 pm
by gabrotherton
Hello all! I have been searching the forums for topics about the check_init_service script. I found the scripted posted, copied it and python will run it. When this script is run this at CLI:

Code: Select all

[root@sms1 libexec]# python check_init_service --service mysqld
OK: all services running (mysqld)
[root@sms1 libexec]#
It is working as expected, and I verified that mysqld is running.

However, my problem is when I call this using the NRPE, I get a weird response in Nagios XI:

Code: Select all

check_nrpe!check_init_service!-a '--service mysqld'!!!!!!
The return:

COMMAND: /usr/local/nagios/libexec/check_nrpe -H sms1 -t 30 -c check_init_service -a '--service mysqld'
OUTPUT: CRITICAL: Failing (mysqld)

Does anyone have any insight for this?

A note: the usage help that I found says to run the command like so:

Code: Select all

check_nrpe!check_init_service!-a 'mysqld'!!!!!!
But that returns an error.

Re: check_init_service py script fails in XI, but works at C

Posted: Wed Dec 02, 2015 2:13 pm
by hsmith
Can you try running it via the command line as the nagios user, instead of root?

Re: check_init_service py script fails in XI, but works at C

Posted: Wed Dec 02, 2015 2:36 pm
by gabrotherton
as nagios user, I get this:

Code: Select all

-bash-4.1$ python check_init_service --service mysqld
CRITICAL: Failing (mysqld)
-bash-4.1$ 
So this appears to work as root, but not as nagios user. How do I fix that?

Re: check_init_service py script fails in XI, but works at C

Posted: Wed Dec 02, 2015 4:11 pm
by lmiltchev
How did you install the Linux agent (NRPE and Nagios plugins) on the remove machine? Did you follow this document?

Can you show us the "check_init_service" command definition from the remote box? It should be in "common.cfg" if you used our installer or "nrpe.cfg".

Why are you passing the "--service" to the argument? It is sufficient to run:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -c check_init_service -a 'mysqld'

Re: check_init_service py script fails in XI, but works at C

Posted: Thu Dec 03, 2015 9:09 am
by gabrotherton
The NPRE agent is working fine because it is reporting back several other service states normally. The check_init_service python script was apparently not installed when I did the NRPE installation. So I copied the python code from another post here on the forums. After some space adjustments, the python code executed without error. The command definition that NRPE calls is shown last in the copy/paste from the nrpe.cfg file:

All these commands are working properly:

Code: Select all

command[check_users]=/usr/local/nagios/libexec/check_users $ARG1$ $ARG2$
command[check_load]=/usr/local/nagios/libexec/check_load $ARG1$ $ARG2$
command[check_disk]=/usr/local/nagios/libexec/check_disk $ARG1$ $ARG2$ $ARG3$
command[check_total_procs]=/usr/local/nagios/libexec/check_procs $ARG1$ $ARG2$ $ARG3$
command[custom_check_mem]=/usr/local/nagios/libexec/custom_check_mem $ARG1$ $ARG2$
# Check cpu usage
command[check_cpu]=/usr/local/nagios/libexec/check_linux_stats.pl $ARG1$ $ARG2$ 
command[check_init_service]=/usr/local/nagios/libexec/check_init_service $ARG1$ $ARG2$ 
I didn't explain properly the reason I have to pass the "--service" option is explained in my initial post. When I passed '-a mysqld' I get this error:

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_nrpe -H sms1 -t 30 -c check_init_service -a 'mysqld'
OUTPUT: UNKNOWN: No services specified
Where can I get a copy of the check_init_service python code? I think maybe because I copied the source code from another post in the Nagios XI forums I may have copied a modified version onto my Nagios XI production server.

Re: check_init_service py script fails in XI, but works at C

Posted: Thu Dec 03, 2015 10:54 am
by tgriep
The check_init_services needs to run as root and the command in the nrpe.cfg file needs to be changed.
Edit the nrpe.cfg file and change this line from

Code: Select all

command[check_init_service]=/usr/local/nagios/libexec/check_init_service $ARG1$ $ARG2$ 
to

Code: Select all

command[check_init_service]=sudo /usr/local/nagios/libexec/check_init_service $ARG1$ $ARG2$ 
Restart xinetd for the changed to be in effect.
service xinetd restart

Then edit the /etc/sudoers file and add the following line.

Code: Select all

nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_init_service
Let us know if this works for you.

Re: check_init_service py script fails in XI, but works at C

Posted: Mon Dec 07, 2015 2:37 pm
by gabrotherton
Yes! That did the job. Thanks very much :)

This thread can be closed.