Пример #1
0
    def getAllRouters(self):
        """
        Return a description of the Zenoss routers available.

        from Products.Zuul.routers.introspection import IntrospectionRouter
        zz = IntrospectionRouter(dmd)
        pprint(zz.getAllRouters().data)
        """
        routers = self._getAllRouters()
        data = map(self._getRouterInfo, routers)
        return DirectResponse(data=Zuul.marshal(data))
Пример #2
0
    def getContextMenus(self, uid=None, menuIds=None):
        if uid:
            ob = self.context.dmd.unrestrictedTraverse(uid)
            menuItems = []
            if menuIds:
                menus = self._getDialogMenuItems(menuIds, ob)

                def menuToConfig(menu):
                    return {
                        'id': '%s' % menu.id.lower(),
                        'viewName': menu.action,
                        'text': menu.description
                    }

                if menus:
                    menuItems.extend(menuToConfig(menu) for menu in menus)
        return DirectResponse(menuItems=menuItems)
Пример #3
0
    def classify(self, evrows, evclass):
        """
        Associate event(s) with an event class.

        @type  evrows: [dictionary]
        @param evrows: List of event rows to classify
        @type  evclass: string
        @param evclass: Event class to associate events to
        @rtype:   DirectResponse
        @return:  B{Properties}:
           - msg: (string) Success/failure message
           - success: (boolean) True if class update successful
        """
        msg, url = self.zep.createEventMapping(evrows, evclass)
        if url:
            msg += " | " + url.split('/dmd/')[1]
        return DirectResponse(msg, success=bool(url))
Пример #4
0
    def getRouterMethods(self, router=None):
        """
        Return a JSON list of methods, arguments and documentation

        Example usage from zendmd:

        from Products.Zuul.routers.introspection import IntrospectionRouter
        zz = IntrospectionRouter(dmd)
        pprint(zz.getRouterMethods('DeviceRouter').data)
        """
        if router is not None:
            klasses = self._getRouterByName(router)
            if klasses:
                # TODO: log something?
                klass = klasses[0]
            else:
                return DirectResponse.fail(msg="No router named '%s' found" %
                                           router)
        else:
            klass = self.__class__

        methods = {}
        for name, code in inspect.getmembers(klass):
            if name.startswith('_'):
                continue
            if not inspect.ismethod(code):
                continue

            argspec = inspect.getargspec(code)
            if argspec.defaults is None:
                args = argspec.args[1:]  # Ignore 'self'
                kwargs = {}
            else:
                n = len(argspec.defaults)
                args = argspec.args[1:-n]  # Ignore 'self'
                kwargs = dict(zip(argspec.args[-n:], argspec.defaults))

            methods[name] = dict(
                documentation=inspect.getdoc(code),
                kwargs=kwargs,
                args=args,
            )

        return DirectResponse(data=Zuul.marshal(methods))
Пример #5
0
    def getDetailNavConfigs(self, uid=None, menuIds=None):
        """
        return a list of Detail navigation configurations. Can be used to create
        navigation links. Format is:
        {
        id: <id of the configuration>,
        'viewName': <view to display>,
        'xtype': <Ext type for the panel>,
        'text': <display name of the config info>
        }
        """
        detailItems = []

        def convertToDetailNav(tab):
            return {
                'id': '%s' % tab['name'].lower(),
                'xtype': 'backcompat',
                'viewName': tab['action'],
                'text': tab['name']
            }

        def menuToNav(menu):
            return {
                'id': '%s' % menu.id.lower(),
                'xtype': 'backcompat',
                'viewName': menu.action,
                'text': menu.description
            }

        if uid:
            ob = self.context.dmd.unrestrictedTraverse(uid)
            tabs = ob.zentinelTabs('')
            detailItems = [convertToDetailNav(tab) for tab in tabs]
            #get menu items that are not dialogs
            if menuIds:
                menus = self._getLinkMenuItems(menuIds, ob)
                if menus:
                    detailItems.extend(menuToNav(menu) for menu in menus)
        return DirectResponse(detailConfigs=detailItems)
Пример #6
0
 def getRouterInfo(self, router=None):
     """
     Return information about the router
     """
     data = self._getRouterInfo(router)
     return DirectResponse(data=Zuul.marshal(data))