def parse_alert(context, alert): try: alert_model = dict() alert_model['alert_id'] = alert.get(AlertHandler.OID_SYMPTOMID) trap_map_desc = consts.TRAP_DESC.get( alert.get(AlertHandler.OID_SYMPTOMID)) if trap_map_desc: alert_desc = trap_map_desc[2] else: alert_desc = alert.get(AlertHandler.OID_SYMPTOMTEXT) alert_model['alert_name'] = alert.get(AlertHandler.OID_SYMPTOMTEXT) alert_model['severity'] = AlertHandler.TRAP_LEVEL_MAP.get( alert.get(AlertHandler.OID_SEVERITY), constants.Severity.INFORMATIONAL) alert_model['category'] = constants.Category.FAULT alert_model['type'] = constants.EventType.EQUIPMENT_ALARM occur_time = utils.utcnow_ms() alert_model['occur_time'] = occur_time alert_model['description'] = alert_desc alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE alert_model['location'] = alert.get(AlertHandler.OID_NODE) alert_model['match_key'] = hashlib.md5(alert.get( AlertHandler.OID_SYMPTOMTEXT).encode()).hexdigest() return alert_model except Exception as e: LOG.error(e) msg = (_("Failed to build alert model as some attributes missing")) raise exception.InvalidResults(msg)
def parse_alert(context, alert): try: alert_model = dict() alert_model['alert_id'] = alert.get(consts.PARSE_ALERT_ALERT_ID) alert_model['severity'] = consts.PARSE_ALERT_SEVERITY_MAP.get( alert.get(consts.PARSE_ALERT_SEVERITY), constants.Severity.NOT_SPECIFIED) alert_model['category'] = constants.Category.FAULT alert_model['occur_time'] = utils.utcnow_ms() alert_model['description'] = '({}:{}): {}'.format( alert.get(consts.PARSE_ALERT_STORAGE_NAME), alert.get(consts.PARSE_ALERT_CONTROLLER_NAME), alert.get(consts.PARSE_ALERT_DESCRIPTION)) alert_model['location'] = alert.get( consts.PARSE_ALERT_CONTROLLER_NAME) alert_model['type'] = constants.EventType.EQUIPMENT_ALARM alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE alert_model['alert_name'] = alert.get( consts.PARSE_ALERT_ALERT_NAME) alert_model['sequence_number'] = alert.get( consts.PARSE_ALERT_ALERT_ID) alert_model['match_key'] = hashlib.md5( str(alert.get( consts.PARSE_ALERT_ALERT_ID)).encode()).hexdigest() return alert_model except Exception as e: LOG.error(e) msg = (_("Failed to build alert model as some attributes missing")) raise exception.InvalidResults(msg)
def test_dispatch_snmp_validation_alert(self): validator = snmp_validator.SNMPValidator() storage = fakes.FAKE_STOTRAGE alert = { 'storage_id': storage['id'], 'storage_name': storage['name'], 'vendor': storage['vendor'], 'model': storage['model'], 'serial_number': storage['serial_number'], 'alert_id': constants.SNMP_CONNECTION_FAILED_ALERT_ID, 'sequence_number': 0, 'alert_name': 'SNMP connect failed', 'category': constants.Category.FAULT, 'severity': constants.Severity.MAJOR, 'type': constants.EventType.COMMUNICATIONS_ALARM, 'location': 'NetworkEntity=%s' % storage['name'], 'description': "SNMP connection to the storage failed. " "SNMP traps from storage will not be received.", 'recovery_advice': "1. The network connection is abnormal. " "2. SNMP authentication parameters " "are invalid.", 'occur_time': utils.utcnow_ms(), } validator._dispatch_snmp_validation_alert( context, storage, constants.Category.FAULT) base_exporter.AlertExporterManager(). \ dispatch.assert_called_once_with(context, alert)
def parse_alert(alert): try: alert_info = alert.get(constant.OID_TRAP_DATA) alert_array = alert_info.split(':') if len(alert_array) > 1: description = alert_array[1] alert = alert_array[0].split() if len(alert) > 1: alert_id = alert[0] severity = constant.SEVERITY_MAP.get(alert[1]) if severity == constant.SEVERITY_MAP.get('Information'): return alert_model = { 'alert_id': alert_id, 'alert_name': alert_id, 'severity': severity, 'category': constants.Category.FAULT, 'type': constants.EventType.EQUIPMENT_ALARM, 'occur_time': utils.utcnow_ms(), 'description': description, 'match_key': hashlib.md5((alert_id + severity + description).encode()).hexdigest(), 'resource_type': constants.DEFAULT_RESOURCE_TYPE, 'location': '' } return alert_model except exception.DelfinException as e: err_msg = "Failed to parse alert from " \ "hitachi nas: %s" % (six.text_type(e.msg)) LOG.error(err_msg) raise e except Exception as err: err_msg = "Failed to parse alert from " \ "hitachi nas: %s" % (six.text_type(err)) LOG.error(err_msg) raise exception.InvalidResults(err_msg)
def parse_alert(alert): try: alert_model = dict() alert_model['alert_id'] = AlertHandler.check_event_code( alert.get(consts.OID_MESSAGECODE)) alert_model['alert_name'] = alert.get(consts.OID_DETAILS) alert_model['severity'] = consts.TRAP_LEVEL_MAP.get( alert.get(consts.OID_SEVERITY), constants.Severity.INFORMATIONAL) alert_model['category'] = constants.Category.FAULT alert_model['type'] = constants.EventType.EQUIPMENT_ALARM alert_model['occur_time'] = utils.utcnow_ms() alert_model['description'] = alert.get(consts.OID_DETAILS) alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE alert_model['match_key'] = hashlib.md5( alert.get(consts.OID_DETAILS, '').encode()).hexdigest() return alert_model except Exception as e: LOG.error(e) msg = (_("Failed to build alert model as some attributes missing " "in alert message.")) raise exception.InvalidResults(msg)
def _dispatch_snmp_validation_alert(self, ctxt, storage, category): alert = { 'storage_id': storage['id'], 'storage_name': storage['name'], 'vendor': storage['vendor'], 'model': storage['model'], 'serial_number': storage['serial_number'], 'alert_id': constants.SNMP_CONNECTION_FAILED_ALERT_ID, 'sequence_number': 0, 'alert_name': 'SNMP connect failed', 'category': category, 'severity': constants.Severity.MAJOR, 'type': constants.EventType.COMMUNICATIONS_ALARM, 'location': 'NetworkEntity=%s' % storage['name'], 'description': "SNMP connection to the storage failed. " "SNMP traps from storage will not be received.", 'recovery_advice': "1. The network connection is abnormal. " "2. SNMP authentication parameters " "are invalid.", 'occur_time': utils.utcnow_ms(), } self.exporter.dispatch(ctxt, alert)
def parse_alert(alert): try: alert_info = alert.get(NetAppHandler.OID_TRAP_DATA) node_name = alert.get(NetAppHandler.NODE_NAME) alert_info = alert_info.replace("]", '') alert_array = alert_info.split("[") alert_model = {} alert_map = {} if len(alert_array) > 1: category = constants.Category.RECOVERY \ if 'created' in alert_array[0] \ else constants.Category.RECOVERY alert_values = alert_array[1].split(",") for alert_value in alert_values: array = alert_value.split("=") if len(array) > 1: key = array[0].replace(' ', '') value = array[1].replace(' ', '').replace('.', '') alert_map[key] = value if alert_map: alert_map_info = \ alert_template.ALERT_TEMPLATE.get( alert_map.get('AlertId')) severity = description = location = '' if alert_map_info: severity = constant.ALERT_SEVERITY[ alert_map_info['severityofAlert']] location = \ alert_map_info['probableCause'] +\ ':' + alert_map_info['PossibleEffect'] description = alert_map_info['description'] alert_model = { 'alert_id': alert_map.get('AlertId'), 'alert_name': alert_map.get('AlertId'), 'severity': severity, 'category': category, 'type': constants.EventType.EQUIPMENT_ALARM, 'occur_time': utils.utcnow_ms(), 'description': description, 'match_key': hashlib.md5((alert_map.get('AlertId') + node_name + alert_map['AlertingResource'] ).encode()).hexdigest(), 'resource_type': constants.DEFAULT_RESOURCE_TYPE, 'location': location } return alert_model except Exception as err: err_msg = "Failed to parse alert from " \ "netapp cmode: %s" % (six.text_type(err)) LOG.error(err_msg) raise exception.InvalidResults(err_msg)