check_init_service py script fails in XI, but works at CLI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gabrotherton
Posts: 57
Joined: Wed Dec 03, 2014 11:16 am

check_init_service py script fails in XI, but works at CLI

Post 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.
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

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

Post by hsmith »

Can you try running it via the command line as the nagios user, instead of root?
Former Nagios Employee.
me.
gabrotherton
Posts: 57
Joined: Wed Dec 03, 2014 11:16 am

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

Post 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?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

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

Post 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'
Be sure to check out our Knowledgebase for helpful articles and solutions!
gabrotherton
Posts: 57
Joined: Wed Dec 03, 2014 11:16 am

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

Post 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.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

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

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
gabrotherton
Posts: 57
Joined: Wed Dec 03, 2014 11:16 am

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

Post by gabrotherton »

Yes! That did the job. Thanks very much :)

This thread can be closed.
Locked