Skip navigation
1 2 Previous Next 9548 Views 22 Replies Latest reply: Apr 3, 2012 9:56 AM by dpetzel RSS
john55 Rank: White Belt 28 posts since
Dec 12, 2007
Currently Being Moderated

Feb 12, 2008 7:28 PM

Nagios plug-in COMMAND output problem - help!

Hello, I'm trying to install a mysql check slave nagios plug-in for Zenoss. I've been reading through all sorts of documenation and ran into a wall. Maybe someone who is familiar with nagios plugins for Zenoss can shed some light.

The nagios plugin I want to install is a perl script check-mysql-slave.pl. When running the script on command line:

 

 

/bi/usr/local/zenoss/libexec/check-mysql-slave.pl --host=hostxxx.com --port=3306 --user=userxxx --password=pass'



I recieve a good output


 

 

OK - Waiting for master to send event, replicating host (ip):3306



This means that replication is working and the script does what it is asked for.

So now the problem occurs when trying to add the template for this. I created a local copy of my template. Go into datasource and create a new Command datasource. Added the command into the command template and save. Now I got back into the command line and run:

 

 

/usr/local/zenoss/bin/zencommand run -d hostxxx.com -v10




I get the following results:

 

 


DEBUG:zen.zencommand:Command: '/bin/sh -c exec /usr/local/zenoss/libexec/check-mysql-slave.pl --host=hostxxx.com --port=3306 --user=user --password=(pass)'
DEBUG:zen.zencommand:Output: ''
DEBUG:zen.zencommand:Process check-mysql-slave.pl --host=hostxxx.com --port=3306 --user=user --password=(pass) stopped (255), 0.085734 elapsed
DEBUG:zen.zencommand:The result of "/usr/local/zenoss/libexec/check-mysql-slave.pl --host=hostxxx.com --port=3306 --user=user --password=(pass)' was ""




It seems as though it is not returning an output. I then try to run : /bin/sh -c exec /usr/local/zenoss/libexec/check-mysql-slave.pl --host=hostxxx.com --port=3306 --user=user --password=(pass)

And this does not give an output. So I created a simple script that gives me the time and run that script against the /bin/sh -c exec command and it still does not output.


Any idea what might be the problem?
  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    1. Mar 25, 2012 8:55 AM (in response to john55)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi John,

     

    Where you able to solve this one?

    I'm having the same problem.

     

    Thanks in advance,

    Tzach

  • jmp242 ZenossMaster 4,060 posts since
    Mar 7, 2007
    Currently Being Moderated
    2. Mar 26, 2012 7:57 AM (in response to Tzach Solomon)
    Re: Nagios plug-in COMMAND output problem - help!

    Back from the dead thread here - I don't know if the OP ever solved this, but the issue is that the format returned is not what Zenoss is looking for.

    See:

    https://zcaportal.org/wiki/bin/view/ZCA/ZCAFAQ#Command_Based_Data_Sources

     

    --

    James Pulver

    ZCA Member

    LEPP Computer Group

    Cornell University

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    3. Mar 26, 2012 8:14 AM (in response to jmp242)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi jmp242,

     

    Thanks for replying.

    I have found my scripts are getting the return code 1 ( General error ) when I use the logging.basicConfig function in my scripts.

    When I mask them, zencommand run myscripts perfectly with return code 0 - Success.

     

    I've developed my scripts with python 2.7 and I see zenoss is using python 2.6.2, maybe logging.basicConfig isn't supported by python 2.6.2?

     

    Thanks in advanced for any help

    Tzach

  • dpetzel Rank: Brown Belt 1,141 posts since
    Oct 17, 2010
    Currently Being Moderated
    4. Mar 26, 2012 8:51 AM (in response to Tzach Solomon)
    Re: Nagios plug-in COMMAND output problem - help!

    basicConfig has been around a while, it should work just fine in 2.6.2. I actually use it in many of my dmd scripts (albeit I've not tried it in a command data source, but I can see why it would make a difference).

     

    Are you sure you are properly using the basicConfig method? If you create a simple .py file with a main, and you run it, what is the exit code as seen by the OS?

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    5. Mar 26, 2012 11:05 AM (in response to dpetzel)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi Dpetzel,

     

    Thanks for the response

     

    Here are both the script and result in zencommand debug.

    Notice the return code of zencommand.

     

    am I doing something wrong?

     

    This is the check.py:

     

    #!/usr/local/zenoss/zenoss/bin/python

    # Logging configuration

    import logging

    # change this to logging.DEBUG for more information

    logLevel = logging.INFO

     

     

    logname='check'

    logger = logging.getLogger(logname)

    formatString = '%(asctime)s - %(name)s - %(levelname)s - %(filename)s - %(funcName)s - %(message)s'

    logging.basicConfig(filename=logname, level=logLevel, filemode='w', format=formatString)

    consoleLogger = logging.StreamHandler()

    consoleLogger.setLevel(logLevel)

    # create formatter

    formatter = logging.Formatter(formatString)

    # add formatter to console

    consoleLogger.setFormatter(formatter)

    print "COMMAND OK|test=1"

     

     

    This is the zencommand debug log:

     

    2012-03-26 17:03:12,443 DEBUG zen.zencommand: Total of 1 queued events

    2012-03-26 17:03:19,062 DEBUG zen.zencommand: running '/usr/local/zenoss/scripts/check.py'

    2012-03-26 17:03:19,062 DEBUG zen.zencommand: cmd line: '/bin/sh -c exec /usr/local/zenoss/scripts/check.py'

    2012-03-26 17:03:19,069 DEBUG zen.zencommand: Process check.py  started

    2012-03-26 17:03:19,070 DEBUG zen.zencommand: Next command in 28 seconds

    2012-03-26 17:03:19,174 DEBUG zen.zencommand: Received exit code: 1

    2012-03-26 17:03:19,175 DEBUG zen.zencommand: Command: '/bin/sh -c exec /usr/local/zenoss/scripts/check.py'

    2012-03-26 17:03:19,175 DEBUG zen.zencommand: Output: ''

    2012-03-26 17:03:19,176 DEBUG zen.zencommand: Process check.py  stopped (1), 0.11 seconds elapsed

    2012-03-26 17:03:19,176 DEBUG zen.zencommand: The result of "/usr/local/zenoss/scripts/check.py" was "''"

    2012-03-26 17:03:19,178 DEBUG zen.zencommand: Queueing event {'severity': 3, 'performanceData': '', 'component': '', 'agent': 'zencommand', 'summary': 'Cmd: /usr/local/zenoss/scripts/check.py - Code: 1 - Msg: General error', 'manager': 'zenossu.il.imperva.com', 'eventKey': 'Check', 'device': '10.1.13.101', 'message': 'Cmd: /usr/local/zenoss/scripts/check.py - Code: 1 - Msg: General error', 'eventClass': '/Cmd/Fail', 'monitor': 'localhost'}

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009
    Currently Being Moderated
    6. Mar 26, 2012 11:02 PM (in response to Tzach Solomon)
    Re: Nagios plug-in COMMAND output problem - help!

    Tzach:

     

    You'll need to pass an exit code.

     

    import sys

     

    sys.exit(0)

     

    Best,

    --Shane (Hackman238)

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    7. Mar 27, 2012 3:48 AM (in response to Shane Scott)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi Shane,

     

    I added sys.exit(0) at the end of the script.

    Still, zencommand return with exit code 1

     

    2012-03-27 09:47:38,168 DEBUG zen.zencommand: Next command in 160 seconds

    2012-03-27 09:47:38,273 DEBUG zen.zencommand: Received exit code: 1

    2012-03-27 09:47:38,274 DEBUG zen.zencommand: Command: '/bin/sh -c exec /usr/local/zenoss/scripts/check.py'

    2012-03-27 09:47:38,275 DEBUG zen.zencommand: Output: ''

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009
    Currently Being Moderated
    8. Mar 29, 2012 1:40 AM (in response to Tzach Solomon)
    Re: Nagios plug-in COMMAND output problem - help!

    Tzach:

     

    Really? Thats bizarre. Is anything in the script failing?

     

    --Shane

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    9. Mar 29, 2012 7:46 AM (in response to Shane Scott)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi Shane,

     

    1st, Thanks for replying

     

    2nd, nope, nothing else is failing...

     

    The problem is I can't debug why it return the exit code 1.

    From what I have found out the zencommand.py is executed using twisted module.

    The function that recieve the return code is:

     

    def processEnded(self, reason):

            "notify the starter that their process is complete"

            self.exitCode = reason.value.exitCode

            log.debug('Received exit code: %s' % self.exitCode)

            log.debug('Command: %r' % self.command)

            log.debug('Output: %r' % self.output)

     

    This function is located, at least in my install here:

    /usr/local/zenoss/zenoss/Products/ZenRRD

     

    BTW, this an ubutnu server and zenoss installed on it.

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009

    Tzach:

     

    Try passing an arbitray code like 42 or 75. See if the code is passed correctly. This is very interesting.

     

    --Shane

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    11. Apr 1, 2012 3:17 AM (in response to Shane Scott)
    Re: Nagios plug-in COMMAND output problem - help!

    Shane:

     

     

    It seems sys.exit doesn't matter to the zencommand, I get the same result.

     

    Meaning if the script has the line:

    logging.basicConfig(filename=logname, level=logLevel, filemode='w', format=formatString)

     

    Then I get following:

    2012-04-01 10:13:15,126 DEBUG zen.zencommand: running '/usr/local/zenoss/scripts/check.py'

    2012-04-01 10:13:15,126 DEBUG zen.zencommand: cmd line: '/bin/sh -c exec /usr/local/zenoss/scripts/check.py'

    2012-04-01 10:13:15,128 DEBUG zen.zencommand: Process check.py  started

    2012-04-01 10:13:15,129 DEBUG zen.zencommand: Next command in 8 seconds

    2012-04-01 10:13:15,227 DEBUG zen.zencommand: Received exit code: 1

     

     

    If I mask the logging.basicConfig with # like this:

    #logging.basicConfig(filename=logname, level=logLevel, filemode='w', format=formatString)

     

     

    I get the following:

     

     

    2012-04-01 10:13:25,305 DEBUG zen.zencommand: Command: '/bin/sh -c exec /usr/local/zenoss/scripts/check.py'

    2012-04-01 10:13:25,306 DEBUG zen.zencommand: Output: 'COMMAND OK|test=1\n'

    2012-04-01 10:13:25,306 DEBUG zen.zencommand: Process check.py  stopped (47), 0.07 seconds elapsed

    2012-04-01 10:13:25,306 DEBUG zen.zencommand: The result of "/usr/local/zenoss/scripts/check.py" was "'COMMAND OK|test=1\n'"

    2012-04-01 10:13:25,307 DEBUG zen.zencommand: Queueing event {'severity': 3, 'performanceData': 'test=1', 'component': '', 'agent': 'zencommand', 'summary': 'COMMAND OK', 'manager': 'zenossu.il.check.com', 'eventKey': 'Check', 'device': '10.1.13.118', 'message': 'COMMAND OK', 'eventClass': '/Cmd/Fail', 'monitor': 'localhost'}

    2012-04-01 10:13:25,307 DEBUG zen.zencommand: Total of 1 queued events

    2012-04-01 10:13:25,308 DEBUG zen.zencommand: Next command in 9 seconds

    2012-04-01 10:13:26,952 DEBUG zen.zencommand: Received exit code: 0

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009

    Tzach:

     

    Interesting. I'm going to tes this in other versions monday and get back to you. Looks like a bug.

     

    --Shane

  • dpetzel Rank: Brown Belt 1,141 posts since
    Oct 17, 2010
    Currently Being Moderated
    13. Apr 1, 2012 4:43 PM (in response to Shane Scott)
    Re: Nagios plug-in COMMAND output problem - help!

    Tzach, I was able to recreate a similar sitation if permissions on "check"  (The file) don't have write permissions. Is it possible that the "check" file doesn't have permissions for the zenoss user to write/append?

     

    In my attempts to reproduce, I ran the check.py first as root, then switched to the zenoss user and manually ran check.py. In this case I did see a stack trace (unsure if zencommand might swallow it), but I did get an exit code of 1.

     

    It might be worth checking the permissions.

  • Tzach Solomon Rank: White Belt 15 posts since
    Mar 20, 2012
    Currently Being Moderated
    14. Apr 2, 2012 2:42 AM (in response to dpetzel)
    Re: Nagios plug-in COMMAND output problem - help!

    Hi Dpetzel, Shane,

     

    First of all, WOW, much thanks for the help and time!

    Really appreciate it

     

    2nd, here the permissions:

     

    -rwxrwxr-x 1 zenoss zenoss   647 2012-04-01 10:13 check.py

     

    BTW, my system is:

    Linux zenossu 3.0.0-12-generic-pae #20-Ubuntu SMP Fri Oct 7 16:37:17 UTC 2011 i686 i686 i386 GNU/Linux

    Zenoss version 3.2.1

1 2 Previous Next

More Like This

  • Retrieving data ...