cannot run custom command from anywhere but libexec folder

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Nighthawkz
Posts: 27
Joined: Fri Oct 20, 2017 7:05 am

Re: cannot run custom command from anywhere but libexec fold

Post by Nighthawkz »

ok if I created a custom script and run it returns as follows:

Code: Select all

0
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: cannot run custom command from anywhere but libexec fold

Post by scottwilkerson »

In your CompCU.jar it is creating a file cu_output.xml somewhere, and this file likely need to be writable by the nagios user
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
danjoh
Posts: 73
Joined: Mon Dec 07, 2015 10:43 am
Location: Zürich, Switzerland
Contact:

Re: cannot run custom command from anywhere but libexec fold

Post by danjoh »

What I meant is that after you have executed the command "/usr/bin/java...." and it finishes, you then execute "echo $?" (do not execute any additional commands in-between).

Code: Select all

Error setting up log file null: File already exists and cant delete it (is it in use?)
Exception saving output file [cu_output.xml]: java.io.FileNotFoundException: cu_output.xml (Permission denied)
There you go...
The command tries to delete/create the file "cu_output.xml". Where a can not tell, but probably someplace where root is allowed to write but the nagios user is not, OR, root has created the file (from your command that was run as root) and the nagios user is not allowed to delete/recreate the file.
Do a search to find the "cu_output.xml" file (find / -name cu_output.xml) and check the creation time - if it matches with when you run your command as root, then delete the file and try rerunning the command as nagios (WITHOUT trying to run it as root in between)..

You could maybe also try to add "-xmloutputfile ’/tmp/cu_output.xml’" to the command line (I do not know the CompCU.jar application so I am not sure if this works, but I saw this option in the manual).
--
D/\N
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: cannot run custom command from anywhere but libexec fold

Post by scottwilkerson »

Thanks @danjoh
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Nighthawkz
Posts: 27
Joined: Fri Oct 20, 2017 7:05 am

Re: cannot run custom command from anywhere but libexec fold

Post by Nighthawkz »

thank you both for your help and patience so far!


I did as you said.

removed the xml. reran as user nagios. ran successfully. xml file created with nagios as owner. The 127 error still occurs when nagios trys to run it automatically.

The error mentions worker3 at the end of it (see original post) so i logged into that box as user nagios. the script and jar file had been sync'd across to it and have correct permissions. no xml file. so i ran the script manually on worker3. script ran fine. xml created with nagios as owner.

error still occurs

regards
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: cannot run custom command from anywhere but libexec fold

Post by scottwilkerson »

If you have this setup with Mod-Gearman and workers, you are going to need to force this to always run on the same worker, so it always has access to the files that are written to the filesystem, also you need to make sure that the file that is sync'd is the one where the full paths were added for java and the .jar file
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Nighthawkz
Posts: 27
Joined: Fri Oct 20, 2017 7:05 am

Re: cannot run custom command from anywhere but libexec fold

Post by Nighthawkz »

well...i fell daft. the problem was simply my eyesight. i had an extra "s" on the end of the check in the command.cfg, Changed it and it works a treat. case closed!

thanks again for your help.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: cannot run custom command from anywhere but libexec fold

Post by scottwilkerson »

Wow, well in the end that was easy.

Glad it is resolved
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked