Skip to content

Instantly share code, notes, and snippets.

@elubow
Created March 9, 2012 21:08
Show Gist options
  • Save elubow/2008708 to your computer and use it in GitHub Desktop.
Save elubow/2008708 to your computer and use it in GitHub Desktop.

Revisions

  1. 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')
  2. 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))