Service test button runs script as apache user

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Service test button runs script as apache user

Post by gormank »

Hi,
I have a service running a script that runs commands via ssh in remote boxes. It fails in funny ways intermittently. On another Nagios install that's supposed to be the same, the same service always seems to work fine. The scripts are identical. I added a line to the script to touch a file to see who's running the script. I had assumed it would run as nagios, but I its owned by apache on the server with the problem.

Works:
-rw-r--r-- 1 nagios nagios 0 Oct 20 16:21 /tmp/check_capacity.txt
Fails:
-rw-r--r-- 1 apache apache 0 Oct 20 16:13 /tmp/check_capacity.txt

So on one system, the script is running as apache, and on the other as nagios. Where is the user running the service defined? I don't see it in nagios.cfg

When I test the service (test check command button), the command always fails on either system.

OUTPUT: Could not connect to...

When run by the nagios user, the script runs fine every time.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Service test button runs script as apache user

Post by tmcdonald »

When you use the Test Check Command button, it is always run by apache. If the check is run organically, it is run by nagios. What is likely happening is that you are testing it with the Test Check button first, and due to the permissions on the file it cannot be overwritten when nagios runs it organically, so it appears to always be run by apache. I'd bet if you skipped the test phase, it would work as expected.
Former Nagios employee
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Service test button runs script as apache user

Post by gormank »

If it normally runs as nagios, that's a good thing at least...
It seems asinine to test as a user that won't run the service. What's the point of testing?
I delete the file at the beginning: rm /tmp/check_capacity.txt; touch /tmp/check_capacity.txt; chmod 666 /tmp/check_capacity.txt
Maybe set UID permission would help. Its a pain to not be able to use the test button (bad lazy user).

This can be closed.
Thanks
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Service test button runs script as apache user

Post by lmiltchev »

Thanks for the feedback, gormank!
FYI, modifying the way "test" button works under the CCM is being discussed among our developers. I expect to see some changes in the future versions of XI.
I am closing this topic.
Be sure to check out our Knowledgebase for helpful articles and solutions!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Service test button runs script as apache user

Post by tmcdonald »

Just to tack on, even running it as nagios would not truly be the same as actually loading it into the running nagios configuration, which means things like the $USERn$ macros would have no meaning.
Former Nagios employee
Locked