TECHZEN Zenoss User Community ARCHIVE  

In search of pointers to help understanding Zenoss from a light weight developer ...

Subject: In search of pointers to help understanding Zenoss from a light weight developer point of view
Author: Larry Virden
Posted: 2016-06-07 08:33

My current team has 2 former developers, 1 person who has been admin for a variety of systems and had to learn bits of different programming languages, and a retiring developer/system programmer.

None of us have python experience. We have just a few months of exposure to Zenoss Core 5and we are trying to learn what we need from examples in the wiki and forums.

One of the simple things we are trying to do is, given an event key, output a few fields from the event. So based on code from one of the wiki pages, we have:

#!/usr/bin/env python

# disponeevent.py - Display one Zenoss eventy by eventKey

# disponeevent.py

import sys

import Globals

from Products.ZenUtils.ZenScriptBase import ZenScriptBase

from transaction import commit

dmd = ZenScriptBase(connect=True, noopts=True).dmd

# import the stuff that zep needs

from Products.Zuul import getFacade, listFacades

from zenoss.protocols.jsonformat import from_dict

from zenoss.protocols.protobufs.zep_pb2 import EventSummary

from Products.ZenEvents.events2.proxy import EventSummaryProxy

# create a context for the sync function

sync = dmd.zport._p_jar.sync

# create the zep context

zep = getFacade('zep')

# create an event filter to only fetch events with

# a specific event key

zep_filter = zep.createEventFilter(event_key=sys.argv[1])

# 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))

# print some information about the event

print 'eventKey: %s' % (evt.eventKey)

print 'Device: %s' % (evt.device)

print 'eventState: %s' % (evt.eventState)

print 'firstTime: %s' % (evt.firstTime)

print 'severity: %s' % (evt.severity)

print 'eventClass: %s' % (evt.eventClass)

print 'lastTime: %s' % (evt.lastTime)

print 'Summary: %s' % (evt.summary)

print 'message: %s' % (evt.message)

-----

The above works if the event is in the console. But if the event is in the archive, we are getting almost no information back.

Is there a way to modify the Generator so that it searches both the current events and the archived events

Thank you



Subject: I would use the API when
Author: Jay Stanley
Posted: 2016-09-02 07:54

I would use the API when working with events, other than loading a dmd instance. It's much faster.

With that being said, you want to query the archive as well, you would need to make two calls.

zep.getEventSummariesGenerator(filter=zep_filter)

and

zep.getEventSummariesGenerator(filter=zep_filter, archive=True)

You can get the same result using the API, with:

(Examples are based on the API documents and examples)

data = { "start" : 0, "limit" : 1000, "sort" : "firstTime", "dir" : "DESC", "params": { "eventKey": "CHANGEME" }, 'archive': False}

ZenossAPI()._router_request('EventsRouter', 'query', [data])

data = { "start" : 0, "limit" : 1000, "sort" : "firstTime", "dir" : "DESC", "params": { "eventKey": "CHANGEME" }, 'archive': True}

ZenossAPI()._router_request('EventsRouter', 'query', [data])



< Previous
Performance Graphs not displaying
  Next
Question regarding use of Zenoss Core in production environments
>