Skip to content

Instantly share code, notes, and snippets.

@cluther
Last active May 22, 2018 18:52
Show Gist options
  • Select an option

  • Save cluther/dbb893a5b1c3aeece4a3f1d4304c18e4 to your computer and use it in GitHub Desktop.

Select an option

Save cluther/dbb893a5b1c3aeece4a3f1d4304c18e4 to your computer and use it in GitHub Desktop.

Revisions

  1. cluther revised this gist May 22, 2018. 2 changed files with 41 additions and 1 deletion.
    39 changes: 39 additions & 0 deletions api.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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)
    3 changes: 2 additions & 1 deletion configure.zcml
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    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="*"
    @@ -11,4 +12,4 @@
    permission="Zenoss.View"
    />

    </configure>
    </configure>
  2. cluther created this gist May 22, 2018.
    14 changes: 14 additions & 0 deletions configure.zcml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?xml version="1.0" encoding="utf-8"?>
    <configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser">

    <browser:directRouter
    name="resolvesys_router"
    for="*"
    class=".api.ResolveSysRouter"
    namespace="Zenoss.remote"
    permission="Zenoss.View"
    />

    </configure>