Exemplo n.º 1
0
 def getEventSummariesGenerator(self, filter=None, exclude=None, sort=None, archive=False, timeout=None):
     if isinstance(exclude, dict):
         exclude = from_dict(EventFilter, exclude)
     if isinstance(filter, dict):
         filter = from_dict(EventFilter, filter)
     if sort is not None:
         sort = tuple(self._getEventSort(s) for s in safeTuple(sort))
     searchid = self.client.createSavedSearch(event_filter=filter, exclusion_filter=exclude, sort=sort,
                                              archive=archive, timeout=timeout)
     log.debug("created saved search %s", searchid)
     eventSearchFn = partial(self.client.savedSearch, searchid, archive=archive)
     offset = 0
     limit = 1000
     try:
         while offset is not None:
             result = self._getEventSummaries(eventSearchFn, offset, limit)
             for evt in result['events']:
                 yield evt
             offset = result['next_offset']
     finally:
         try:
             log.debug("closing saved search %s", searchid)
             self.client.deleteSavedSearch(searchid, archive=archive)
         except Exception as e:
             log.debug("error closing saved search %s (%s) - %s", searchid, type(e), e)
Exemplo n.º 2
0
 def updateEventSummaries(self, update, eventFilter=None, exclusionFilter=None, limit=None, timeout=None):
     update_pb = from_dict(EventSummaryUpdate, update)
     event_filter_pb = None if (eventFilter is None) else from_dict(EventFilter, eventFilter)
     exclusion_filter_pb = None if (exclusionFilter is None) else from_dict(EventFilter, exclusionFilter)
     status, response = self.client.updateEventSummaries(update_pb, event_filter_pb, exclusion_filter_pb,
                                                         limit=limit, timeout=timeout)
     return status, to_dict(response)
Exemplo n.º 3
0
    def reopenEventSummaries(self, eventFilter=None, exclusionFilter=None, limit=None, userName=None, timeout=None):
        if eventFilter:
            eventFilter = from_dict(EventFilter, eventFilter)
        if exclusionFilter:
            exclusionFilter = from_dict(EventFilter, exclusionFilter)

        if not userName:
            userUuid, userName = self._findUserInfo()
        else:
            userUuid = self._getUserUuid(userName)
        status, response = self.client.reopenEventSummaries(
            userUuid, userName, eventFilter, exclusionFilter, limit, timeout=timeout)
        return status, to_dict(response)
Exemplo n.º 4
0
    def load(self, configData):
        """
        configData is a JSON dict that contains a key of the same
        name as specified in this class (ie self.key).

        The value from this key is expected to be an arrary of dictionaries
        as used by the ZEP system. See the documentation in the 
        ZenModel/ZenPackTemplate/CONTENT/zep/zep.json.example file.
        """
        if configData:
            self.zep = getFacade('zep')
            items = configData.get(EventDetailItemHandler.key)
            if items is None:
                log.warn("Expected key '%s' for details is missing from the zep.json file",
                          self.key)
                return
            detailItemSet = from_dict(EventDetailItemSet, dict(
                # An empty array in details casues ZEP to puke
                details = items
            ))
            try:
                self.zep.addIndexedDetails(detailItemSet)
            except Exception as ex:
                log.error("ZEP %s error adding detailItemSet data: %s\nconfigData= %s",
                              getattr(ex, 'status', 'unknown'), detailItemSet, configData)
                log.error("See the ZEP logs for more information.")
Exemplo n.º 5
0
    def updateTrigger(self, **data):
        user = getSecurityManager().getUser()

        triggerObj = self._guidManager.getObject(data['uuid'])

        log.debug('Trying to update trigger: %s' % triggerObj.id)

        if self.triggerPermissions.userCanManageTrigger(user, triggerObj):
            if 'globalRead' in data:
                triggerObj.globalRead = data.get('globalRead', False)
                log.debug('setting globalRead %s' % triggerObj.globalRead)

            if 'globalWrite' in data:
                triggerObj.globalWrite = data.get('globalWrite', False)
                log.debug('setting globalWrite %s' % triggerObj.globalWrite)

            if 'globalManage' in data:
                triggerObj.globalManage = data.get('globalManage', False)
                log.debug('setting globalManage %s' % triggerObj.globalManage)

            triggerObj.users = data.get('users', [])
            self.triggerPermissions.clearPermissions(triggerObj)
            self.triggerPermissions.updatePermissions(self._guidManager, triggerObj)

        if self.triggerPermissions.userCanUpdateTrigger(user, triggerObj):
            if "name" in data:
                triggerObj.setTitle(data["name"])
            trigger = from_dict(zep.EventTrigger, data)
            response, content = self.triggers_service.updateTrigger(trigger)
            return content
Exemplo n.º 6
0
    def _processArgs(self, eventFilter, exclusionFilter, userName):
        if eventFilter:
            eventFilter = from_dict(EventFilter, eventFilter)
        if exclusionFilter:
            exclusionFilter = from_dict(EventFilter, exclusionFilter)

        if not userName:
            userUuid, userName = self._findUserInfo()
        else:
            userUuid = self._getUserUuid(userName)

        if eventFilter is None and exclusionFilter is None:
            raise NoFiltersException("Cannot modify event summaries without at least one filter specified.")

        return {'eventFilter': eventFilter, 'exclusionFilter': exclusionFilter,
                'userName': userName, 'userUuid': userUuid}
Exemplo n.º 7
0
def get_alert(alrt_evid, alrt_type, alrt_urls):
	message = None

	try:
		filter_zep = zep.createEventFilter(uuid=alrt_evid)
		for summary in zep.getEventSummariesGenerator(filter=filter_zep):

			sync()

	        		evt = EventSummaryProxy(from_dict(EventSummary, summary))

			if evt.severity == 5:
				severity_string='Critical'
			elif evt.severity == 4:
				severity_string='Error'
			elif evt.severity == 3:
				severity_string='Warning'
			elif evt.severity == 2:
				severity_string='Info'
			elif evt.severity == 1:
				severity_string='Debug'

		  	if alrt_type == 'incident':
				message = """[casc-zenoss] SYSTEMS - {1} {2} <br /> Device: {1} <br /> Component: {3} <br /> Severity: {0} <br /> Time: {4} <br /> Message: <br /> {5} <br /> <a href="{6}">Event Detail</a> <br /> <a href="{7}">Acknowledge</a> <br /> <a href="{8}">Close</a> <br /> <a href="{9}">Device Events</a>""".format(severity_string, evt.device, evt.summary, evt.component, evt.lastTime, evt.message, alrt_urls[0], alrt_urls[1], alrt_urls[2], alrt_urls[3])
			else:
				message = """[casc-zenoss] SYSTEMS - CLEAR: {0} {7} <br /> Event: {1} <br /> Cleared by: {7} <br /> At: {2} <br /> Device: {0} <br /> Component: {3} <br /> Severity: {4} <br /> Message: <br /> {5} <br /> <a href="{6}">Undelete</a>""".format(evt.device, evt.summary, alrt_urls[2], evt.component, severity_string, evt.message, alrt_urls[0], alrt_urls[1])

		if message != None:
			post_alert(alrt_type, severity_string, message)
		else:
			raise Exception("Invalid region name: {0}".format(regions[x]))
Exemplo n.º 8
0
 def setConfigValues(self, values):
     """
     @type  values: Dictionary
     @param values: Key Value pairs of config values
     """
     zepConfigProtobuf = from_dict(ZepConfig, values)
     self.configClient.setConfigValues(zepConfigProtobuf)
Exemplo n.º 9
0
 def upgrade(self, configData):
     if configData:
         self.zep = getFacade('zep')
         items = configData.get(EventDetailItemHandler.key, [])
         for item in items:
             log.info("Upgrading the following to be indexed by ZEP: %s" % item)
             detailItem = from_dict(EventDetailItem, item)
             self.zep.updateIndexedDetailItem(detailItem)
Exemplo n.º 10
0
    def getEventSummaries(self, offset, limit=1000, sort=None, filter=None, exclusion_filter=None):
        client_fn = self.client.getEventSummaries

        if filter is not None and isinstance(filter, dict):
            filter = from_dict(EventFilter, filter)
        if exclusion_filter is not None and isinstance(exclusion_filter, dict):
            exclusion_filter = from_dict(EventFilter, exclusion_filter)
        if sort is not None:
            sort = tuple(self._getEventSort(s) for s in safeTuple(sort))

        result = self._getEventSummaries(source=partial(client_fn,
                                         filter=filter,
                                         exclusion_filter=exclusion_filter,
                                         sort=sort),
                                         offset=offset, limit=limit)

        return result
Exemplo n.º 11
0
    def updateTrigger(self, **data):
        user = getSecurityManager().getUser()

        triggerObj = self._guidManager.getObject(data['uuid'])

        log.debug('Trying to update trigger: %s' % triggerObj.id)

        if self.triggerPermissions.userCanManageTrigger(user, triggerObj):
            if 'globalRead' in data:
                triggerObj.globalRead = data.get('globalRead', False)
                log.debug('setting globalRead %s' % triggerObj.globalRead)

            if 'globalWrite' in data:
                triggerObj.globalWrite = data.get('globalWrite', False)
                log.debug('setting globalWrite %s' % triggerObj.globalWrite)

            if 'globalManage' in data:
                triggerObj.globalManage = data.get('globalManage', False)
                log.debug('setting globalManage %s' % triggerObj.globalManage)

            triggerObj.users = data.get('users', [])
            self.triggerPermissions.clearPermissions(triggerObj)
            self.triggerPermissions.updatePermissions(
                self._guidManager, triggerObj
            )

        if self.triggerPermissions.userCanUpdateTrigger(user, triggerObj):
            if "name" in data:
                triggerObj.setTitle(cgi.escape(data["name"]))
                parent = triggerObj.getPrimaryParent()
                path = triggerObj.absolute_url_path()
                oldId = triggerObj.getId()
                newId = triggerObj.title
                if not isinstance(newId, unicode):
                    newId = Utils.prepId(newId)
                newId = newId.strip()
                if not newId:
                    raise Exception("New trigger id cannot be empty.")
                if newId != oldId:
                    # rename the trigger id since its title changed
                    try:
                        if triggerObj.getDmd().Triggers.findObject(newId):
                            message = 'Trigger %s already exists' % newId
                            # Duplicate trigger found
                            raise Exception(message)
                    except AttributeError as ex:
                        # the newId is not a duplicate
                        pass

                    try:
                        parent.manage_renameObject(oldId, newId)
                        triggerObj.id = newId
                    except CopyError:
                        raise Exception("Trigger rename failed.")

            trigger = from_dict(zep.EventTrigger, data)
            response, content = self.triggers_service.updateTrigger(trigger)
            return content
Exemplo n.º 12
0
 def reopenEventSummaries(self, userUuid, userName=None, event_filter=None, exclusionFilter=None, limit=None,
                          timeout=None):
     update = from_dict(EventSummaryUpdate, dict(
         status = STATUS_NEW,
         current_user_uuid = userUuid,
         current_user_name = userName,
     ))
     return self.updateEventSummaries(update, event_filter=event_filter, exclusion_filter=exclusionFilter,
                                      limit=limit, timeout=timeout)
Exemplo n.º 13
0
 def _getEventSort(self, sortParam):
     eventSort = {}
     if isinstance(sortParam, (list, tuple)):
         field, direction = sortParam
         eventSort['direction'] = self.SORT_DIRECTIONAL_MAP[direction.lower()]
     else:
         field = sortParam
     eventSort.update(getDetailsInfo().getSortMap()[field.lower()])
     return from_dict(EventSort, eventSort)
Exemplo n.º 14
0
    def getEventSummaries(self, offset, limit=1000, sort=None, filter=None, exclusion_filter=None, client_fn=None,
                          use_permissions=False):
        if client_fn is None:
            client_fn = self.client.getEventSummaries
        if filter is not None and isinstance(filter,dict):
            filter = from_dict(EventFilter, filter)
        if exclusion_filter is not None and isinstance(exclusion_filter, dict):
            exclusion_filter = from_dict(EventFilter, exclusion_filter)
        if sort is not None:
            sort = tuple(self._getEventSort(s) for s in safeTuple(sort))

        result = None

        if use_permissions:
            user = getSecurityManager().getUser()
            userSettings = self._dmd.ZenUsers._getOb(user.getId())
            hasGlobalRoles = not userSettings.hasNoGlobalRoles()
            if not hasGlobalRoles:
                adminRoles = userSettings.getAllAdminRoles()
                if adminRoles:
                    # get ids for the objects they have permission to access
                    # and add to filter
                    ids = [IGlobalIdentifier(x.managedObject()).getGUID() for x in adminRoles]
                    if filter is None:
                        filter = EventFilter()
                    tf = filter.tag_filter.add()
                    tf.tag_uuids.extend(ids)
                else:
                    # no permission to see events, return 0
                    result =  {
                        'total' : 0,
                        'events' : [],
                    }

        if not result:
            result = self._getEventSummaries(source=partial(client_fn,
                                                   filter=filter,
                                                   exclusion_filter=exclusion_filter,
                                                   sort=sort
                                                   ),
                                           offset=offset, limit=limit
                                           )
        return result
Exemplo n.º 15
0
    def getEventSummaries(self, offset, limit=1000, sort=None, filter=None, exclusion_filter=None, client_fn=None,
                          use_permissions=False):
        if client_fn is None:
            client_fn = self.client.getEventSummaries
        if filter is not None and isinstance(filter,dict):
            filter = from_dict(EventFilter, filter)
        if exclusion_filter is not None and isinstance(exclusion_filter, dict):
            exclusion_filter['operator'] = 1 # Set operator to OR
            exclusion_filter = from_dict(EventFilter, exclusion_filter)
        if sort is not None:
            sort = tuple(self._getEventSort(s) for s in safeTuple(sort))

        result = None

        if use_permissions:
            user = getSecurityManager().getUser()
            userSettings = self._dmd.ZenUsers._getOb(user.getId())
            hasGlobalRoles = not userSettings.hasNoGlobalRoles()
            if not hasGlobalRoles:
                # get guids for the objects user has permission to access
                # and add to filter
                guids = userSettings.getAllAdminGuids(returnChildrenForRootObj=True)
                if guids:
                    if filter is None:
                        filter = EventFilter()
                    tf = filter.tag_filter.add()
                    tf.tag_uuids.extend(guids)
                else:
                    # no permission to see events, return 0
                    result =  {
                        'total' : 0,
                        'events' : [],
                    }

        if not result:
            result = self._getEventSummaries(source=partial(client_fn,
                                                   filter=filter,
                                                   exclusion_filter=exclusion_filter,
                                                   sort=sort
                                                   ),
                                           offset=offset, limit=limit
                                           )
        return result
Exemplo n.º 16
0
    def addNoteBulkAsync(self, uuids, message, userUuid=None, userName=None):
        """
        Add a note (what used to be called log) to several event summaries.
        """

        note = from_dict(EventNote, dict(
            user_uuid = userUuid,
            user_name = userName,
            message = message
        ))

        return self.client.post('notes_async', body=note, params={'uuid': uuids})
Exemplo n.º 17
0
    def addNote(self, uuid, message, userUuid=None, userName=None):
        """
        Add a note (what used to be called log) to an event summary.
        """

        note = from_dict(EventNote, dict(
            user_uuid = userUuid,
            user_name = userName,
            message = message
        ))

        return self.client.post('%s/notes' % uuid, body=note)
Exemplo n.º 18
0
    def _getEventTagSeverities(self, eventClass=(), severity=(), status=(), tags=()):
        if not severity:
            severity = (SEVERITY_CRITICAL, SEVERITY_ERROR, SEVERITY_WARNING)
        if not status:
            status = (STATUS_NEW, STATUS_ACKNOWLEDGED)
        eventFilter = self.createEventFilter(
            severity=severity,
            status=status,
            event_class=eventClass,
            tags=tags,
            )

        response, content = self.client.getEventTagSeverities(from_dict(EventFilter, eventFilter))
        return content.severities
Exemplo n.º 19
0
 def updateNotificationSubscriptions(self, notification):
     triggerSubscriptions = []
     notification_guid = IGlobalIdentifier(notification).getGUID()
     for subscription in notification.subscriptions:
         triggerSubscriptions.append(dict(
             delay_seconds = notification.delay_seconds,
             repeat_seconds = notification.repeat_seconds,
             subscriber_uuid = notification_guid,
             send_initial_occurrence = notification.send_initial_occurrence,
             trigger_uuid = subscription,
         ))
     subscriptionSet = from_dict(zep.EventTriggerSubscriptionSet, dict(
         subscriptions = triggerSubscriptions
     ))
     self.triggers_service.updateSubscriptions(notification_guid, subscriptionSet)
Exemplo n.º 20
0
    def test_1_DetailUpdates(self):
        eventproto = from_dict(Event, self.initialEvent)
        proxy = EventProxy(eventproto)

        proxy.details['A'] = 1000
        proxy.details['B'] = (1000,)

        self.assertEqual(len(proxy.details), 2)
        self.assertEqual(proxy.details['A'], '1000')
        self.assertRaises(KeyError, proxy.details.__getitem__, 'C')
        del proxy.details['B']
        self.assertEqual(len(proxy.details), 1)
        self.assertRaises(KeyError, proxy.details.__getitem__, 'B')
        # but this does not raise a KeyError
        del proxy.details['B']
        del proxy.details['A']
        self.assertEqual(len(proxy.details), 0)
Exemplo n.º 21
0
    def test_0_TagUpdates(self):
        eventproto = from_dict(ZepRawEvent, self.initialEvent)
        proxy = ZepRawEventProxy(eventproto)

        proxy.tags.addAll('TAG_TYPE_1', ['value%d' % i for i in range(10)])
        proxy.tags.addAll('TAG_TYPE_2', ['value0',])
        proxy.tags.addAll('TAG_TYPE_3', ['value0', 'value1'])
        self.assertEqual(self._countTags(eventproto.event), 13)

        proxy.tags.clearType('TAG_TYPE_1')
        self.assertEqual(self._countTags(eventproto.event), 3)

        self.assertEqual(len(proxy.tags.getByType('TAG_TYPE_3')), 2)

        proxy.tags.clearType('TAG_TYPE_3')
        self.assertEquals(self._countTags(eventproto.event), 1)
        self.assertEqual(len(proxy.tags.getByType('TAG_TYPE_2')), 1)
Exemplo n.º 22
0
 def updateNotificationSubscriptions(self, notification):
     triggerSubscriptions = []
     notification_guid = IGlobalIdentifier(notification).getGUID()
     for subscription in notification.subscriptions:
         triggerSubscriptions.append({
             'delay_seconds': notification.delay_seconds,
             'repeat_seconds': notification.repeat_seconds,
             'subscriber_uuid': notification_guid,
             'send_initial_occurrence':
                 notification.send_initial_occurrence,
             'trigger_uuid': subscription,
         })
     subscriptionSet = from_dict(
         zep.EventTriggerSubscriptionSet,
         {'subscriptions': triggerSubscriptions}
     )
     self.triggers_service.updateSubscriptions(
         notification_guid, subscriptionSet
     )
Exemplo n.º 23
0
    def push(self, data, routingKey, mandatory=False):
        """
        Push a message on the queue

        @param data The data to populate the protobuf with
        """

        proto = self.protobufClass
        proto = jsonformat.from_dict(proto, data)

        log.info('Sending message of type "%s" to "%s" using key "%s"', proto.DESCRIPTOR.full_name, self.exchange.name, routingKey)
        log.debug('Message:\n    %s' % '\n    '.join(MessageToString(proto).split('\n')))

        published = False
        try:
            self.publisher.publish(self.exchange, routingKey, proto, mandatory=mandatory)
            published = True
        except PublishException, e:
            log.error("%s (%d)", e.reply_text, e.reply_code)
Exemplo n.º 24
0
    def _getEventTagSeverities(self, eventClass=(), severity=(), status=(), tags=(), deviceOnly=False):
        if not severity:
            severity = (SEVERITY_CRITICAL, SEVERITY_ERROR, SEVERITY_WARNING)
        if not status:
            status = (STATUS_NEW, STATUS_ACKNOWLEDGED)
        if deviceOnly:
            eventFilter = self.createEventFilter(
                severity=severity,
                status=status,
                event_class=eventClass,
                tags=tags,
                element_sub_identifier=[""],
                )
        else:
            eventFilter = self.createEventFilter(
                severity=severity,
                status=status,
                event_class=eventClass,
                tags=tags,
                )

        response, content = self.client.getEventTagSeverities(from_dict(EventFilter, eventFilter))
        return content.severities
Exemplo n.º 25
0
 def create_exception_event(self, message, exception):
     # construct wrapper event to report this event processing failure
     # including content of the original event
     orig_zep_event = ZepRawEvent()
     orig_zep_event.event.CopyFrom(message)
     failure_event = {
         'uuid': guid.generate(),
         'created_time': int(time() * 1000),
         'fingerprint':
             '|'.join(['zeneventd', 'processMessage', repr(exception)]),
         # Don't send the *same* event class or we loop endlessly
         'eventClass': '/',
         'summary': 'Internal exception processing event: %r' % exception,
         'message':
             'Internal exception processing event: %r/%s' %
             (exception, to_dict(orig_zep_event.event)),
         'severity': 4,
     }
     zep_raw_event = ZepRawEvent()
     zep_raw_event.event.CopyFrom(from_dict(Event, failure_event))
     event_context = EventContext(log, zep_raw_event)
     event_context.eventProxy.device = 'zeneventd'
     event_context.eventProxy.component = 'processMessage'
     return event_context
Exemplo n.º 26
0
    def processMessage(self, message):
        """
        Handles a queue message, can call "acknowledge" on the Queue Consumer
        class when it is done with the message
        """

        if self.SYNC_EVERY_EVENT:
            doSync = True
        else:
            # sync() db if it has been longer than self.syncInterval since the last time
            currentTime = datetime.now()
            doSync = currentTime > self.nextSync
            self.nextSync = currentTime + self.syncInterval

        if doSync:
            self.dmd._p_jar.sync()

        try:
            retry = True
            processed = False
            while not processed:
                try:
                    # extract event from message body
                    zepevent = ZepRawEvent()
                    zepevent.event.CopyFrom(message)
                    if log.isEnabledFor(logging.DEBUG):
                        log.debug("Received event: %s", to_dict(zepevent.event))

                    eventContext = EventContext(log, zepevent)

                    for pipe in self._pipes:
                        eventContext = pipe(eventContext)
                        if log.isEnabledFor(logging.DEBUG):
                            log.debug('After pipe %s, event context is %s' % ( pipe.name, to_dict(eventContext.zepRawEvent) ))
                        if eventContext.event.status == STATUS_DROPPED:
                            raise DropEvent('Dropped by %s' % pipe, eventContext.event)

                    processed = True

                except AttributeError:
                    # _manager throws Attribute errors if connection to zope is lost - reset
                    # and retry ONE time
                    if retry:
                        retry=False
                        log.debug("Resetting connection to catalogs")
                        self._manager.reset()
                    else:
                        raise

        except DropEvent:
            # we want these to propagate out
            raise
        except Exception as e:
            log.info("Failed to process event, forward original raw event: %s", to_dict(zepevent.event))
            # Pipes and plugins may raise ProcessingException's for their own reasons - only log unexpected
            # exceptions of other type (will insert stack trace in log)
            if not isinstance(e, ProcessingException):
                log.exception(e)

            # construct wrapper event to report this event processing failure (including content of the
            # original event)
            origzepevent = ZepRawEvent()
            origzepevent.event.CopyFrom(message)
            failReportEvent = dict(
                uuid = guid.generate(),
                created_time = int(time.time()*1000),
                fingerprint='|'.join(['zeneventd', 'processMessage', repr(e)]),
                # Don't send the *same* event class or we trash and and crash endlessly
                eventClass='/',
                summary='Internal exception processing event: %r' % e,
                message='Internal exception processing event: %r/%s' % (e, to_dict(origzepevent.event)),
                severity=4,
            )
            zepevent = ZepRawEvent()
            zepevent.event.CopyFrom(from_dict(Event, failReportEvent))
            eventContext = EventContext(log, zepevent)
            eventContext.eventProxy.device = 'zeneventd'
            eventContext.eventProxy.component = 'processMessage'

        if log.isEnabledFor(logging.DEBUG):
            log.debug("Publishing event: %s", to_dict(eventContext.zepRawEvent))

        return eventContext.zepRawEvent
Exemplo n.º 27
0
from zenoss.protocols.jsonformat import to_dict, from_dict
from zenoss.protocols.protobufs.zep_pb2 import EventSummary, EventNote, EventSummaryUpdate, EventFilter
from zenoss.protocols.protobufs.zep_pb2 import STATUS_NEW, STATUS_SUPPRESSED
zep = getFacade('zep')
user_name = 'admin'
user_uuid = zep._getUserUuid(user_name)
filter_dict = {'event_summary': ['hola']}
filter_protobuf = from_dict(EventFilter, filter_dict)

suppress_update = from_dict(EventSummaryUpdate, dict(
        status = STATUS_SUPPRESSED,
        current_user_uuid = user_uuid,
        current_user_name = user_name,
))


new_update = from_dict(EventSummaryUpdate, dict(
        status = STATUS_NEW,
        current_user_uuid = user_uuid,
        current_user_name = user_name,
))

print 'Suppressing events that contain the word "hola" in the summary'

#zep.client.updateEventSummaries(suppress_update, event_filter=filter_protobuf)
#zep.client.updateEventSummaries(new_update, event_filter=filter_protobuf)


Exemplo n.º 28
0
 def testFromDict(self):
     pb = from_dict(TestMessage, self.data)
     self._compareProtoDict(self.data, pb)
Exemplo n.º 29
0
import datetime
import time

from zenoss.protocols.jsonformat import to_dict, from_dict
from zenoss.protocols.protobufs.zep_pb2 import EventSummary, EventNote, EventSummaryUpdate, EventFilter
from zenoss.protocols.protobufs.zep_pb2 import STATUS_NEW, STATUS_ACKNOWLEDGED, STATUS_CLOSED, STATUS_SUPPRESSED

from Products.ZenUtils import debugtools

event_summary = str(datetime.datetime.now())

zep = getFacade('zep')
user_name = 'admin'
user_uuid = zep._getUserUuid(user_name)
filter_dict = { 'event_summary': [ event_summary ] }
filter_protobuf = from_dict(EventFilter, filter_dict)


print 'Creating 1000 events containing "{0}" in the event summary'.format(event_summary)
for i in range(0,1000):
	os.system('zensendevent -d localhost "{0} {1}"'.format(event_summary, i))

print 'Sleeping for 1 minute to wait for events to be created'
time.sleep(60)

#Get the events that we just created
response = zep.getEventSummaries(0, filter=filter_protobuf)

uuids = [ event['uuid'] for event in response['events'] ]

@debugtools.profile
# zep_filterA = zep.createEventFilter(status=[0,1], operator=zep.AND, severity=[5])
# zep_filterB = zep.createEventFilter(subfilter=zep_filterA, details={'zenoss.device.production_state':1000})
# zep_filterC = zep.createEventFilter(subfilter=zep_filterB, details={'zenoss.device.priority':1}, operator=zep.OR)

# See $ZENHOME/Products/Zuul/facades/zepfacade.py for more information

# fetch	the events from	zep using the filter we just created
for summary in zep.getEventSummariesGenerator(filter=zep_filter):

    # synchronize each cycle for good measure
    sync()

    # create the event context so that the event can be
    # queried/manipulated as you would in an event transform
    # this is done using an event proxy
    evt = EventSummaryProxy(from_dict(EventSummary, summary))

#     # Here is a full list of available event-related items that are pullable from zen's dmd CLI interface:
#     #  These are commented out, as they are unused to generate the events.csv file for webpass use.
#     print 'component: %s' % (evt.component)
#     print 'dedupid : %s' % (evt.dedupid)
#     print 'evid : %s' % (evt.evid)
#     print 'device : %s' % (evt.device)
#     print 'component : %s' % (evt.component)
#     print 'eventClass : %s' % (evt.eventClass)
#     print 'eventKey : %s' % (evt.eventKey)
#     print 'summary : %s' % (evt.summary)
#     print 'message : %s' % (evt.message)
#     print 'severity : %s' % (evt.severity)
#     print 'eventState : %s' % (evt.eventState)
#     print 'eventClassKey : %s' % (evt.eventClassKey)