Created
March 6, 2014 10:30
-
-
Save crashdump/9386980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# set expandtab ts=4 sw=4 ai | |
import os, sys | |
import time | |
import random | |
import string | |
import prowlpy | |
from twisted.python import log | |
def randomid(length): | |
chars = '%s%s' % (string.lowercase, string.digits) | |
return ''.join(random.choice(chars) for i in range(length)) | |
def app(): | |
time.sleep(1) | |
log.msg('prowl called, rcpt is %s and subject is %s' % (apikey, subject)) | |
p = prowlpy.Prowl(apikey) | |
try: | |
p.add('Zabbix', subject, body, 1, None) | |
print 'Success' | |
except Exception,msg: | |
print msg | |
if __name__ == '__main__': | |
#exit(0) | |
if len(sys.argv[1:]) != 3: | |
print "usage: ./prowl.py <api> <subject> <message>" | |
exit(1) | |
apikey = sys.argv[1:][0] | |
subject = sys.argv[1:][1] | |
body = sys.argv[1:][2] | |
# log output | |
logfile = open('/var/log/zabbix-server/prowl.log', 'a') | |
log.startLogging(logfile) # or sys.stdout | |
log.callWithContext({'system' : randomid(8)}, app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment