TECHZEN Zenoss User Community ARCHIVE  

Help sought with code not displaying events

Subject: Help sought with code not displaying events
Author: Larry Virden
Posted: 2016-09-09 08:16

We are running Zenoss 5.1.1.

We have a script that is supposed to get information regarding an event. However, right now all we are getting is UNKNOWN.

One problem is that I am not certain that the code I am looking at is the code that is executing. I am in the zenhub looking at the code that supposedly is executing. However, I added a print line so I could know that the code is running - and I don't see that line.

I created a snapshot, commited that snapshot, then did a restart of the zenhub. I still don't see the change.

Here's the code I am executing:

#!/usr/bin/env python
# disponeevent.py - Display one Zenoss event by eventKey
# disponeevent.py

import sys

#print 'Number of arguments:', len(sys.argv), 'arguments.'
#print 'Argument list:', str(sys.argv)

# import the stuff that zendmd needs and create the dmd context

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 status of 0 or 1 (new or acknowledged)
zep_filter = zep.createEventFilter(event_key=sys.argv[1])
#print 'zep_filter: %s' % (zep_filter)

# 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 'DaveH display of events'
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)

# create an event filter to use when acknowledging,
# closing, or reopening a single event (set based on evt.evid)
evid_filter = zep.createEventFilter(uuid=[evt.evid])

We are seeing everything EXCEPT the DaveH line - which I just tried to add this morning.

1. Why would I not be getting information in the evt.attributes

2. Why would I not be seeing the DaveH print line

Thank you



Subject: I tried running your script
Author: Jane Curry
Posted: 2016-09-09 10:02

I tried running your script standalone in my 5.0.7 rig. I put the script under /z which is setup as per Chet's instructions here -http://zenpacklib.zenoss.com/en/latest/development-environment-5.html so it is common to all containers and to the host machine.

I ran the script from the zope container and that worked for me.

Cheers,

Jane

Email: jane.curry@skills-1st.co.uk    Web: https://www.skills-1st.co.uk



Subject: How to troubleshoot no output
Author: Larry Virden
Posted: 2016-09-09 10:43

So in my case, through a series of scripts, this code should be invoked. It is not being invoked.

I changed my environment so that I am calling from the zope container as well. The results are still not showing the script being executed. I should be getting back a series of lines to stdout of event information. Instead I am getting 0 lines of stdout.

I have been trying to locate articles with suggestions as to how to track this down. The script is so simple, it is almost as if it is failing before it ever begins.

The script in our environment is called from another script - not invoked from the command line.

Is there something that I could set that would tell me why the script is failing Since you were able to run the script, it doesn't appear to be a syntax error. I befuddled about what might be happening.



Subject: Start breaking it down and
Author: Jay Stanley
Posted: 2016-09-09 11:55

Start breaking it down and simplify

Connect to the container and run the script manually. Do you get output



< Previous
Export / Import Existing Devices Classes, Networks
  Next
SNMP and Windows services/event log errors
>