def get_alert(cls, service, alert): if service.state in ["active", "failed"]: description = alert.description.format( service.name, service.state, service.threshold_waiting_time) else: description = alert.description.format(service.name, service.state, service.nonactive_threshold) return { "sensor_request_type": { "service_status_alert": { "host_id": OSUtils.get_fqdn(), "severity": SeverityReader().map_severity(alert.alert_type), "alert_id": MonUtils.get_alert_id(str(int(time.time()))), "alert_type": alert.alert_type, "info": { "resource_type": cls.RESOURCE_TYPE, "resource_id": service.name, "event_time": str(int(time.time())), "description": description, "impact": alert.impact.format(service.name), "recommendation": alert.recommendation, }, "specific_info": { "service_name": service.name, "previous_state": service.previous_state, "state": service.state, "previous_substate": service.previous_substate, "substate": service.substate, "previous_pid": service.previous_pid, "pid": service.pid, } } } }
def __init__(self, info, username="******", signature="N/A", expires=-1): """Initialize thread monitoring message.""" super(ThreadMonitorMsg, self).__init__() self._epoch_time = str(int(time.time())) self._json = { "username": username, "description": self.DESCRIPTION, "title": self.TITLE, "expires": expires, "signature": signature, "time": self._epoch_time, "message": { "sspl_ll_msg_header": { "schema_version": self.SCHEMA_VERSION, "sspl_version": self.SSPL_VERSION, "msg_version": self.MESSAGE_VERSION, }, "sensor_response_type": { "info": { "event_time": self._epoch_time, "resource_id": info.get("module_name"), "resource_type": self.RESOURCE_TYPE, "description": info.get("description"), "impact": info.get("impact"), "recommendation": info.get("recommendation") }, "alert_type": info.get("alert_type"), "severity": info.get("severity"), "specific_info": info.get("specific_info"), "alert_id": MonUtils.get_alert_id(self._epoch_time), "host_id": socket.getfqdn() } } }
def __init__(self, host_id, local_time, interfaces, resource_id, resource_type, alert_type, severity, event, username="******", signature="N/A", in_time="N/A", expires=-1): super(IFdataMsg, self).__init__() self._username = username self._signature = signature self._time = in_time self._expires = expires self._host_id = host_id self._local_time = local_time self._interfaces = interfaces self._resource_id = resource_id self._resource_type = resource_type self.alert_type = alert_type self._severity = severity epoch_time = str(int(time.time())) alert_id = MonUtils.get_alert_id(epoch_time) self._json = { "username": self._username, "expires": self._expires, "description": self.DESCRIPTION, "title": self.TITLE, "signature": self._signature, "time": self._time, "message": { "sspl_ll_msg_header": { "msg_version": self.MESSAGE_VERSION, "schema_version": self.SCHEMA_VERSION, "sspl_version": self.SSPL_VERSION, }, "sensor_response_type": { "info": { "event_time": epoch_time, "resource_id": self._resource_id, "resource_type": self._resource_type, "description": event }, "specific_info": { "localtime": self._local_time, "interfaces": self._interfaces }, "host_id": self._host_id, "alert_type": self.alert_type, "severity": self._severity, "alert_id": alert_id } } }
def _build_generic_info(self, response): """ Build json with generic information :param response: :return: """ epoch_time = str(int(time.time())) response['instance_id'] = self._resource_id response['alert_type'] = AlertTypes.GET.value response['severity'] = SeverityTypes.INFORMATIONAL.value response['alert_id'] = MonUtils.get_alert_id(epoch_time) response['info'] = { "resource_type": f"enclosure:{self._enclosure_type.lower()}:{self._enclosure_resource_type.lower()}", "resource_id": self._resource_id, "event_time": epoch_time, } # fetch host details response["host_id"] = socket.getfqdn()
def make_response(self, component_details, component, component_type, resource_id, ctrl_action = None): resource_type = "enclosure:{}:{}".format(component, component_type) epoch_time = str(int(time.time())) alert_id = MonUtils.get_alert_id(epoch_time) fru = self.rssencl.is_storage_fru(component_type) if ctrl_action in self.CTRL_ACTION_LST: resource_type = component_details['resource_type'] del component_details['resource_type'] self.ALERT_TYPE = component_details['alert_type'] del component_details['alert_type'] self.SEVERITY = component_details['severity'] del component_details['severity'] if self.SEVERITY == "warning": del component_details['description'] elif component == "hw": if resource_id == self.RESOURCE_ALL: for comp in component_details: comp['resource_id'] = self.fru_response_manipulators[ component_type](comp if component_type!=self.FRU_DISK else [comp]) else: resource_id = self.fru_response_manipulators[component_type](component_details) response = { "alert_type": self.ALERT_TYPE, "severity": self.SEVERITY, "host_id": socket.getfqdn(), "alert_id": alert_id, "info": { "resource_type": resource_type, "fru": fru, "resource_id": resource_id, "event_time": epoch_time }, "specific_info": component_details } return response
def __init__(self, host_id, local_time, free_space, total_space, disk_used_percentage, units, alert_type, event, username = "******", signature = "N/A", in_time = "N/A", expires = -1 ): super(DiskSpaceAlertMsg, self).__init__() self._username = username self._signature = signature self._time = in_time self._expires = expires self._host_id = host_id # No need for local time self._free_space = free_space self._total_space = total_space self._disk_used_percentage = disk_used_percentage self._units = units self.alert_type = alert_type self.event = event if self.alert_type == "fault_resolved": self.SEVERITY = "informational" epoch_time = str(calendar.timegm(time.gmtime())) alert_id = MonUtils.get_alert_id(epoch_time) self._json = { "username" : self._username, "description" : self.DESCRIPTION, "title" : self.TITLE, "expires" : self._expires, "signature" : self._signature, "time" : epoch_time, "message" : { "sspl_ll_msg_header": { "msg_version" : self.MESSAGE_VERSION, "schema_version" : self.SCHEMA_VERSION, "sspl_version" : self.SSPL_VERSION, }, "sensor_response_type": { "alert_type": self.alert_type, "severity": self.SEVERITY, "alert_id": alert_id, "host_id": self._host_id, "info": { "resource_type": self.RESOURCE_TYPE, "resource_id": self.RESOURCE_ID, "event_time": epoch_time, "description": self.event }, "specific_info": { "freeSpace" : { "value" : self._free_space, "units" : self._units }, "totalSpace" : { "value" : self._total_space, "units" : self._units }, "diskUsedPercentage" : self._disk_used_percentage } } } }
def __init__(self, host_id, local_time, csps, idle_time, interrupt_time, iowait_time, nice_time, softirq_time, steal_time, system_time, user_time, core_data, cpu_usage, alert_type, event, username = "******", signature = "N/A", in_time = "N/A", expires = -1): super(CPUdataMsg, self).__init__() self._username = username self._signature = signature self._time = in_time self._expires = expires self._host_id = host_id self._local_time = local_time self._csps = csps self._idle_time = idle_time self._interrupt_time = interrupt_time self._iowait_time = iowait_time self._nice_time = nice_time self._softirq_time = softirq_time self._steal_time = steal_time self._system_time = system_time self._user_time = user_time self._core_data = core_data self._cpu_usage = cpu_usage self.alert_type = alert_type self.event = event if self.alert_type == "fault_resolved": self.SEVERITY = "informational" epoch_time = str(int(time.time())) alert_id = MonUtils.get_alert_id(epoch_time) self._json = { "username" : self._username, "description" : self.DESCRIPTION, "title" : self.TITLE, "expires" : self._expires, "signature" : self._signature, "time" : epoch_time, "message" : { "sspl_ll_msg_header": { "schema_version" : self.SCHEMA_VERSION, "sspl_version" : self.SSPL_VERSION, "msg_version" : self.MESSAGE_VERSION, }, "sensor_response_type": { "alert_type": self.alert_type, "severity": self.SEVERITY, "alert_id": alert_id, "host_id": self._host_id, "info": { "resource_type": self.RESOURCE_TYPE, "resource_id": self.RESOURCE_ID, "event_time": epoch_time, "description": self.event }, "specific_info": { "localtime" : self._local_time, "csps" : self._csps, "idleTime" : self._idle_time, "interruptTime" : self._interrupt_time, "iowaitTime" : self._iowait_time, "niceTime" : self._nice_time, "softirqTime" : self._softirq_time, "stealTime" : self._steal_time, "systemTime" : self._system_time, "userTime" : self._user_time, "coreData" : self._core_data, "cpu_usage" : self._cpu_usage } } } }
def __init__(self, host_id, local_time, boot_time, up_time, uname, units, total_memory, logged_in_users, process_count, running_process_count, alert_type, event, username = "******", signature = "N/A", in_time = "N/A", expires = -1): super(HostUpdateMsg, self).__init__() self._username = username self._signature = signature self._time = in_time self._expires = expires self._host_id = host_id self._local_time = local_time self._boot_time = boot_time self._up_time = up_time self._uname = uname self._total_memory = total_memory self._units = units self._logged_in_users = logged_in_users self._process_count = process_count self._running_process_count = running_process_count self.alert_type = alert_type self.event = event if self.alert_type == "fault_resolved": self.SEVERITY = "informational" epoch_time = str(int(time.time())) alert_id = MonUtils.get_alert_id(epoch_time) self._json = { "username" : self._username, "description" : self.DESCRIPTION, "title" : self.TITLE, "expires" : self._expires, "signature" : self._signature, "time" : epoch_time, "message" : { "sspl_ll_msg_header": { "schema_version" : self.SCHEMA_VERSION, "sspl_version" : self.SSPL_VERSION, "msg_version" : self.MESSAGE_VERSION, }, "sensor_response_type": { "alert_type": self.alert_type, "severity": self.SEVERITY, "alert_id": alert_id, "host_id": self._host_id, "info": { "resource_type": self.RESOURCE_TYPE, "resource_id": self.RESOURCE_ID, "event_time": epoch_time, "description": self.event }, "specific_info": { "localtime" : self._local_time, "bootTime" : self._boot_time, "upTime" : self._up_time, "uname" : self._uname, "totalMemory" : self._total_memory, "loggedInUsers" : self._logged_in_users, "processCount" : self._process_count, "runningProcessCount" : self._running_process_count } } } }