def parse_queried_alerts(self, alert_model_list, alert_list, query_para): alerts = alert_list.get('data', {}).get('events') if alerts: for alert in alerts: try: occur_time = int(time.mktime(time.strptime( alert.get('time'), self.TIME_PATTERN))) * AlertHandler.SECONDS_TO_MS if not alert_util.is_alert_in_time_range( query_para, occur_time): continue alert_model = {} alert_model['alert_id'] = alert.get('type') alert_model['alert_name'] = alert.get('description') alert_model['severity'] = self.ALERT_LEVEL_MAP.get( alert.get('severity'), constants.Severity.INFORMATIONAL) alert_model['description'] = alert.get('description') alert_model['category'] = constants.Category.FAULT alert_model['type'] = constants.EventType.EQUIPMENT_ALARM alert_model['sequence_number'] = alert.get('id') alert_model['occur_time'] = occur_time alert_model['resource_type'] = \ constants.DEFAULT_RESOURCE_TYPE alert_model_list.append(alert_model) except Exception as e: LOG.error(e) err_msg = "Failed to build alert model as some" \ " attributes missing in queried alerts: %s"\ % (six.text_type(e)) raise exception.InvalidResults(err_msg)
def get_alerts(self, query_para, array, version): """Get all alerts with given version and arrayid :param query_para: Contains optional begin and end time :param array: the array serial number :param version: the unisphere version :returns: alert_list -- dict or None """ target_uri = '/%s/system/symmetrix/%s/alert?acknowledged=false' \ % (version, array) # First get list of all alert ids alert_id_list = self.get_alert_request(target_uri) if not alert_id_list: # No current alert ids found return [] # For each alert id, get details of alert # Above list is prefixed with 'alertId' alert_id_list = alert_id_list['alertId'] alert_list = [] for alert_id in alert_id_list: target_uri = '/%s/system/symmetrix/%s/alert/%s' \ % (version, array, alert_id) alert = self.get_alert_request(target_uri) if alert is not None and alert_util.is_alert_in_time_range( query_para, alert['created_date_milliseconds']): alert_list.append(alert) return alert_list
def parse_queried_alerts(alerts, alert_list, query_para=None): if not alerts: return for alert in alerts: occur_time = int(time.mktime(time.strptime( alert.get('occurenceTime'), HitachiVspDriver.TIME_PATTERN))) * \ HitachiVspDriver.SECONDS_TO_MS if not alert_util.is_alert_in_time_range(query_para, occur_time): continue a = { 'location': alert.get('location'), 'alert_id': alert.get('alertId'), 'sequence_number': alert.get('alertIndex'), 'description': alert.get('errorDetail'), 'alert_name': alert.get('errorSection'), 'resource_type': constants.DEFAULT_RESOURCE_TYPE, 'occur_time': occur_time, 'category': constants.Category.FAULT, 'type': constants.EventType.EQUIPMENT_ALARM, 'severity': HitachiVspDriver.ALERT_LEVEL_MAP.get( alert.get('errorLevel'), constants.Severity.INFORMATIONAL) } alert_list.append(a)
def list_alerts(self, query_para=None): alert_list = [] try: storage_alert = self.get_rest_info(consts.REST_SCALEIO_ALERT) alert_description_map = alert_consts.ALERT_MAP for json_alert in (storage_alert or []): match_key = json_alert.get('id') + json_alert.get('name') occur_time = json_alert.get('startTime') datetime_obj = datetime.datetime.strptime( occur_time, consts.DATETIME_UTC_FORMAT) alert_time = int( time.mktime(datetime_obj.timetuple()) * consts.DEFAULT_ALERTS_TIME_CONVERSION + datetime_obj.microsecond / consts.DEFAULT_ALERTS_TIME_CONVERSION) alert_type_desc = json_alert.get('alertType') alert_type_desc = alert_type_desc.lower().replace('_', ' ') if not alert_util.is_alert_in_time_range( query_para, alert_time): continue alert_severity = json_alert.get('severity') if 'LOW' in alert_severity: alert_severity = constants.Severity.MINOR elif 'MEDIUM' in alert_severity: alert_severity = constants.Severity.CRITICAL elif 'HIGH' in alert_severity: alert_severity = constants.Severity.FATAL alert_type = json_alert.get('alertType') alert_model = { 'alert_id': json_alert.get('id'), 'alert_name': alert_type + json_alert.get('name'), 'severity': alert_severity, 'category': constants.Category.FAULT, 'type': alert_type, 'sequence_number': json_alert.get('uuid'), 'description': alert_description_map.get(json_alert.get('alertType'), alert_type_desc), 'occur_time': alert_time, 'match_key': hashlib.md5(match_key.encode()).hexdigest() } alert_list.append(alert_model) return alert_list except exception.DelfinException as err: err_msg = "Get Storage alerts error: %s" % err.msg LOG.error(err_msg) raise err except Exception as e: LOG.error("Get Storage alerts error: %s", six.text_type(e)) raise exception.InvalidResults(e)
def list_alerts(self, query_para): alert_list = [] try: alert_infos = self.ssh_pool.do_exec('show events error') alert_json = self.handle_xml_to_json(alert_infos, 'events') for alert_map in alert_json: now = time.time() occur_time = int( round(now * consts.SecondsNumber.SECONDS_TO_MS)) time_stamp = alert_map.get('time-stamp-numeric') if time_stamp is not None: occur_time = int(time_stamp) * consts.SecondsNumber\ .SECONDS_TO_MS if not alert_util.is_alert_in_time_range( query_para, occur_time): continue event_code = alert_map.get('event-code') event_id = alert_map.get('event-id') location = alert_map.get('message') resource_type = alert_map.get('event-code') severity = alert_map.get('severity') additional_info = str(alert_map.get('additional-information')) match_key = None if event_code: match_key = event_code if severity: match_key += severity if location: match_key += location description = None if additional_info: description = additional_info if severity == 'Informational' or severity == 'RESOLVED': continue alert_model = { 'alert_id': event_id, 'alert_name': event_code, 'severity': severity, 'category': constants.Category.FAULT, 'type': 'EquipmentAlarm', 'sequence_number': event_id, 'occur_time': occur_time, 'description': description, 'resource_type': resource_type, 'location': location, 'match_key': hashlib.md5(match_key.encode()).hexdigest() } alert_list.append(alert_model) alert_list_data = SSHHandler.get_last_alert_data(alert_list) return alert_list_data except Exception as e: err_msg = "Failed to get storage alert: %s" % (six.text_type(e)) LOG.error(err_msg) raise e
def list_alerts(self, query_para): try: alert_list = [] alert_info = self.exec_ssh_command('lseventlog -monitoring yes ' '-message no') alert_res = alert_info.split('\n') for i in range(1, len(alert_res)): if alert_res[i] is None or alert_res[i] == '': continue alert_str = ' '.join(alert_res[i].split()) strinfo = alert_str.split(' ', 1) detail_command = 'lseventlog %s' % strinfo[0] deltail_info = self.exec_ssh_command(detail_command) alert_map = {} self.handle_detail(deltail_info, alert_map, split=' ') occur_time = int(alert_map.get('last_timestamp_epoch')) * \ self.SECONDS_TO_MS if not alert_util.is_alert_in_time_range( query_para, occur_time): continue alert_name = alert_map.get('event_id_text', '') event_id = alert_map.get('event_id') location = alert_map.get('object_name', '') resource_type = alert_map.get('object_type', '') severity = self.SEVERITY_MAP.get( alert_map.get('notification_type')) if severity == 'Informational' or severity is None: continue alert_model = { 'alert_id': event_id, 'alert_name': alert_name, 'severity': severity, 'category': constants.Category.FAULT, 'type': 'EquipmentAlarm', 'sequence_number': alert_map.get('sequence_number'), 'occur_time': occur_time, 'description': alert_name, 'resource_type': resource_type, 'location': location } alert_list.append(alert_model) return alert_list except exception.DelfinException as e: err_msg = "Failed to get storage alert: %s" % (six.text_type(e)) LOG.error(err_msg) raise e except Exception as err: err_msg = "Failed to get storage alert: %s" % (six.text_type(err)) LOG.error(err_msg) raise exception.InvalidResults(err_msg)
def parse_queried_alerts(self, alert_model_list, alert_dict, query_para): alerts = alert_dict.get('entries') for alert in alerts: try: content = alert.get('content', {}) if content.get('state') == AlertHandler.STATE_SOLVED: continue occur_time = int(time.mktime(time.strptime( content.get('timestamp'), self.TIME_PATTERN))) hour_offset = (time.mktime(time.localtime()) - time.mktime( time.gmtime())) / AlertHandler.SECONDS_PER_HOUR occur_time = occur_time + (int(hour_offset) * AlertHandler.SECONDS_PER_HOUR) if not alert_util.is_alert_in_time_range( query_para, int(occur_time * AlertHandler.SECONDS_TO_MS)): continue alert_model = {} location = '' resource_type = constants.DEFAULT_RESOURCE_TYPE if content.get('component'): location = content.get('component').get('id') alert_model['alert_id'] = content.get('messageId') alert_model['alert_name'] = content.get('message') alert_model['severity'] = self.ALERT_LEVEL_MAP.get( content.get('severity'), constants.Severity.INFORMATIONAL) alert_model['category'] = constants.Category.FAULT alert_model['type'] = constants.EventType.EQUIPMENT_ALARM alert_model['sequence_number'] = content.get('id') alert_model['occur_time'] = int(occur_time * AlertHandler.SECONDS_TO_MS) alert_model['description'] = content.get('description') alert_model['resource_type'] = resource_type alert_model['location'] = location alert_model['match_key'] = hashlib.md5( content.get('message').encode()).hexdigest() if alert_model['severity'] == 'Informational': continue alert_model_list.append(alert_model) except Exception as e: LOG.error(e) err_msg = "Failed to build alert model as some attributes " \ "missing in queried alerts: %s" % (six.text_type(e)) raise exception.InvalidResults(err_msg)
def parse_queried_alerts(self, alert_list, query_para): """Parses list alert data and fill the alert model.""" # List contains all the current alarms of given storage id alert_model_list = [] for alert in alert_list: try: occur_time = alert['startTime'] # skip if alert not in input time range if not alert_util.is_alert_in_time_range( query_para, occur_time): continue alert_model = dict() alert_model['alert_id'] = alert['eventID'] alert_model['alert_name'] = alert['name'] alert_model['severity'] = self.QUERY_ALERTS_SEVERITY_MAP.get( alert['level'], constants.Severity.NOT_SPECIFIED) alert_model['category'] = self.QUERY_ALERTS_CATEGORY_MAP.get( alert['eventType'], constants.Category.NOT_SPECIFIED) alert_model['type'] = constants.EventType.NOT_SPECIFIED alert_model['sequence_number'] = alert['sequence'] alert_model['occur_time'] = int(occur_time * 1000) alert_model['description'] = alert['description'] alert_model['recovery_advice'] = alert['suggestion'] alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE alert_model['location'] = alert['location'] alert_model_list.append(alert_model) except Exception as e: LOG.error(e) msg = (_("Failed to build alert model as some attributes" " missing in queried alerts.")) raise exception.InvalidResults(msg) return alert_model_list