def _run_alarm_processor(self, alarm, sql_response, mock_log, mock_mysql):
        """Runs a mocked alarm processor reading from queue while running,
        returns (queue_message, log_message)
        """
        # Since the log runs in another thread I can mock it directly, instead
        # change the methods to put to a queue
        mock_log.warn = self.trap.append
        mock_log.error = self.trap.append
        mock_log.exception = self.trap.append

        # Setup the sql response
        if sql_response is not None:
            mock_mysql.return_value = mock_mysql
            mock_mysql.cursor.return_value = mock_mysql
            mock_mysql.__iter__.return_value = sql_response

        self.conf_override(group='mysql',
                           ssl=None,
                           host='localhost',
                           port='3306',
                           user='******',
                           db='dbname',
                           passwd='mysql_passwd')
        self.conf_override(group='statsd', host='localhost', port=8125)
        processor = alarm_processor.AlarmProcessor()

        return processor.to_notification(alarm)
示例#2
0
    def _run_alarm_processor(self, alarm, sql_response, mock_log, mock_mysql):
        """Runs a mocked alarm processor reading from queue while running, returns (queue_message, log_message)
        """
        # Since the log runs in another thread I can mock it directly, instead change the methods to put to a queue
        mock_log.warn = self.trap.append
        mock_log.error = self.trap.append
        mock_log.exception = self.trap.append

        # Setup the sql response
        if sql_response is not None:
            mock_mysql.return_value = mock_mysql
            mock_mysql.cursor.return_value = mock_mysql
            mock_mysql.__iter__.return_value = sql_response

        mysql_config = {
            'mysql': {
                'ssl': None,
                'host': 'mysql_host',
                'port': 'mysql_port',
                'user': '******',
                'db': 'dbname',
                'passwd': 'mysql_passwd'
            }
        }

        processor = alarm_processor.AlarmProcessor(600, mysql_config)

        return processor.to_notification(alarm)
 def __init__(self):
     self._statsd = get_statsd_client()
     self._consumer = consumer.KafkaConsumer(
         CONF.kafka.url, ','.join(CONF.zookeeper.url),
         CONF.zookeeper.notification_path, CONF.kafka.group,
         CONF.kafka.alarm_topic)
     self._producer = producer.KafkaProducer(CONF.kafka.url)
     self._alarms = ap.AlarmProcessor()
     self._notifier = np.NotificationProcessor()
 def __init__(self):
     self._statsd = get_statsd_client()
     self._consumer = client_factory.get_kafka_consumer(
         CONF.kafka.url, CONF.kafka.group, CONF.kafka.alarm_topic,
         CONF.zookeeper.url, CONF.zookeeper.notification_path,
         CONF.kafka.legacy_kafka_client_enabled)
     self._producer = client_factory.get_kafka_producer(
         CONF.kafka.url, CONF.kafka.legacy_kafka_client_enabled)
     self._alarms = ap.AlarmProcessor()
     self._notifier = np.NotificationProcessor()