def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._statsd = monascastatsd.Client(name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer(config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) if 'ssl' in config['mysql']: ssl_config = config['mysql']['ssl'] else: ssl_config = None self._alarms = AlarmProcessor(config['processors']['alarm']['ttl'], config['mysql']['host'], config['mysql']['user'], config['mysql']['passwd'], config['mysql']['db'], ssl_config) self._notifier = NotificationProcessor(config['notification_types'])
class NotificationEngine(object): def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._statsd = monascastatsd.Client(name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer(config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._notifier = NotificationProcessor(config['notification_types']) def run(self): finished_count = self._statsd.get_counter(name='alarms_finished_count') for alarm in self._consumer: log.debug('Received alarm >|%s|<', str(alarm)) notifications, partition, offset = self._alarms.to_notification(alarm) if notifications: sent, failed = self._notifier.send(notifications) self._producer.publish(self._topics['notification_topic'], [i.to_json() for i in sent]) self._producer.publish(self._topics['retry_topic'], [i.to_json() for i in failed]) self._consumer.commit() finished_count.increment()
def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka'][ 'notification_topic'] self._topics['retry_topic'] = config['kafka'][ 'notification_retry_topic'] self._statsd = monascastatsd.Client( name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer( config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._notifier = NotificationProcessor(config['notification_types'])
class NotificationEngine(object): def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka'][ 'notification_topic'] self._topics['retry_topic'] = config['kafka'][ 'notification_retry_topic'] self._statsd = monascastatsd.Client( name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer( config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._notifier = NotificationProcessor(config['notification_types']) def run(self): finished_count = self._statsd.get_counter(name='alarms_finished_count') for alarm in self._consumer: log.debug('Received alarm >|%s|<', str(alarm)) notifications, partition, offset = self._alarms.to_notification( alarm) if notifications: sent, failed = self._notifier.send(notifications) self._producer.publish(self._topics['notification_topic'], [i.to_json() for i in sent]) self._producer.publish(self._topics['retry_topic'], [i.to_json() for i in failed]) self._consumer.commit() finished_count.increment()
class NotificationEngine(BaseEngine): def __init__(self, config): super(NotificationEngine, self).__init__(config, config['kafka']['alarm_topic'], config['zookeeper']['notification_path']) self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._finished_count = self._statsd.get_counter(name=ALARMS_FINISHED_COUNT) self._notifier = NotificationProcessor(config) def _add_periodic_notifications(self, notifications): for notification in notifications: topic = notification.periodic_topic if topic in self._config['kafka']['periodic'] and notification.type == "webhook": notification.notification_timestamp = time.time() self._producer.publish(self._config['kafka']['periodic'][topic], [notification.to_json()]) def do_message(self, alarm): log.debug('Received alarm >|%s|<', str(alarm)) notifications, partition, offset = self._alarms.to_notification(alarm) if notifications: self._add_periodic_notifications(notifications) sent, failed = self._notifier.send(notifications) self.publish_messages(sent, self._topics['notification_topic']) self.publish_messages(failed, self._topics['retry_topic']) self._consumer.commit() self._finished_count.increment()
def __init__(self, config): super(NotificationEngine, self).__init__(config, config['kafka']['alarm_topic'], config['zookeeper']['notification_path']) self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._finished_count = self._statsd.get_counter(name=ALARMS_FINISHED_COUNT) self._notifier = NotificationProcessor(config)
def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._statsd = monascastatsd.Client(name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer(config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) self._alarm_ttl = config['processors']['alarm']['ttl'] self._alarms = AlarmProcessor(self._alarm_ttl, config) self._notifier = NotificationProcessor(config['notification_types'])
class NotificationEngine(object): def __init__(self, config): self._topics = {} self._topics['notification_topic'] = config['kafka']['notification_topic'] self._topics['retry_topic'] = config['kafka']['notification_retry_topic'] self._statsd = monascastatsd.Client(name='monasca', dimensions=BaseProcessor.dimensions) self._consumer = KafkaConsumer(config['kafka']['url'], config['zookeeper']['url'], config['zookeeper']['notification_path'], config['kafka']['group'], config['kafka']['alarm_topic']) self._producer = KafkaProducer(config['kafka']['url']) if 'ssl' in config['mysql']: ssl_config = config['mysql']['ssl'] else: ssl_config = None self._alarms = AlarmProcessor(config['processors']['alarm']['ttl'], config['mysql']['host'], config['mysql']['user'], config['mysql']['passwd'], config['mysql']['db'], ssl_config) self._notifier = NotificationProcessor(config['notification_types']) def run(self): finished_count = self._statsd.get_counter(name='alarms_finished_count') for alarm in self._consumer: notifications, partition, offset = self._alarms.to_notification(alarm) if notifications: sent, failed = self._notifier.send(notifications) self._producer.publish(self._topics['notification_topic'], sent) self._producer.publish(self._topics['retry_topic'], failed) self._consumer.commit([partition]) finished_count.increment()