cannot run custom command from anywhere but libexec folder
-
- Posts: 27
- Joined: Fri Oct 20, 2017 7:05 am
cannot run custom command from anywhere but libexec folder
I have a custom .py script provided to myself to monitor dell storage controllers. I'm trying to get nagios to run locally (no way of adding a client to the storage controller).
it's a python script that invokes a jar file.
the script is attached. the JAR file and the script currently sit in /usr/local/nagios/libexec/ and have been given full permissions (777) just to blank cover whilst I test set-up.
I've set up the command in the command.cfg as follows :
define command{
command_name check_compellent_alerts
command_line $USER1$/check_compellent_alert.py -P $USER47$
}
user47 beign the password I'm trying to pass it from the resource.cfg
and the check itself is in a check.cfg :
define service {
use generic-service
host_name c-host-1
service_description Command Utility Script Results
check_command check_compellent_alerts
}
problem is the script will only run - if I run the script manually from within the folder the script is located and add the password parameter I want to pass through as variables within the script itself. . otherwise if I try and run it like
/usr/local/nagios/libexec/check_compellent_alerts.py
or
/usr/local/nagios/libexec/check_compellent_alerts.py -P $USER47$
I get a traceback of "need one more argument to unpack" which I understand to believe meaning it's expecting a parameter to be passed but got nothing.
so now I'm doubting if I've actually set this up right at all and am hoping someone could help advise!
Regards
it's a python script that invokes a jar file.
the script is attached. the JAR file and the script currently sit in /usr/local/nagios/libexec/ and have been given full permissions (777) just to blank cover whilst I test set-up.
I've set up the command in the command.cfg as follows :
define command{
command_name check_compellent_alerts
command_line $USER1$/check_compellent_alert.py -P $USER47$
}
user47 beign the password I'm trying to pass it from the resource.cfg
and the check itself is in a check.cfg :
define service {
use generic-service
host_name c-host-1
service_description Command Utility Script Results
check_command check_compellent_alerts
}
problem is the script will only run - if I run the script manually from within the folder the script is located and add the password parameter I want to pass through as variables within the script itself. . otherwise if I try and run it like
/usr/local/nagios/libexec/check_compellent_alerts.py
or
/usr/local/nagios/libexec/check_compellent_alerts.py -P $USER47$
I get a traceback of "need one more argument to unpack" which I understand to believe meaning it's expecting a parameter to be passed but got nothing.
so now I'm doubting if I've actually set this up right at all and am hoping someone could help advise!
Regards
- Attachments
-
- check_compellent_alerts.py
- (3.18 KiB) Downloaded 541 times
-
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: cannot run custom command from anywhere but libexec fold
Hello, @Nighthawkz. Let's start from simple. Sign in to your system as a Nagios user and try to run the plugin locally:
You can not pass in macros from the resource.cfg locally:
Only nagios has access to this macro. So if you were to run the command locally you need to use a normal password.
Next, open the /usr/local/nagios/etc/nagios.cfg file and make sure that:
Also, pay attention to this:
That means $USER47$ can not contain any special characters.
Restart the nagios service with:
Code: Select all
su -nagios
Code: Select all
/usr/local/nagios/libexec/check_compellent_alerts.py -P *password*
Code: Select all
/usr/local/nagios/libexec/check_compellent_alerts.py -P $USER47$
Next, open the /usr/local/nagios/etc/nagios.cfg file and make sure that:
Code: Select all
enable_environment_macros=1
Code: Select all
illegal_macro_output_chars=`~$&|'"<>
Restart the nagios service with:
Code: Select all
service nagios restart
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
-
- Posts: 27
- Joined: Fri Oct 20, 2017 7:05 am
Re: cannot run custom command from anywhere but libexec fold
Hi
running it as nagios:
unless i CD into the libexec folder and run it as ./check_compellent_alerts.py
in which case it runs correctly.
the enable_environment_macros is set to one and teh password does nto contain any of the illegal characters
EDIT** took the -P out of the code bit as i forgot it had the password in it.....
running it as nagios:
Code: Select all
nagios@nagios:/usr/local/nagios> /usr/local/nagios/libexec/check_compellent_alerts.py
Traceback (most recent call last):
File "/usr/local/nagios/libexec/check_compellent_alerts.py", line 81, in <module>
alerts = run_CompCU("alert show")
File "/usr/local/nagios/libexec/check_compellent_alerts.py", line 39, in run_CompCU
(CUHeader,blank,CUBreak1,CUUser,CUHost,CUIntent,CUBreak2,CUConnect,CURunning)=lines[:9]
ValueError: need more than 1 value to unpack
unless i CD into the libexec folder and run it as ./check_compellent_alerts.py
in which case it runs correctly.
the enable_environment_macros is set to one and teh password does nto contain any of the illegal characters
EDIT** took the -P out of the code bit as i forgot it had the password in it.....
Re: cannot run custom command from anywhere but libexec fold
Have you tried to use the fully qualified path to the jar-file?
I.e.
instead of
I.e.
Code: Select all
output=commands.getoutput('java -jar /usr/local/nagios/libexec/CompCU.jar -host %s -user %s -password %s -c "%s"' % (Host,SCUser,password,command))
Code: Select all
output=commands.getoutput('java -jar CompCU.jar -host %s -user %s -password %s -c "%s"' % (Host,SCUser,password,command))
--
D/\N
D/\N
-
- 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
You may also need the fully qualified path to java as welldanjoh wrote:Have you tried to use the fully qualified path to the jar-file?
Code: Select all
output=commands.getoutput('/usr/bin/java -jar /usr/local/nagios/libexec/CompCU.jar -host %s -user %s -password %s -c "%s"' % (Host,SCUser,password,command))
-
- Posts: 27
- Joined: Fri Oct 20, 2017 7:05 am
Re: cannot run custom command from anywhere but libexec fold
wow - why did i not think of that.
it now works no mater where i run from manually. hopefully it'll also work when i re enable/restart nagios now!
it now works no mater where i run from manually. hopefully it'll also work when i re enable/restart nagios now!
-
- 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
Let us know if you have further problems
-
- Posts: 27
- Joined: Fri Oct 20, 2017 7:05 am
Re: cannot run custom command from anywhere but libexec fold
apologies for the delay! I now getting the following results when nagios tries to run it automatically:
CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. (worker: nagios3)
Running it from command line as either root or nagios user doesn't return a result - but doesn't fail either (don't think ti should re returning a result if nothings wrong to be honest)
*EDIT* I told a lie - it should be returning a result as I checked the storage manager itself (which has alerts). It just doesn't return anything. If I input the wrong password onto the command lien to be passed through, it does correctly return that the user could not be logged in due to incorrect log in:
"Couldn't connect to host-1: Error returned from Web Server, make sure certificates are created correctly (Incorrect or missing user login or password)"
CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. (worker: nagios3)
Running it from command line as either root or nagios user doesn't return a result - but doesn't fail either (don't think ti should re returning a result if nothings wrong to be honest)
*EDIT* I told a lie - it should be returning a result as I checked the storage manager itself (which has alerts). It just doesn't return anything. If I input the wrong password onto the command lien to be passed through, it does correctly return that the user could not be logged in due to incorrect log in:
"Couldn't connect to host-1: Error returned from Web Server, make sure certificates are created correctly (Incorrect or missing user login or password)"
Last edited by Nighthawkz on Fri Apr 13, 2018 7:57 am, edited 1 time in total.
Re: cannot run custom command from anywhere but libexec fold
When you run it from the command line, what is the exit code?
Hint:
Hint:
Code: Select all
/usr/bin/java -jar /usr/local/nagios/libexec/CompCU.jar -host <Host> -user <SCUser> -password <password> -c "<command>"
echo $?
--
D/\N
D/\N
-
- Posts: 27
- Joined: Fri Oct 20, 2017 7:05 am
Re: cannot run custom command from anywhere but libexec fold
I get a correct response if run as root:
NOTE i had to leave echo $? off. didn't like it kept telling me "Error parsing options:"
If i run as nagios i get the same response expect with an error at the end :
Code: Select all
Controller Index Alert_Type Message Status Date_Created Object_Name Category Count Acknowledged Date_Cleared Reference_Number
---------- ------ ---------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------- ------------------------ ---------------------------------------------------------------- ---------------- ------ ------------ ------------------------ ------------------------
77842 1 Alert Local ISCSI Port 0000000000000000 is Down
If i run as nagios i get the same response expect with an error at the end :
Code: Select all
Successfully finished running Compellent Command Utility (CompCU) application.
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)
java.io.FileNotFoundException: cu_output.xml (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:204)
at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
at java.io.FileWriter.<init>(FileWriter.java:57)
at com.compellent.cli.StorageCenterCLIMain.main(Unknown Source)