TECHZEN Zenoss User Community ARCHIVE  

API: How to add and manage event using JSON python API

Subject: API: How to add and manage event using JSON python API
Author: [Not Specified]
Posted: 2013-12-28 11:03

Andrew Kirch
Welcome, Andrew Kirch (Log out)

New
Your Stuff
History
Browse

Search for:
Zenoss Community > Forums > zenoss-users > Discussions
Up to Discussions in zenoss-users
1428 Views 11 Replies Latest reply: Dec 25, 2013 9:21 AM by Photon RSS
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
11
May 20, 2013 11:27 AM
API: How to add and manage event using JSON python API

This question is Not Answered.(Mark as assumed answered)

I'm trying to use JSON/Python API to create a new event

I'm using the documentation (ZenossAPIExample) to create a new event (create_event_on_device)

Up to this point it's working and I am able to create a new event,

The problem is I don't understand how to use the data returns to manage the event,

For example, the return code is:

{u'uuid': u'b8791acb-b6f9-4071-b065-9c26e36acd45', u'tid': 1, u'result': {u'msg'

: u'Created event', u'success': True}, u'action': u'EventsRouter', u'type': u'rp

c', u'method': u'add_event'}

My questions:

1. Is there any way to get the "Event ID" in the return call

2. What is the "u'uuid'" used for

All event actions (Acknowledge, close, add note etc..) requires the event ID and I'm trying to sync Zenoss with 3rd party events.

System:

Zenoss: 4.2.3

OS: CentOS 6.4

Any suggestions

Thanks

Like (0)
Reply

Tags (edit): zenoss-core, api, zenoss_api, 4.2, 4.2.3

Shane Scott ZenossMaster
Shane Scott
1,373 posts since
Jul 6, 2009
1. May 20, 2013 5:00 PM (in response to James M)
Re: API: How to add and manage event using JSON python API

James,

What are you trying to solve for I may have a published solution I can point you to.

Best,

--Shane Scott (hackman238)

http://shanewilliamscott.com

http://linkedin.com/in/shanewilliamscott
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
2. May 21, 2013 3:00 AM (in response to Shane Scott)
Re: API: How to add and manage event using JSON python API

Hey Shane Scott

I'm trying to integrate Zenoss events with an internal system (self developed).

Basically what I need is:

Use API to open an event and get the event ID in the callback (return code)

and then update the event (notes, ack, close etc..)

I just don't understand how to get this value (event ID) in the callback while creating an event.

Any suggestions will be appreciated.

Many thanks!
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
3. May 26, 2013 6:37 AM (in response to James M)
Re: API: How to add and manage event using JSON python API

Any suggestions
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
vitaly_il Rank: Green Belt
vitaly_il
189 posts since
Jul 8, 2008
4. May 27, 2013 6:28 AM (in response to James M)
Re: API: How to add and manage event using JSON python API

James, if I undersood properly (I haven't had hands-on experience with this stuff ), uuid and evid are two representation (formats) of the same ID.

See

http://community.zenoss.org/message/70515

http://wiki.zenoss.org/ZenDMD_Tip_-_Manipulate_Events

and Jane's paper http://www.skills-1st.co.uk/papers/jane/zenoss4-events/
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
5. Dec 24, 2013 12:55 PM (in response to vitaly_il)
Re: API: How to add and manage event using JSON python API

Hi

Still didn't manage to do that..

I'm opening a new event and getting the next data:

{u'uuid': u'43e33625-9dbb-42b1-a609-6750481b4c9b', u'tid': 1, u'result': {u'msg': u'Created event', u'success': True}, u'action': u'EventsRouter', u'type': u'rpc', u'method': u'add_event'}

But I didn't understand how to "convert" the 'uuid' to 'evid'

I want to use API call to close the event but I need the evid to do that..

Any suggestions
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
Photon Rank: White Belt
Photon
44 posts since
Apr 15, 2011
6. Dec 24, 2013 6:54 PM (in response to James M)
Re: API: How to add and manage event using JSON python API

Hi !

As far as I know, evid and uuid are the same... Where you can find a difference, is in the MySQL database where the uuid is stored as a binary representation. Also, you can aknowledge an event using the zepfacade methods and an event's uuid. I never used the JSON API but using a dmd script, it can go this way:

zendmd

>>> from Products.Zuul import getFacade

>>> from zenoss.protocols.jsonformat import from_dict

>>> from zenoss.protocols.protobufs.zep_pb2 import EventSummary

>>> from Products.ZenEvents.events2.proxy import EventSummaryProxy

>>> zep = getFacade('zep')

>>> filter1 =zep.createEventFilter(uuid=u'43e33625-9dbb-42b1-a609-6750481b4c9b')

>>> eventDict = zep.getEventSummariesGenerator(filter=filter1).next()

>>> eventDict['uuid']

>>> evt = EventSummaryProxy(from_dict(EventSummary, eventDict))

>>> evt.evid

>>> zep.acknowledgeEventSummaries(eventFilter=filter1)

You should find out that eventDict['uuid'] == evt.evid and that your event has been aknowledged

Good luck,

--

Fayal
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
alex0cy Rank: White Belt
alex0cy
58 posts since
May 13, 2008
7. Dec 25, 2013 4:52 AM (in response to James M)
Re: API: How to add and manage event using JSON python API

Why not to use snmp traps and event transforms
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
8. Dec 25, 2013 5:36 AM (in response to vitaly_il)
Re: API: How to add and manage event using JSON python API

Hi Photon, vitaly_il & Shane Scott

Thanks for your response.

I have converted the 'blob' to evid, BUT what I get is the evid which is not the same as the 'uuid' I'm getting in the API callback.

API uuid = 96bc2155-6a3a-422f-901c-ccd7370d27c7

evid = 0050568b-1ad6-bb6a-11e3-6cbd7bdf7e74

How do I correlate between them

To be clearer:

1. I'm opening an event using JSON API

2. Receiving the 'uuid' in the callback

---3 --- Here I'm missing a way to use this 'uuis' and convert it to the evid (using THIS uuid)

4. with the evid I can use the API for additional actions (acknowledge, notes, close, etc...)

alex0cy - snmp traps are not what I'm looking for (Working on automation using API)

Any suggestions

Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
Photon Rank: White Belt
Photon
44 posts since
Apr 15, 2011
9. Dec 25, 2013 6:06 AM (in response to James M)
Re: API: How to add and manage event using JSON python API

Hi,

Can you post your JSON API call so that I recreate the situation here
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
James M Rank: White Belt
James M
56 posts since
Nov 14, 2012
10. Dec 25, 2013 6:39 AM (in response to Photon)
Re: API: How to add and manage event using JSON python API

Hi Photon

Thanks for your reply.

I'm using the python API script 'api_example.py' method: 'create_event_on_device' from the official documentation:

http://community.zenoss.org/servlet/JiveServlet/downloadBody/13242-102-1...

method:

def create_event_on_device(self, device, severity, summary):

if severity not in ('Critical', 'Error', 'Warning', 'Info', 'Debug', 'Clear'):

raise Exception('Severity "' + severity +'" is not valid.')

data = dict(device=device, summary=summary, severity=severity,

component='', evclasskey='', evclass='')

return self._router_request('EventsRouter', 'add_event', [data])

The call is:

event = api.create_event_on_device('testDevice', 'Warning', 'TEST! zenoss api new event')

print event:

{u'uuid': u'96bc2155-6a3a-422f-901c-ccd7370d27c7', u'tid': 1, u'result': {u'msg': u'Created event', u'success': True}, u'action': u'EventsRouter', u'type': u'rpc', u'method': u'add_event'}

I need to get the 'evid' of this 'uuid'

Thanks
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply
Photon Rank: White Belt
Photon
44 posts since
Apr 15, 2011
11. Dec 25, 2013 9:21 AM (in response to James M)
Re: API: How to add and manage event using JSON python API

I used your code and noticed that when creating the same event multiple times (translated to an incrementation of the count field in the event console), I get each time a different uuid... I think there is no direct correlation between the uuid you get and the evid. I also checked if it corresponded to the occurence uuids of the created event, but that wasn't the case...

Maybe the uuid you get is just identifying your call and not the event.

Can't be of much help here...

Good luck !
Correct Answer
Helpful Answer
Edit
Delete
Branch
Report Abuse
Like (0)
Reply



< Previous
KeyError:'macAddresses'