Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """Custom ActionRule/ZenAction processor for sending xmpp messages"""
- import Globals
- import sys
- from Products.ZenUtils.Utils import monkeypatch
- from Products.ZenEvents.zenactions import *
- target = getattr(sys.modules['Products.ZenEvents.zenactions'], 'ZenActions')
- @monkeypatch(target)
- def mainbody(self):
- """main loop to run actions.
- """
- from twisted.internet.process import reapAllProcesses
- reapAllProcesses()
- zem = self.dmd.ZenEventManager
- self.loadActionRules()
- self.processRules(zem)
- @monkeypatch(target)
- def runCycle(self):
- try:
- start = time.time()
- self.syncdb()
- self.mainbody()
- self.log.info("processed %s rules in %.2f secs", len(self.actions), time.time()-start)
- self.sendHeartbeat()
- except:
- self.log.exception("unexpected exception")
- reactor.callLater(60, self.runCycle)
- @monkeypatch(target)
- def run(self):
- self.schedule.start()
- self.runCycle()
- reactor.run()
- @monkeypatch(target)
- def sendXmpp(self, action, data, clear = None):
- fmt, body = self.format(action, data, clear)
- recipients = action.getAddresses()
- if not recipients:
- self.log.warning('failed to send message %s on rule %s: %s', action.getUser().id, action.id, 'Unspecified recipient.')
- return True
- for recipient in recipients:
- self.log.info('Sending message to %s: %s', recipient, fmt)
- return True
- if __name__=='__main__':
- za = ZenActions()
- # filter out actions that we are not interested in
- za.actions = filter(lambda ar: ar.action.title() != 'Xmpp', za.actions)
- import logging
- logging.getLogger('zen.Events').setLevel(90)
- za.run()
Add Comment
Please, Sign In to add comment