def buildPayload(self, signal, notification, data):
        skipfails = notification.content.get('skipfails', False)
        event = EventSummaryProxy(signal.event)

        hbSource = processTALES(notification.content.get('hbSource'),
                                skipfails, data)
        hbEventClass = processTALES(notification.content.get('hbEventClass'),
                                    skipfails, data)
        hbDescription = processTALES(notification.content.get('hbDescription'),
                                     skipfails, data)
        hbFullDescription = processTALES(
            notification.content.get('hbFullDescription'), skipfails, data)

        severity = EventManagerBase.severities.get(
            event.severity, 'Unknown (%s)' % event.severity)
        clear = signal.clear

        payload = {
            "source": hbSource,
            "event_class": hbEventClass,
            "severity": 'Clear' if clear else severity,
            "summary": hbDescription,
            "details": hbFullDescription,
        }

        return payload
Esempio n. 2
0
def _signalToContextDict(signal, zopeurl, notification=None, guidManager=None):
    summary = signal.event
    # build basic event context wrapper for notifications
    if signal.clear:
        # aged and closed events have clear == True, but they don't have an associated clear event
        #   spoof a clear event in those cases, so the notification messages contain useful info
        if summary.status == zep_pb2.STATUS_AGED:
            occur = signal.clear_event.occurrence.add()
            occur.summary = "Event aging task aged out the event."
            summary.cleared_by_event_uuid = "Event aging task"
        elif summary.status == zep_pb2.STATUS_CLOSED:
            occur = signal.clear_event.occurrence.add()

            # once an event is in a closed state, the ownerid (current_user_name) is removed
            # determine who closed the event by extracting the most recent user_name in the event's audit_log
            last_audit_entry = max(signal.event.audit_log,
                                   key=lambda x: x.timestamp)
            summary.current_user_name = last_audit_entry.user_name

            occur.summary = "User '" + summary.current_user_name + "' closed the event in the Zenoss event console."
            summary.cleared_by_event_uuid = "User action"
        data = NotificationEventContextWrapper(summary, signal.clear_event)
    else:
        data = NotificationEventContextWrapper(summary)

    # add urls to event context
    data['urls']['eventUrl'] = getEventUrl(zopeurl, summary.uuid)
    data['urls']['ackUrl'] = getAckUrl(zopeurl, summary.uuid)
    data['urls']['closeUrl'] = getCloseUrl(zopeurl, summary.uuid)
    proxy = EventSummaryProxy(summary)
    data['urls']['deviceUrl'] = _getBaseDeviceUrl(zopeurl, proxy.DeviceClass,
                                                  proxy.device)
    data['urls']['eventsUrl'] = getEventsUrl(zopeurl, proxy.DeviceClass,
                                             proxy.device)
    data['urls']['reopenUrl'] = getReopenUrl(zopeurl, summary.uuid)
    data['urls']['baseUrl'] = zopeurl
    # now process all custom processors that might be registered to enhance
    # the event context
    for key, processor in getUtilitiesFor(IProcessSignal):
        data[key] = processor.process(signal)

    # Process INotificationContextProvider
    for key, contextProvider in getUtilitiesFor(INotificationContextProvider):
        contextProvider.updateContext(signal, data)

    # Add trigger and notification info
    if notification:
        data['notification']['name'] = notification.titleOrId()
    if guidManager:
        trigger = guidManager.getObject(signal.trigger_uuid)
        if trigger:
            data['trigger']['name'] = trigger.titleOrId()

    return data