def testFillTriggerProtoBuf(self): triggerPb = TriggerPb() spec = self.z.cfg.classes.get('BasicComponent') ob = self.z.obs[1] self.get_guid(ob) impact_fact = BaseTriggers(ob) for trigger in impact_fact.get_triggers(): t_spec = self.find_trigger_spec(trigger, spec) args = t_spec.get_trigger() msg = args[0] self.factory._fillTriggerProto(triggerPb, trigger) self.assertEquals(ob._guid, triggerPb.nodeId) self.assertEquals(msg, triggerPb.triggerId) self.assertEquals(t_spec.trigger, triggerPb.triggerType) self.assertEquals('global', triggerPb.contextId) pbe = ProtobufEnum(State, enum='StateType') self.assertEquals(pbe.AVAILABILITY, triggerPb.policyType) self.assertEquals('AVAILABILITY', pbe.getName(triggerPb.policyType)) self.assertEquals(3, len(triggerPb.properties)) self.assertEquals("threshold", triggerPb.properties[0].name) self.assertEquals(str(t_spec.threshold), triggerPb.properties[0].value) self.assertEquals("dependentState", triggerPb.properties[1].name) self.assertEquals(t_spec.dependent_state, triggerPb.properties[1].value) self.assertEquals("state", triggerPb.properties[2].name) self.assertEquals(t_spec.state, triggerPb.properties[2].value)
from Products.ZenMessaging.ChangeEvents.events import ( MessagePrePublishingEvent, MessagePostPublishingEvent) from Products.ZenMessaging.queuemessaging.interfaces import ( IModelProtobufSerializer, IQueuePublisher, IProtobufSerializer, IEventPublisher) from contextlib import closing from zenoss.protocols.protobufutil import ProtobufEnum from zenoss.protocols.protobufs import modelevents_pb2 from zenoss.protocols.protobufs.zep_pb2 import Event from zenoss.protocols.interfaces import IQueueSchema, IAMQPConnectionInfo import logging log = logging.getLogger('zen.queuepublisher') MODEL_TYPE = ProtobufEnum(modelevents_pb2.ModelEvent, 'model_type') class ModelChangePublisher(object): """ Keeps track of all the model changes so far in this transaction. Do not instantiate this class directly, use "getModelChangePublisher" to receive the singleton """ def __init__(self): self._events = [] self._msgs = [] self._addedGuids = set() self._modifiedGuids = set() self._removedGuids = set() self._publishable = []
# ############################################################################## import urllib from zope.interface import implements from zenoss.protocols.protobufs.zep_pb2 import EventSummary from zenoss.protocols.protobufutil import ProtobufEnum from zenoss.protocols.services.zep import EventStatus from Products.ZenEvents.events2.proxy import EventProxy from Products.Zuul.catalog.interfaces import IModelCatalogTool from Products.ZenUtils.guid.interfaces import IGUIDManager from Products.Zuul.interfaces import IMarshallable from lxml.html.clean import clean_html from lxml.etree import ParserError _status_name = ProtobufEnum(EventSummary, 'status').getPrettyName def _mergeAuditLogToNotes(evtsumm): if 'audit_log' in evtsumm: mergedNotes = evtsumm.get('notes', []) for auditNote in evtsumm['audit_log']: mergedNotes.append({ 'created_time': auditNote['timestamp'], 'user_uuid': auditNote.get('user_uuid', ''), 'user_name': auditNote.get('user_name', ''), 'message': 'state changed to {}'.format(
# This content is made available according to terms specified in # License.zenoss under the directory where your Zenoss product is installed. # ############################################################################## import logging from zenoss.protocols.services import ProtobufRestServiceClient, ServiceConnectionError from zenoss.protocols.jsonformat import from_dict from zenoss.protocols.protobufs.zep_pb2 import EventSummary, Event, EventNote, EventSummaryUpdate, EventSort, EventSummaryUpdateRequest, EventSummaryRequest, EventQuery, ZepConfig from zenoss.protocols.protobufs.zep_pb2 import STATUS_NEW, STATUS_ACKNOWLEDGED, STATUS_CLOSED from zenoss.protocols.protobufutil import ProtobufEnum, listify from datetime import timedelta log = logging.getLogger('zepclient') EventSeverity = ProtobufEnum(Event, 'severity') EventStatus = ProtobufEnum(EventSummary, 'status') EventSortField = ProtobufEnum(EventSort, 'field') EventSortDirection = ProtobufEnum(EventSort, 'direction') ZERO = timedelta(0) HOUR = timedelta(hours=1) class ZepServiceException(Exception): pass class ZepConnectionError(ServiceConnectionError): pass