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
def send_alert_tosfp(self, alert): ''' Convert the alert to a service focal point log and send to the service focal point ''' get_logger().debug('In send_alert_tofsp') #================================================================== # Parameters for build() call, which will build the SFP message. # self, alert, client_name, fru_list, notif_type, # enc_mtms, pwr_mtms, neighbor_list, eed_location, # extended_data #================================================================== self.raw_data_dict = raw_data2dict(alert.raw_data) if 'fru_list' in self.raw_data_dict: fru_list = self.raw_data_dict['fru_list'] frus = str(fru_list).replace('{','').rstrip('}').split('},') get_logger().debug('There is a fru list in the raw data dict.') else: frus = [] get_logger().debug('There is no fru list in the raw data dict.') if 'encl_mtms' in self.raw_data_dict: enclos_mtms = str(self.raw_data_dict['encl_mtms']) get_logger().debug('Enclosure MTMS = {0}'.format(enclos_mtms)) else: enclos_mtms = [] get_logger().debug('There is no Enclosure MTMS in the raw data dict.') if 'pwr_enc' in self.raw_data_dict: pwr_mtms = str(self.raw_data_dict['pwr_enc']) get_logger().debug('Power Enclosure MTMS = {0}'.format(enclos_mtms)) else: pwr_mtms = [] get_logger().debug('There is no Power MTMS in the raw data dict.') notif_type = 0 cust_notif = alert.get_metadata()[META_ALERT_CUST_NOTIFICATION] if (cust_notif == 'Y'): notif_type = 1 call_home = alert.get_metadata()[META_ALERT_CALL_HOME] #================================================================== # If call_home is not set, then set to a default #================================================================== if (call_home == 'Y'): notif_type |= 16 if 'nbr_loc' in self.raw_data_dict and 'nbr_typ' in self.raw_data_dict: neighbor_list = ['{0}:{1}'.format(self.raw_data_dict['nbr_typ'], self.raw_data_dict['nbr_loc'])] else: neighbor_list = [] if 'eed_loc' in self.raw_data_dict: eed_location = str(self.raw_data_dict['eed_loc']) else: eed_location = "" extended_data = "" #get_logger().debug('FRUs = {0}'.format('\n'.join([str(fru) for fru in frus]))) get_logger().debug(' Power MTMS = {0}'.format(pwr_mtms)) get_logger().debug(' Neighbor list = {0}'.format(neighbor_list)) get_logger().debug(' EED location = {0}'.format(eed_location)) msg = SfpCreateMessage() pkt = msg.build(alert, self.client_name, frus, notif_type, enclos_mtms, pwr_mtms, neighbor_list, eed_location, extended_data) #================================================================== # The following is for DEBUGING #================================================================== #pkt_file = open('/tmp/create_msg.txt', 'a') #print >>pkt_file,pkt #pkt_file.close() self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self._connect_to_hmc() #================================================================== # Try to send the Packet to SFP, the number of times specified in # in self.sfp_retry_count #================================================================== if (self.hmc_connected == True): retries_left = self.sfp_retry_count while retries_left > 0: try: rc = self.sock.send(pkt) if rc == 0 : get_logger().exception('send failed.') else: get_logger().debug('The message has been sent to SFP of size {0}'.format(rc)) break except: retries_left -= 1 get_logger().exception('send failed. Retries left {0}'.format(retries_left)) self._connect_to_hmc() #================================================================== # Check the data returned from the send #================================================================== data = self.sock.recv(10) msg_ver, status, seq_num = struct.unpack('>BBQ', data) get_logger().debug('Message Version = {0}'.format(msg_ver)) get_logger().debug(' Status = {0}'.format(status)) get_logger().debug('Sequence number = {0}'.format(seq_num)) #================================================================== # Check the status returned: # 0 - Success the message has been sent to SFP # 1 - Message was not sent because of bad formatting # 2 - Message was not sent because of a duplicate sequence num #================================================================== if (status == 0): get_logger().debug('The message has been sent to Service Focal Point') elif (status == 1): get_logger().warning('The message has not been sent to Service Focal Point, because of bad formatting') elif (status == 2): # TODO: If 2 need to resend with the next sequence # get_logger().warning('The message has not been sent to Service Focal Point, because of duplicate sequence number') else: get_logger().warning('The message has not been sent to Service Focal Point, because of a connection loss') self.hmc_connected = False else: get_logger().warning('The message has not been sent to Service Focal Point, because of no connection to the HMC.') get_logger().warning('Here is the Alert Data:') get_logger().warning(' Alert = {0}'.format(alert)) get_logger().warning(' Client Name = {0}'.format(self.client_name)) get_logger().warning(' FRUs = {0}'.format(frus)) get_logger().warning(' Notify Type = {0}'.format(notif_type)) get_logger().warning(' Enclosure MTMS = {0}'.format(enclos_mtms)) get_logger().warning(' Power MTMS = {0}'.format(pwr_mtms)) get_logger().warning(' Neighbor List = {0}'.format(neighbor_list)) get_logger().warning(' EED Location = {0}'.format(eed_location)) get_logger().warning(' Extended Data = {0}'.format(extended_data)) self.sock.shutdown(socket.SHUT_RDWR) return