Skip to content

Instantly share code, notes, and snippets.

@devdazed
Forked from elubow/gist:2008708
Created April 24, 2012 16:34
Show Gist options
  • Save devdazed/2481257 to your computer and use it in GitHub Desktop.
Save devdazed/2481257 to your computer and use it in GitHub Desktop.

Revisions

  1. devdazed revised this gist Apr 24, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    #foobar
    # Send the passive service check back to Nagios
    logger.debug("Constructing the Nagios result string")
    nag_message = config.get('nagios','message')
  2. @elubow elubow revised this gist Mar 9, 2012. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,6 @@
    except Exception, e:
    nag_status = 2
    nag_message = "%s" % (e)
    if isinstance(e, MySQLdb.Error):
    nag_message = """Error %d: %s""" % (e.args[0], e.args[1])
    traceback.print_exc()
    logger.error(nag_message)

    # Nagios passive status update
    nag_localhost_name = config.get('nagios','localhost_name')
  3. @elubow elubow created this gist Mar 9, 2012.
    23 changes: 23 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Send the passive service check back to Nagios
    logger.debug("Constructing the Nagios result string")
    nag_message = config.get('nagios','message')
    nag_status = 0
    logger.info("Passive check result sent to Nagios")

    except Exception, e:
    nag_status = 2
    nag_message = "%s" % (e)
    if isinstance(e, MySQLdb.Error):
    nag_message = """Error %d: %s""" % (e.args[0], e.args[1])
    traceback.print_exc()
    logger.error(nag_message)

    # Nagios passive status update
    nag_localhost_name = config.get('nagios','localhost_name')
    nag_remote_service_name = config.get('nagios','remote_service_name')
    nag_servers = config.get('nagios','servers')
    # Structure: $nagios_machine_name;$check_name;<status_int>;message
    nagios_result = """%s;%s;%s;%s in %s""" % (nag_localhost_name,nag_remote_service_name,nag_status,nag_message,total_human_time)

    for host in nag_servers.split(','):
    result = os.system("/bin/echo '%s' | /usr/sbin/send_nsca -c /etc/nagios/send_nsca.cfg -H %s -d ';'" %(nagios_result,host))