# HG changeset patch # User Tero Marttila # Date 1358029559 -7200 # Node ID 49e13576d77c82f46cf00e6a6ec59bc7b2c49d27 # Parent 8127c0f4223d22679a835d843f883000850af625 pvl.irker-syslog: implement a crude mainloop using syslog, to detect EOF on irker diff -r 8127c0f4223d -r 49e13576d77c bin/pvl.irker-syslog --- a/bin/pvl.irker-syslog Sun Jan 13 00:25:01 2013 +0200 +++ b/bin/pvl.irker-syslog Sun Jan 13 00:25:59 2013 +0200 @@ -73,27 +73,49 @@ irker[options.irker_target] log.info("Process syslog messages...") - for item in syslog.main() : - match, rulepath, apply = rules.apply(item) - - log.debug("%s: %s: %s", item, rulepath, apply) - - target = apply.get('irk', options.irker_target) - - tag = '/'.join(str(rule) for rule in reversed(rulepath[:-1])) - text = apply.get('text') + + # customized mainloop that supports irker.irk + while True : + if irker.irk.recv : + reading = (irker.irk, ) + else : + reading = () + + poll = syslog.poll(reading=reading) or () # timeout -> () + + if irker.irk in poll : + # irk + try : + for msg in irker.irk : + log.info("irk: %s", msg) + + except EOFError : + # exit + log.error("irk: EOF") + return 1 + + # syslogs, even on timeout + for item in syslog : + match, rulepath, apply = rules.apply(item) + + log.debug("%s: %s: %s", item, rulepath, apply) + + target = apply.get('irk', options.irker_target) + + tag = '/'.join(str(rule) for rule in reversed(rulepath[:-1])) + text = apply.get('text') + + log.info("%s: %s: %s", target, tag, text) + + if not text : + # XXX: plain irk = ... in rule is broken, as it always applies, and skips any further rules + continue + + if irker and target : + irker[target]('[' + tag + '] ' + text) + else : + print tag, text - log.info("%s: %s: %s", target, tag, text) - - if not text : - # XXX: plain irk = ... in rule is broken, as it always applies, and skips any further rules - continue - - if irker and target : - irker[target]('[' + tag + '] ' + text) - else : - print tag, text - # done log.info("Exiting...") return 0