Page 2 of 2
Re: Exit code - Python script
Posted: Thu May 22, 2014 12:33 am
by amitdaniel
i'm define the command like that :
Code: Select all
define command{
command_name check_cloud_watch
command_line /usr/bin/python /usr/local/nagios/libexec/check_cloud_watch.py
}
You mean that i have to change the command like that :
Code: Select all
define command{
command_name check_cloud_watch
command_line /usr/local/nagios/libexec/check_cloud_watch.py
}
Already tried this and it's not working.
Re: Exit code - Python script
Posted: Thu May 22, 2014 4:31 pm
by sreinhardt
hmm, ok. I know you are able to run the script and get reasonable output back. Have you tried su-ing to the nagios user and executing it, to make sure that you are not erroring there?
Re: Exit code - Python script
Posted: Sun May 25, 2014 3:33 am
by amitdaniel
yes of course .
if i run the script with nagios user everything is working fine.
(Manually run)
Re: Exit code - Python script
Posted: Sun May 25, 2014 10:35 pm
by eloyd
Please run your script as the nagios user, replacing all command line arguments with their appropriate values, and then type this immediately after the script stops:
Please verify that the exit status (which is what the $? variable is) matches what you expect.
Re: Exit code - Python script
Posted: Mon May 26, 2014 4:15 am
by amitdaniel
Guys ,
Thank you all but i resolved the issue .
let me share with you the solution.
When you run the script with nagios / root you must create a file called .boto in the home directory with the accessKey & SecretKey.
BUT when nagios run the script like daemon we need to use another method that include the AccessKey & SecretKey inside the script.
Code: Select all
Cloudwatch_Connection_Virginia = boto.ec2.cloudwatch.CloudWatchConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, True, None, None, None, None, None, 0, None)
AFTER THAT
Code: Select all
Alarm_Virginia = Cloudwatch_Connection_Virginia.describe_alarms(None, None, None, None, "ALARM", None
Now everything is working fine
Thank you all for your great help !!!!!
Re: Exit code - Python script
Posted: Mon May 26, 2014 1:42 pm
by eloyd
Glad to hear it is working!
Re: Exit code - Python script
Posted: Tue May 27, 2014 3:47 am
by Stuart Watts
This sort of thing catches me out far too often!
I'm trying to make a habit of testing plugins like:
Code: Select all
su - nagios -c "/usr/local/nagios/libexec/check_something -H somehost -w 1 -c 2"
Also, you shouldn't be logged in as 'root', ideally!
Re: Exit code - Python script
Posted: Tue May 27, 2014 5:05 am
by liquidcool
Instead of using print use sys.stdout.write
Makes the code a little better.
Re: Exit code - Python script
Posted: Tue May 27, 2014 9:33 am
by tmcdonald
Closing as resolved.