Exit code - Python script

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.
amitdaniel
Posts: 25
Joined: Mon Jul 01, 2013 9:17 am

Re: Exit code - Python script

Post 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.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Exit code - Python script

Post 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?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
amitdaniel
Posts: 25
Joined: Mon Jul 01, 2013 9:17 am

Re: Exit code - Python script

Post by amitdaniel »

yes of course .
if i run the script with nagios user everything is working fine.
(Manually run)
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Exit code - Python script

Post 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:

Code: Select all

echo $?
Please verify that the exit status (which is what the $? variable is) matches what you expect.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
amitdaniel
Posts: 25
Joined: Mon Jul 01, 2013 9:17 am

Re: Exit code - Python script

Post 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 !!!!!
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Exit code - Python script

Post by eloyd »

Glad to hear it is working!
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Stuart Watts
Posts: 40
Joined: Wed Sep 25, 2013 7:01 am

Re: Exit code - Python script

Post 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!
liquidcool
Posts: 59
Joined: Tue Feb 21, 2012 6:08 am

Re: Exit code - Python script

Post by liquidcool »

Instead of using print use sys.stdout.write
Makes the code a little better.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Exit code - Python script

Post by tmcdonald »

Closing as resolved.
Former Nagios employee
Locked