class MessageHandler: def __init__(self, **kwargs): """Create Publisher.""" user, password = get_user_and_password() exchange = kwargs.get('exchange', 'exchange/%s/pulse_actions' % user) try: self.publisher = GenericPublisher( config=PulseConfiguration(user=user, password=password), exchange=exchange ) except AuthenticationError as e: print(e.message) sys.exit(1) except Exception as e: # We continue without posting to pulse print('ERROR: We failed to post a pulse message with what we did') print(e.message) def publish_message(self, data, routing_key): """Publish a message to exchange/${pulse_user}/pulse_actions.""" msg = GenericMessage() msg.routing_parts = routing_key.split('.') for key, value in data.iteritems(): msg.set_data(key, value) self.publisher.publish(msg)
def __init__(self, **kwargs): """Create Publisher.""" user, password = get_user_and_password() exchange = kwargs.get('exchange', 'exchange/%s/pulse_actions' % user) try: self.publisher = GenericPublisher( config=PulseConfiguration(user=user, password=password), exchange=exchange ) except AuthenticationError as e: print(e.message) sys.exit(1) except Exception as e: # We continue without posting to pulse print('ERROR: We failed to post a pulse message with what we did') print(e.message)
def main(): from optparse import OptionParser from mozillapulse.publishers import GenericPublisher from mozillapulse.config import PulseConfiguration import logging.handlers parser = OptionParser() parser.set_defaults( verbosity=0, logfile=None, max_retries=5, retry_time=60, ) parser.add_option("--passwords", dest="passwords") parser.add_option("-q", "--queuedir", dest="queuedir") parser.add_option("-v", "--verbose", dest="verbosity", action="count", help="increase verbosity") parser.add_option("-l", "--logfile", dest="logfile", help="where to send logs") parser.add_option("-r", "--max_retries", dest="max_retries", type="int", help="number of times to retry") parser.add_option("-t", "--retry_time", dest="retry_time", type="int", help="seconds to wait between retries") options, args = parser.parse_args() # Set up logging if options.verbosity == 0: log_level = logging.WARNING elif options.verbosity == 1: log_level = logging.INFO else: log_level = logging.DEBUG if not options.logfile: logging.basicConfig(level=log_level, format="%(asctime)s - %(message)s") else: logger = logging.getLogger() logger.setLevel(log_level) handler = logging.handlers.RotatingFileHandler(options.logfile, maxBytes=1024**2, backupCount=5) formatter = logging.Formatter("%(asctime)s - %(message)s") handler.setFormatter(formatter) logger.addHandler(handler) if not options.passwords: parser.error("--passwords is required") if not options.queuedir: parser.error("-q/--queuedir is required") passwords = {} execfile(options.passwords, passwords, passwords) publisher = GenericPublisher(PulseConfiguration( user=passwords['PULSE_USERNAME'], password=passwords['PULSE_PASSWORD'], ), exchange=passwords['PULSE_EXCHANGE']) pusher = PulsePusher(options.queuedir, publisher, max_retries=options.max_retries, retry_time=options.retry_time) pusher.loop()
def __init__(self, **kwargs): GenericPublisher.__init__(self, PulseConfiguration(**kwargs), 'org.mozilla.exchange.bugzilla')