update procmail script to use REST dispatch
This commit is contained in:
parent
78b0f4267a
commit
f2d72e322d
|
@ -11,7 +11,8 @@ import os
|
|||
import re
|
||||
import sys
|
||||
import time
|
||||
import xmlrpc.client
|
||||
|
||||
import requests
|
||||
|
||||
# set up some basic logging
|
||||
logger = logging.getLogger()
|
||||
|
@ -35,10 +36,7 @@ if (args.filename == None or args.key == None or args.user == None or
|
|||
|
||||
password = getpass.getpass("password for {0:s}: ".format(args.user))
|
||||
|
||||
drbotzo = xmlrpc.client.ServerProxy("https://{0:s}:{1:s}@{2:s}".format(args.user, password, args.location))
|
||||
if 'dispatch' not in drbotzo.system.listMethods():
|
||||
print("remote dr.botzo instance doesn't seem to implement 'dispatch'!")
|
||||
sys.exit(2)
|
||||
auth = requests.auth.HTTPBasicAuth(args.user, password)
|
||||
|
||||
file = open(args.filename, 'r')
|
||||
|
||||
|
@ -113,7 +111,10 @@ while 1:
|
|||
|
||||
if sender and subject:
|
||||
logger.debug("notifying: '{0:s}' from {1:s}".format(subject, sender))
|
||||
drbotzo.dispatch(args.key, "'{0:s}' from {1:s}".format(subject, sender))
|
||||
message = "[{0:s}] '{1:s}' from {2:s}".format(args.key, subject, sender)
|
||||
payload = {'message': message}
|
||||
r = requests.post(args.location, verify=False, auth=auth, data=payload)
|
||||
print(r.json())
|
||||
except UnicodeDecodeError as e:
|
||||
logger.error("Error: " + str(e) + ", skipping")
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue