Source

pyohio_talk / alerting_example.py

Full commit
import time, sys
from pysp.splunk_examples import SplunkExamples

eg = SplunkExamples()

def create_alert_for_nagios():
    errors = eg.errors_last_hour(max_count=100)

    while not errors.isDone:
        continue

    if errors.resultCount == 0:
        print "No errors in the last hour"
        erorrs.cancel()
        sys.exit(0)
    elif errors.resultCount > 0 and errors.resultCount < 10:
        print "%d errors in the last hour" % errors.resultCount
        erorrs.cancel()
        sys.exit(1)
    elif errors.resultCount > 10:
        print "%d+ errors in the last hour" % errors.resultCount
        erorrs.cancel()
        sys.exit(2)

if __name__ == '__main__':
    create_alert_for_nagios()