예제 #1
0
파일: gear.py 프로젝트: ppjsand/pyteal
    def update_init_data(self):
        """ This method is called by update_init_data_main which does setup to simplify the 
        coding of this method.  
       
        This method should modify how the alert should be created by modifying self.init_dict which
        will be filled in prior to it being called and will be returned after this method returns
        """

        # Assumes that all the events have the same event id.
        events = self.get_events()
        primary_event = events[0]

        # Determine where to get the message based on the event component
        src_comp = primary_event.get_src_comp()

        if primary_event.event_id in SNMP_UNEXPECTED_EVENTS:
            # Set the reason message based on the event data
            self.init_dict[ALERT_ATTR_REASON] = SNMP_UNEXPECTED_REASON_MSG
            self.init_dict[ALERT_ATTR_RECOMMENDATION] = SNMP_UNEXPECTED_RECOMMENDATION
            self.init_dict[ALERT_ATTR_SEVERITY] = "E"

            # Include any special data in the raw data section
            self.init_dict[ALERT_ATTR_RAW_DATA] = primary_event.raw_data["raw_data"]

        elif src_comp == SNMP_IPMI:
            # Set the reason message based on the event data
            self.init_dict[ALERT_ATTR_REASON] = primary_event.raw_data[IPMI_EVENT_MSG]
            self.init_dict[ALERT_ATTR_SEVERITY] = _map_ipmi_severity(primary_event.raw_data[IPMI_EVENT_SEVERITY])

            # Include any special data in the raw data section
            self.init_dict[ALERT_ATTR_RAW_DATA] = dict2raw_data(primary_event.raw_data)

        elif src_comp == SNMP_AMM:
            # Set the reason message based on the event data
            self.init_dict[ALERT_ATTR_REASON] = primary_event.raw_data[AMM_MSG_TEXT]
            self.init_dict[ALERT_ATTR_SEVERITY] = _map_amm_severity(primary_event.raw_data[AMM_PRIORITY])

            # Include any special data in the raw data section
            self.init_dict[ALERT_ATTR_RAW_DATA] = dict2raw_data(primary_event.raw_data)

        else:
            # Unknown event source, ignore event and do no additional processing
            pass
예제 #2
0
    
    def create_alert(self, event, location):
        ''' create the alert '''
        # Populate the dictionary
        alert_dict = {}
        alert_dict[ALERT_ATTR_SRC_NAME] = self.src_name
        alert_dict[ALERT_ATTR_ALERT_ID] = self.alert_id.get_value()
        if self.severity.is_set():
            alert_dict[ALERT_ATTR_SEVERITY] = self.severity.get_value()
        if self.urgency.is_set():
            alert_dict[ALERT_ATTR_URGENCY] = self.urgency.get_value()
        if self.fru_loc.is_set():
            alert_dict[ALERT_ATTR_FRU_LOC] = self.fru_loc.get_value()
        if self.recommendation.is_set():
            alert_dict[ALERT_ATTR_RECOMMENDATION] = self.recommendation.get_value()
        if self.raw_data.is_set():
            alert_dict[ALERT_ATTR_RAW_DATA] = self.raw_data.get_value()
        if self.msg_template.is_set():
            alert_dict[ALERT_ATTR_MSG_TEMPLATE] = self.msg_template.get_value()
        if self.priority.is_set():
            alert_dict[ALERT_ATTR_PRIORITY] = self.priority.get_value()
        alert_dict[ALERT_ATTR_CONDITION_EVENTS] = set([event])
        
        if self.event_loc.is_set():
            loc = self.event_loc.get_value()
        else:
            loc = get_service(SERVICE_LOCATION).get_teal_location(self.ruleset.name)
        alert_dict[ALERT_ATTR_EVENT_LOC] = loc.get_location()
        alert_dict[ALERT_ATTR_EVENT_LOC_TYPE] = loc.get_id()
        
        # Fill in raw data
        raw_data_dict = {}
        raw_data_dict['exception'] = '{0}: {1}'.format(str(location.ex_type), str(location.ex_value))
        alert_dict[ALERT_ATTR_RAW_DATA] = dict2raw_data(raw_data_dict)
        
        # Call init routine if specified 
        if self.init_class_callable is not None:
            try:
                alert_dict = self.init_class_callable().update_init_data_main(alert_dict)
            except ThreadKilled:
                raise
            except ExtFatalError:
                get_logger().exception('FATAL ERROR raised --> kill analyzer')
                raise
            except:
                self.ruleset.trace_error(self.trace_id[1], 'Error in update_init_data_main')
                get_logger().exception('')

        # Allocate the potential alert 
        amgr = get_service(SERVICE_ALERT_MGR)
        alert = amgr.allocate(self.alert_id.get_value(), alert_dict)
        # send the alert to the delivery queue
        get_logger().debug('  creating {0}'.format(str(alert)))
        amgr.commit(alert)
        self.ruleset.send_alert(alert)
예제 #3
0
 def update_init_data_main(self, init_dict):
     ''' This is the method that is called to process the alert init dictionary
     It puts the init dictionary into self.init dictionary and sets self.raw_data_dict
     and processes them to correctly return them before it returns
     
     While this method can be overridden, it is recommended to override update_init_data
     instead.
     '''
     self.metadata_cache = None
     self.init_dict = init_dict
     if ALERT_ATTR_RAW_DATA in init_dict:
         self.raw_data_dict = raw_data2dict(init_dict[ALERT_ATTR_RAW_DATA])
     else:
         self.raw_data_dict = {}
     self.update_init_data() 
     if len(self.raw_data_dict) != 0:
         self.init_dict[ALERT_ATTR_RAW_DATA] = dict2raw_data(self.raw_data_dict)
     return self.init_dict