Discussion:
JSON add_event - Include Message?
matttherogue
2013-07-30 17:05:23 UTC
Permalink
matttherogue [http://community.zenoss.org/people/matttherogue] created the discussion

"JSON add_event - Include Message?"

To view the discussion, visit: http://community.zenoss.org/message/74233#74233

--------------------------------------------------------------
Good afternoon,

I'm trying to create a API call that will add an event to the system and I'm having two issues. The major issue that I've encountered is the inability to include a separate message text. I tried adding a new function to zep.py and zepfacade.py to accept a message as one of the variables passed, but it gives me some serious errors whenever I try to restart Zenoss afterwards. +Has anyone managed to include message text passed through the API?+

The other issue I'm encountering is that it's simply ignoring my severity setting. I've tried passing everything from  "severity":5 to "severity":"Critical", but with no success so far. Is there something simple I'm completely missing?

Here is a formatted version of my working cURL command.

curl
    -u "user:password"
    -X POST
    -H "Content-Type:application/json"
    -d "{
        \"action\":\"EventsRouter\",
        \"method\":\"add_event\",
        \"data\":[{
            \"summary\":\"summary text here\",
            \"device\":\"tc1-atl.loc\",
            \"component\":\"SYSTEM\",
            \"severity\":5,
            \"evclasskey\":\"\",
            \"evclass\":\"/Random\/Class\"
        }],
        \"type\":\"rpc\",
        \"tid\":1}"
    " http://127.0.0.1:8899/zport/dmd/evconsole_router http://127.0.0.1:8899/zport/dmd/evconsole_router" > resultString.html


Thanks a lot,
-Matt
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/74233#74233]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
matttherogue
2013-07-30 18:49:37 UTC
Permalink
matttherogue [http://community.zenoss.org/people/matttherogue] created the discussion

"Re: JSON add_event - Include Message?"

To view the discussion, visit: http://community.zenoss.org/message/74234#74234

--------------------------------------------------------------
Got it! Well, I can add a message anyway. Still working on severity.

Here was my process

1) cp $ZENHOME/Products/Zuul/facades/zepfacade.py $ZENHOME/Products/Zuul/facades/zepfacade.py.backup
2) Using your favorite editor, vim $ZENHOME/Products/Zuul/facades/zepfacade.py
2a) Add the following function after create(...) (lines 770-781)
def newcreate(self, summary, severity, device, component=None, message=None, mandatory=True, immediate=False,
    occurrence_uuid = str(uuid4())
    rcvtime = time()
    args = dict(evid=occurrence_uuid, summary=summary, severity=severity, device=device)
        args['component'] = component
        args['message'] = message
    args.update(kwargs)
    event = ZenEvent(rcvtime=rcvtime, **args)
    publisher = getUtility(IEventPublisher)
    publisher.publish(event, mandatory=mandatory, immediate=immediate)
2b) Save

3)cp $ZENHOME/Products/Zuul/routers/zep.py $ZENHOME/Products/Zuul/routers/zep.py.backup
4) vim $ZENHOME/Products/Zuul/routers/zep.py
4a) Paste the following function after add_event(...) (lines 599 - 631)
@require('Manage Events')
    """
    Create a new event.
                     Critical, Error, Warning, Info, Debug, or Clear
    """
        self.zep.newcreate(summary, severity, device, component, message, eventClassKey=evclasskey,
                        eventClass=evclass, immediate=True)
        return DirectResponse.succeed("Created event")
        # This occurs if the event is queued but there are no consumers - i.e. zeneventd is not
        # currently running.
        msg = 'Queued event. Check zeneventd status on <a href="/zport/About/zenossInfo">Daemons</a>'
        return DirectResponse.succeed(msg, sticky=True)
        # This occurs if there is a failure publishing the event to the queue.
        log.exception("Failed creating event")
        return DirectResponse.exception(e, "Failed to create event")
4b)Save the file.

5) zenoss restart
curl -u "Username:Password" -X POST -H "Content-Type:application/json" -d "{\"action\":\"EventsRouter\",\"method\":\"newadd_event\",\"data\":[{\"summary\":\"Test Summary\", \"severity\":5, \"device\":\"DEVICENAME\", \"component\":\"SYSTEM\", \"message\":\"Test Message\", \"evclasskey\":\"\", \"evclass\":\"EventClass"}], \"type\":\"rpc\", \"tid\":1}" " http://ZENOSSINSTANCE:PORT/zport/dmd/evconsole_router http://ZENOSSINSTANCE:PORT/zport/dmd/evconsole_router" > OutputLog.html
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/74234#74234]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...