Skip to content

Instantly share code, notes, and snippets.

@cluther
Last active May 22, 2018 18:52
Show Gist options
  • Save cluther/dbb893a5b1c3aeece4a3f1d4304c18e4 to your computer and use it in GitHub Desktop.
Save cluther/dbb893a5b1c3aeece4a3f1d4304c18e4 to your computer and use it in GitHub Desktop.
Extending Zenoss JSON API
from Products.Zuul import getFacade
class ResolveSysRouter(DirectRouter):
"""
JSON API router.
This router is accessed via POST to a URL such as the following.
https://zenoss5.example.com/zport/dmd/resolvesys_router
With an application/json data such as the following.
{
"action": "ResolveSysRouter",
"method": "updateEventDetails",
"data": [
{
"evid": "c0136587-0ce2-417f-94ce-2c13ab4c228a",
"details": {
"Zenoss.Resolve.Worksheet": "exhibit-a",
"WhatIsThatServiceNowFieldCalled": "INC12345"
}
}
]
}
Note that the "resolvesys_router" portion of the URL comes from the name
we give our "directRouter" in configure.zcml when we register it.
"""
def updateEventDetails(self, evid, **details):
"""Update event details of event identified by evid."""
# zep is the "Zenoss Event Processor" API.
zep = getFacade("zep")
# This is easy because we already have a method for it.
zep.updateDetails(evid, **details)
<?xml version="1.0" encoding="utf-8"?>
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<!-- Register our custom JSON API endpoint (router). -->
<browser:directRouter
name="resolvesys_router"
for="*"
class=".api.ResolveSysRouter"
namespace="Zenoss.remote"
permission="Zenoss.View"
/>
</configure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment