def mq_callback(ch, method, properties, body) :
body = loads(body)
args = body.get("args")
host = body.get("host")
port = body.get("host")
time = body.get("time")
uuid = body.get("uuid")
raw = body.get("raw")
event = body.get("event")
col.log.insert(body)
result = None
pprint(body)
for rule in col.rules.find() :
title = rule.get("title")
condition = rule.get("condition")
actions = rule.get("actions")
execute = rule.get('exec')
for k,v in condition.iteritems() :
try :
test = args[int(k)] == v
except :
pass
if test :
print "Executing %s" % title
# See if there's an exec block
if execute :
typeof = execute.get('type')
valof = execute.get('value')
print "%s:%s" % (typeof, valof)
if typeof == 'JSON' :
try :
result = requests.post(valof, json=dumps(body)).json().get('result')
args.append(result)
except :
pass
for action in actions :
# this stupid thing just replaces vars in the string
argdict = dict(k for k in enumerate(args))
argdict.update({'result': result})
final = dict([(str(k), v) for k, v in argdict.items()])
try :
msg = action % final # {str(k) : v for k, v in enumerate(args)}
except :
return
print "MESSAGE : %s" % msg
for ms in msg.split("\n") :
sock.send(ms+"\r\n")
评论列表
文章目录