def _send_manual_notification(self, sessionKey, user, post_data): logger.info("_send_manual_notification started", ) logger.debug("user: {}".format(user)) logger.debug("post_data: {}".format(post_data)) notification = {} notifications = [] query = {} query['incident_id'] = post_data.get('incident_id') logger.debug("Filter: {}".format(json.dumps(query))) uri = '/servicesNS/nobody/alert_manager/storage/collections/data/incidents?query={}'.format( urllib.parse.quote(json.dumps(query))) serverResponse, incident = rest.simpleRequest(uri, sessionKey=sessionKey) logger.debug("Settings for incident: {}".format(incident)) incidents = json.loads(incident) notification['alert'] = incidents[0].get("alert") notification['incident'] = post_data.get('incident_id') notification['event'] = post_data.get('event') notification_message = post_data.get('notification_message') recipients = post_data.get('recipients') recipients_overwrite = post_data.get('recipients_overwrite') logger.debug("recipients_overwrite: {}".format(recipients_overwrite)) notifications.append(notification.copy()) ic = IncidentContext(sessionKey, notification['incident']) context = ic.getContext() context.update({'notification_message': notification_message}) context.update({'recipients': recipients}) context.update({'recipients_overwrite': recipients_overwrite}) logger.debug("Notification context: {}".format(json.dumps(context))) eh = EventHandler(sessionKey=sessionKey) eh.handleEvent(alert=notification['alert'], event=notification['event'], incident=incidents[0], context=ic.getContext()) logger.info("_send_manual_notification stopped") return self.response('Manual notification executed', http.client.OK)
def eventHandlingTest(): print "event handler test set" print "init test set" event_handler = EventHandler() # init modules dbus_module = DbusModule(event_handler,"dbus","org.mymeego.Ui","/org/mymeego/Ui","org.mymeego.Ui") upnp_module = UpnpModule(event_handler,"upnp") worker_module = WorkerModule(event_handler,"worker") #init commands event_handler.addCommand(Command("ReturnUiData",dbus_module)) event_handler.addCommand(Command("DataRequest",worker_module)) # this is the default command from UI event_handler.addCommand(Command("GetDeviceList",upnp_module)) event_handler.addCommand(Command("GetFileList",upnp_module)) event_handler.addCommand(Command("TransferFiles",upnp_module)) print "start tests" event_handler.handleEvent(Event("DataRequest",1,"GetDeviceList")) event_handler.handleEvent(Event("DataRequest",1,"GetFileList")) event_handler.handleEvent(Event("DataRequest",1,"TransferFiles")) event_handler.handleEvent(Event("ReturnUiData",1,"TransferFiles"))
# Fire incident_created or incident_suppressed event # only if it was not deemed a duplicate if is_subsequent_resolved: log.info( "Skipping firing of incident_created event for incident={} because it is a duplicate." .format(incident_id)) else: if incident_suppressed == False: log.info( "Firing incident_created event for incident={}".format( incident_id)) eh.handleEvent( alert=search_name, event="incident_created", incident={"owner": settings.get('default_owner')}, context=ic.getContext()) else: log.info( "Firing incident_suppressed event for incident={}".format( incident_id)) eh.handleEvent( alert=search_name, event="incident_suppressed", incident={"owner": settings.get('default_owner')}, context=ic.getContext()) # If the incident was not resolved already, auto resolved is enabled, and priority is informational - resolve it. auto_info_resolved = False if is_subsequent_resolved == False:
log.info("Incident {} ({}) should be resolved. alert_time={} ttl={} now={}" .format(incident['incident_id'], incident['_key'], incident['alert_time'], incident['ttl'], time.time())) old_status = incident['status'] incident['status'] = 'auto_ttl_resolved' uri = '/servicesNS/nobody/alert_manager/storage/collections/data/incidents/{}'.format(incident['_key']) incidentStr = json.dumps(incident) serverResponse, serverContent = rest.simpleRequest(uri, sessionKey=sessionKey, jsonargs=incidentStr) now = time.strftime("%Y-%m-%dT%H:%M:%S+0000", time.gmtime()) event_id = hashlib.md5(incident['incident_id'].encode('utf-8') + now.encode('utf-8')).hexdigest() log.debug("event_id={} now={}".format(event_id, now)) event = 'time={} severity=INFO origin="alert_manager_scheduler" event_id="{}" user="******" action="auto_ttl_resolve" previous_status="{}" status="auto_ttl_resolved" incident_id="{}"'.format(now, event_id, old_status, incident['incident_id']) log.debug("Event will be: {}".format(event)) input.submit(event, hostname = socket.gethostname(), sourcetype = 'incident_change', source = 'alert_manager_scheduler.py', index = config['index']) ic = IncidentContext(sessionKey, incident["incident_id"]) eh.handleEvent(alert=alert["name"], event="incident_auto_ttl_resolved", incident={"owner": incident["owner"]}, context=ic.getContext()) else: log.info("Incident {} has not ttl reached yet.".format(incident['incident_id'])) else: log.info("No incidents of alert {} to check for reached ttl.".format(alert['name'])) log.debug('Alert "{}" is not configured for auto_ttl_resolve, skipping...'.format(alert['name'])) # # Look for auto_suppress_resolve incidents # query = {} query['auto_suppress_resolve'] = True log.debug("Filter: {}".format(json.dumps(query))) uri = '/servicesNS/nobody/alert_manager/storage/collections/data/incident_settings?query={}'.format(urllib.parse.quote(json.dumps(query))) serverResponse, serverContent = rest.simpleRequest(uri, sessionKey=sessionKey) try: