Exemple #1
0
 def handle_message(self, message):
     """
     The notifications Message Example:
     {
       'message_id': str(uuid.uuid4()),
       'event_type': 'compute.create_instance',
       'publisher_id': 'compute.host1',
       'timestamp': timeutils.utcnow(),
       'priority': 'INFO',
       'payload': {'instance_id': 12, ... }
     }
     """
     alarm_levels = utils.get_alarm_level(CONF.alarm_level)
     message_priority = message.get('priority')
     if message_priority in alarm_levels:
         # NOTE(hzyangtk): flow_data is origin data that will be filtered
         #                 alarm_type is like compute.create.start
         #                 alarm_level is like ERROR
         #                 alarm_owner is like product_manager,
         #                                     platform_manager
         flow_data = {'alarm_type': message.get('event_type'),
                      'alarm_level': message.get('priority'),
                      'alarm_owner': []}
         flow_data = self._do_filter(flow_data)
         if flow_data is not None:
             # move flow_data['alarm_owner'] to message
             message['alarm_owner'] = flow_data['alarm_owner']
             # send alarm to alarm system
             self._do_send_alarm(message)
             LOG.info('Alarm over')
Exemple #2
0
    def handle_message(self, message):
        """
        The notifications Message Example:
        {
          'message_id': str(uuid.uuid4()),
          'event_type': 'compute.create_instance',
          'publisher_id': 'compute.host1',
          'timestamp': timeutils.utcnow(),
          'priority': 'INFO',
          'payload': {'instance_id': 12, ... }
        }
        """
        try:
            # NOTE(hzyangtk): handle message before alarm like notify
            #                 cloud monitor to stop alarm when instance
            #                 was deleted.
            controller_helper.handle_before_alarm(message)

            alarm_levels = utils.get_alarm_level(CONF.alarm_level)
            message_priority = message.get('priority')
            if message_priority in alarm_levels:
                # NOTE(hzyangtk): flow_data is origin data that will be
                #                 filtered alarm_type is like
                #                 compute.create.start
                #                 alarm_level is like ERROR
                #                 alarm_owner is like product_manager,
                #                                     platform_manager
                flow_data = {
                    'alarm_type': message.get('event_type'),
                    'alarm_level': message.get('priority'),
                    'alarm_owner': []
                }
                flow_data = self._do_filter(flow_data)
                if flow_data is not None:
                    # move flow_data['alarm_owner'] to message
                    message['alarm_owner'] = flow_data['alarm_owner']
                    # send alarm to alarm system
                    self._do_send_alarm(message)
                    LOG.info('Alarm over')
        except Exception:
            LOG.exception("Alarm failed")
Exemple #3
0
    def handle_message(self, message):
        """
        The notifications Message Example:
        {
          'message_id': str(uuid.uuid4()),
          'event_type': 'compute.create_instance',
          'publisher_id': 'compute.host1',
          'timestamp': timeutils.utcnow(),
          'priority': 'INFO',
          'payload': {'instance_id': 12, ... }
        }
        """
        try:
            # NOTE(hzyangtk): handle message before alarm like notify
            #                 cloud monitor to stop alarm when instance
            #                 was deleted.
            controller_helper.handle_before_alarm(message)

            alarm_levels = utils.get_alarm_level(CONF.alarm_level)
            message_priority = message.get('priority')
            if message_priority in alarm_levels:
                # NOTE(hzyangtk): flow_data is origin data that will be
                #                 filtered alarm_type is like
                #                 compute.create.start
                #                 alarm_level is like ERROR
                #                 alarm_owner is like product_manager,
                #                                     platform_manager
                flow_data = {'alarm_type': message.get('event_type'),
                             'alarm_level': message.get('priority'),
                             'alarm_owner': []}
                flow_data = self._do_filter(flow_data)
                if flow_data is not None:
                    # move flow_data['alarm_owner'] to message
                    message['alarm_owner'] = flow_data['alarm_owner']
                    # send alarm to alarm system
                    self._do_send_alarm(message)
                    LOG.info('Alarm over')
        except Exception:
            LOG.exception("Alarm failed")
Exemple #4
0
 def testGet_alarm_level(self):
     TEST_CASE = ('INFO', 'WARN', 'ERROR', 'FATAL')
     self.assertEquals(utils.get_alarm_level(TEST_CASE[0]), ['INFO', 'WARN', 'ERROR', 'FATAL'], 'get alarm level error')
     self.assertEquals(utils.get_alarm_level(TEST_CASE[1]), ['WARN', 'ERROR', 'FATAL'], 'get alarm level error')
     self.assertEquals(utils.get_alarm_level(TEST_CASE[2]), ['ERROR', 'FATAL'], 'get alarm level error')
     self.assertEquals(utils.get_alarm_level(TEST_CASE[3]), ['FATAL'], 'get alarm level error')