def exportConfiguration(self, triggerIds=None, notificationIds=None): facade = self._getFacade() triggers, notifications = facade.exportConfiguration(triggerIds, notificationIds) msg = "Exported %d triggers and %d notifications" % (len(triggers), len(notifications)) audit("UI.TriggerNotification.Export", msg) return DirectResponse.succeed( triggers=Zuul.marshal(triggers), notifications=Zuul.marshal(notifications), msg=msg )
def exportConfiguration(self, triggerIds=None, notificationIds=None): facade = self._getFacade() triggers, notifications = facade.exportConfiguration(triggerIds, notificationIds) msg = "Exported %d triggers and %d notifications" % ( len(triggers), len(notifications)) audit('UI.TriggerNotification.Export', msg) return DirectResponse.succeed(triggers=Zuul.marshal(triggers), notifications=Zuul.marshal(notifications), msg=msg)
def test_recursion(self): data = [TestClass(), TestClass()] result = Zuul.marshal(data) self.assert_(isinstance(result, list)) for o in result: self.match(o) data = {'a':TestClass(), 'b':TestClass()} result = Zuul.marshal(data) self.assert_(isinstance(result, dict)) self.assertEqual(sorted(result.keys()), ['a', 'b']) for v in result.values(): self.match(v)
def test_recursion_with_keys(self): keys = ['foo', '_bar'] data = [TestClass(), TestClass()] result = Zuul.marshal(data, keys=keys) self.assert_(isinstance(result, list)) for o in result: self.match(o, keys=keys) data = {'a':TestClass(), 'b':TestClass()} result = Zuul.marshal(data, keys=keys) self.assert_(isinstance(result, dict)) self.assertEqual(sorted(result.keys()), ['a', 'b']) for v in result.values(): self.match(v, keys=keys)
def getIpAddresses(self, uid, start=0, params=None, limit=50, sort='ipAddressAsInt', page=None, dir='ASC'): """ Given a subnet, get a list of IP addresses and their relations. @type uid: string @param uid: Unique identifier of a subnet @type start: integer @param start: Offset to return the results from; used in pagination @type params: string @param params: Not used @type limit: integer @param limit: Number of items to return; used in pagination @type sort: string @param sort: (optional) Key on which to sort the return results; defaults to 'name' @type order: string @param order: Sort order; can be either 'ASC' or 'DESC' @rtype: DirectResponse """ if isinstance(params, basestring): params = unjson(params) instances = self.api.getIpAddresses(uid=uid, start=start, params=params, limit=limit, sort=sort, dir=dir) keys = ['name', 'netmask', 'pingstatus', 'snmpstatus', 'uid', 'device', 'interface', 'macAddress', 'interfaceDescription'] data = Zuul.marshal(instances.results, keys) return DirectResponse.succeed(data=data, totalCount=instances.total, hash=instances.hash_)
def getSequence(self, uid): """ returns the sequence order of keys for a given instance """ facade = self._getFacade() data = facade.getSequence(uid) return DirectResponse(data=Zuul.marshal(data))
def getTraps( self, uid, dir='ASC', sort='name', start=0, page=None, limit=256): count, nodes = self.api.getMibNodes( uid=uid, dir=dir, sort=sort, start=start, limit=limit, relation='notifications' ) return DirectResponse.succeed(count=count, data=Zuul.marshal(nodes))
def _correctReportTitles(self, data): data = Zuul.marshal(data) # show the context in the report title, otherwise the user # has no idea which component the graph is for for row in data: row['title'] = row['contextTitle'] return DirectResponse(data=data)
def queryGenerator(self, sort='lastTime', dir='desc', evids=None, excludeIds=None, params=None, archive=False, uid=None, detailFormat=False): """ Query for events. @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'lastTime') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'DESC') @type params: dictionary @param params: (optional) Key-value pair of filters for this search. (default: None) @type archive: boolean @param archive: (optional) True to search the event archive instead of active events (default: False) @type uid: string @param uid: (optional) Context for the query (default: None) @rtype: generator @return: Generator returning events. """ if not self._canViewEvents(): return includeFilter, excludeFilter = self._buildRequestFilters(uid, params, evids, excludeIds) events = self.zep.getEventSummariesGenerator(filter=includeFilter, exclude=excludeFilter, sort=self._buildSort(sort,dir), archive=archive) eventFormat = EventCompatInfo if detailFormat: eventFormat = EventCompatDetailInfo for event in events: yield Zuul.marshal(eventFormat(self.context.dmd, event))
def getSequence(self, uid): """ returns the sequence order of keys for a given instance """ facade = self._getFacade() data = facade.getSequence(uid) return DirectResponse(data=Zuul.marshal(data) )
def getManufacturerData(self, uid): """ return all extra data for manufacturer id """ facade = self._getFacade() data = facade.getManufacturerData(uid) return DirectResponse(data=Zuul.marshal(data) )
def getMembers(self, uid, keys=None): facade = self._getFacade() if keys is None: keys = ['severity', 'monitor', 'hidden', 'leaf', 'uid', 'text', 'id', 'path', 'iconCls', 'uuid', 'name', 'meta_type'] data = facade.getMembers(uid) return DirectResponse(data=Zuul.marshal(data, keys), totalCount=len(data), hash=len(data))
def getSupportSettings(self): """ Retrieves the collection of settings """ settings = self._getSupportSettings() return DirectResponse.succeed( data=Zuul.marshal(settings.getSupportSettingsData()))
def getProductData(self, uid, prodname): """ return all extra data for product id """ facade = self._getFacade() data = facade.getProductData(uid, prodname) return DirectResponse(data=Zuul.marshal(data) )
def deleteMaintWindow(self, uid, id): """ delete a maintenance window """ facade = self._getFacade() data = facade.deleteMaintWindow(uid, id) return DirectResponse.succeed(data=Zuul.marshal(data))
def deleteUserCommand(self, uid, id): """ delete a user command """ facade = self._getFacade() data = facade.deleteUserCommand(uid, id) return DirectResponse.succeed(data=Zuul.marshal(data))
def isTransformEnabled(self, uid): """ Returns True if transform is enabled, False if disabled. """ facade = self._getFacade() data = facade.isTransformEnabled(uid) return DirectResponse(data=Zuul.marshal(data))
def getManufacturers(self): """ return all manufacturers """ facade = self._getFacade() data = facade.getManufacturers() return DirectResponse(data=Zuul.marshal(data))
def setInfo(self, **data): """ Set attributes on an object. This method accepts any keyword argument for the property that you wish to set. The only required property is "uid". @type uid: string @keyword uid: Unique identifier of an object @rtype: DirectResponse @return: B{Properties}: - data: (dictionary) The modified object """ uid = data['uid'] del data['uid'] obj = self._getFacade()._getObject(uid) passwordFields = self._getPasswordFields(obj) oldData = self._getInfoData(obj, data) info = self._getFacade().setInfo(uid, data) newData = self._getInfoData(obj, data) # Trac #29376: Consistently show thresholdType with threshold operations. thresholdType = obj.getTypeName() if isinstance(obj, ThresholdClass) else None audit(['UI', getDisplayType(obj), 'Edit'], obj, thresholdType=thresholdType, data_=newData, oldData_=oldData, skipFields_=('newId',), # special case in TemplateFacade.setInfo() maskFields_=passwordFields) return DirectResponse.succeed(data=Zuul.marshal(info))
def getUsers(self, keys=None, start=0, limit=50, page=0, sort='name', dir='ASC', name=None): """ Retrieves a list of users. This method supports pagination. @type start: integer @param start: (optional) Offset to return the results from; used in pagination (default: 0) @type name: string @param name: (optional) filter to be applied to users returned (default: None) @type limit: integer @param limit: (optional) Number of items to return; used in pagination (default: 50) @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'name') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'ASC') @rtype: DirectResponse @return: B{Properties}: - data: (list) Dictionaries of user properties - totalCount: (integer) Number of devices returned """ facade = self._getFacade() users = facade.getUsers(start=start, limit=limit, sort=sort, dir=dir, name=name) total = users.total data = Zuul.marshal(users, keys) return DirectResponse.succeed(data=data, totalCount=total)
def queryArchive(self, page=None, limit=0, start=0, sort='lastTime', dir='desc', params=None, exclusion_filter=None, keys=None, uid=None, detailFormat=False): if not self._canViewEvents(): return DirectResponse.succeed( events = [], totalCount = 0, asof = time.time() ) filter = self._buildFilter([uid], params) if exclusion_filter is not None: exclusion_filter = self._buildFilter([uid], exclusion_filter) events = self.zep.getEventSummariesFromArchive(limit=limit, offset=start, sort=self._buildSort(sort,dir), filter=filter, exclusion_filter=exclusion_filter) eventFormat = EventCompatInfo if detailFormat: eventFormat = EventCompatDetailInfo dmd = self.context.dmd # filter out the component and device UUIDs that no longer exist in our system evdata = self._filterInvalidUuids(events['events']) eventObs = [eventFormat(dmd, e) for e in evdata] return DirectResponse.succeed( events = Zuul.marshal(eventObs, keys), totalCount = events['total'], asof = time.time() )
def getProductInstances(self, uid, id, params={}): """ return all instances of this product """ facade = self._getFacade() data = facade.getProductInstances(uid, id, params) return DirectResponse(data=Zuul.marshal(data) )
def getTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) nodes = [ITreeNode(m) for m in monitorfacade.query()] for monitor in nodes: apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) apps = appfacade.queryMasterDaemons() for app in apps: nodes.append(IInfo(app)) return Zuul.marshal(nodes) except URLError as e: log.exception(e) return DirectResponse.fail("Error fetching daemons list: " + str(e.reason))
def _correctReportTitles(self, data): data = Zuul.marshal(data) # show the context in the report title, otherwise the user # has no idea which component the graph is for for row in data: row['title'] = row['contextTitle'] return DirectResponse(data=data)
def isTransformEnabled(self, uid): """ Returns True if transform is enabled, False if disabled. """ facade = self._getFacade() data = facade.isTransformEnabled(uid) return DirectResponse(data=Zuul.marshal(data) )
def getInstances(self, uid, start=0, params=None, limit=50, sort='name', page=None, dir='ASC'): """ Get a list of instances for a process UID. @type uid: string @param uid: Process UID to get instances of @type start: integer @param start: (optional) Offset to return the results from; used in pagination (default: 0) @type params: dictionary @param params: (optional) Key-value pair of filters for this search. @type limit: integer @param limit: (optional) Number of items to return; used in pagination (default: 50) @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'name') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'ASC') @rtype: DirectResponse @return: B{Properties}: - data: ([dictionary]) List of objects representing process instances - total: (integer) Total number of instances """ facade = self._getFacade() instances = facade.getInstances(uid, start, limit, sort, dir, params) keys = ['device', 'monitored', 'pingStatus', 'processName', 'name', 'uid', 'minProcessCount', 'maxProcessCount'] data = Zuul.marshal(instances, keys) return DirectResponse.succeed(data=data, totalCount=instances.total)
def getManufacturers(self): """ return all manufacturers """ facade = self._getFacade() data = facade.getManufacturers() return DirectResponse(data=Zuul.marshal(data))
def deleteMaintWindow(self, uid, id): """ delete a maintenance window """ facade = self._getFacade() data = facade.deleteMaintWindow(uid, id) return DirectResponse.succeed(data=Zuul.marshal(data))
def getManufacturerList(self): """ return a usable tree """ facade = self._getFacade() data = facade.getManufacturerList() return DirectResponse(data=Zuul.marshal(data))
def queryGenerator(self, sort='lastTime', dir='desc', evids=None, excludeIds=None, params=None, archive=False, uid=None, detailFormat=False): """ Query for events. @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'lastTime') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'DESC') @type params: dictionary @param params: (optional) Key-value pair of filters for this search. (default: None) @type archive: boolean @param archive: (optional) True to search the event archive instead of active events (default: False) @type uid: string @param uid: (optional) Context for the query (default: None) @rtype: generator @return: Generator returning events. """ if not self._canViewEvents(): return includeFilter, excludeFilter = self._buildRequestFilters(uid, params, evids, excludeIds) events = self.zep.getEventSummariesGenerator(filter=includeFilter, exclude=excludeFilter, sort=self._buildSort(sort, dir), archive=archive) eventFormat = EventCompatInfo if detailFormat: eventFormat = EventCompatDetailInfo for event in events: yield Zuul.marshal(eventFormat(self.context.dmd, event))
def getInstances(self, uid, start=0, params=None, limit=50, sort='name', page=None, dir='ASC'): """ Get a list of instances for a service UID. @type uid: string @param uid: Service UID to get instances of @type start: integer @param start: (optional) Offset to return the results from; used in pagination (default: 0) @type params: dictionary @param params: (optional) Key-value pair of filters for this search. @type limit: integer @param limit: (optional) Number of items to return; used in pagination (default: 50) @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'name') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'ASC') @rtype: DirectResponse @return: B{Properties}: - data: ([dictionary]) List of objects representing service instances - totalCount: (integer) Total number of instances """ if isinstance(params, basestring): params = unjson(params) instances = self.api.getInstances(uid, start=start, params=params, limit=limit, sort=sort, dir=dir) keys = ['description', 'device', 'locking', 'monitored', 'name', 'pingStatus', 'uid'] data = Zuul.marshal(instances, keys) return DirectResponse.succeed(data=data, totalCount=instances.total)
def getTransform(self, uid): """ returns a transform for the context """ facade = self._getFacade() data = facade.getTransform(uid) return DirectResponse(data=Zuul.marshal(data) )
def getTransformTree(self, uid): """ returns a transform for the context with all its inherited transforms """ facade = self._getFacade() data = facade.getTransformTree(uid) return DirectResponse(data=Zuul.marshal(data) )
def getInstances(self, uid, start=0, params=None, limit=50, sort='name', page=None, dir='ASC'): """ Get a list of instances for a process UID. @type uid: string @param uid: Process UID to get instances of @type start: integer @param start: (optional) Offset to return the results from; used in pagination (default: 0) @type params: dictionary @param params: (optional) Key-value pair of filters for this search. @type limit: integer @param limit: (optional) Number of items to return; used in pagination (default: 50) @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'name') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'ASC') @rtype: DirectResponse @return: B{Properties}: - data: ([dictionary]) List of objects representing process instances - total: (integer) Total number of instances """ facade = self._getFacade() instances = facade.getInstances(uid, start, limit, sort, dir, params) keys = ['device', 'monitored', 'pingStatus', 'processName', 'name', 'uid'] data = Zuul.marshal(instances, keys) return DirectResponse.succeed(data=data, totalCount=instances.total)
def getManufacturerData(self, uid): """ return all extra data for manufacturer id """ facade = self._getFacade() data = facade.getManufacturerData(uid) return DirectResponse(data=Zuul.marshal(data))
def getProductInstances(self, uid, id, params={}): """ return all instances of this product """ facade = self._getFacade() data = facade.getProductInstances(uid, id, params) return DirectResponse(data=Zuul.marshal(data))
def getEventsCounts(self, uid): """ return all the event counts for this context """ facade = self._getFacade() data = facade.getEventsCounts(uid) return DirectResponse(data=Zuul.marshal(data) )
def queryArchive(self, page=None, limit=0, start=0, sort='lastTime', dir='desc', params=None, exclusion_filter=None, keys=None, uid=None, detailFormat=False): if not self._canViewEvents(): return DirectResponse.succeed( events=[], totalCount=0, asof=time.time() ) filter = self._buildFilter(uid, params) if exclusion_filter is not None: exclusion_filter = self._buildFilter(uid, exclusion_filter) events = self.zep.getEventSummariesFromArchive(limit=limit, offset=start, sort=self._buildSort(sort, dir), filter=filter, exclusion_filter=exclusion_filter) eventFormat = EventCompatInfo if detailFormat: eventFormat = EventCompatDetailInfo dmd = self.context.dmd # filter out the component and device UUIDs that no longer exist in our system evdata = self._filterInvalidUuids(events['events']) eventObs = [eventFormat(dmd, e) for e in evdata] return DirectResponse.succeed( events=Zuul.marshal(eventObs, keys), totalCount=events['total'], asof=time.time() )
def getUsers(self, keys=None, start=0, limit=50, page=0, sort='name', dir='ASC', name=None): """ Retrieves a list of users. This method supports pagination. @type start: integer @param start: (optional) Offset to return the results from; used in pagination (default: 0) @type name: string @param name: (optional) filter to be applied to users returned (default: None) @type limit: integer @param limit: (optional) Number of items to return; used in pagination (default: 50) @type sort: string @param sort: (optional) Key on which to sort the return results (default: 'name') @type dir: string @param dir: (optional) Sort order; can be either 'ASC' or 'DESC' (default: 'ASC') @rtype: DirectResponse @return: B{Properties}: - data: (list) Dictionaries of user properties - totalCount: (integer) Number of devices returned """ facade = self._getFacade() users = facade.getUsers(start=start, limit=limit, sort=sort, dir=dir, name=name) total = users.total data = Zuul.marshal(users, keys) return DirectResponse.succeed(data=data, totalCount=total)
def getTransformTree(self, uid): """ returns a transform for the context with all its inherited transforms """ facade = self._getFacade() data = facade.getTransformTree(uid) return DirectResponse(data=Zuul.marshal(data))
def getUserInterfaceSettings(self): """ Retrieves the collection of User interface settings """ settings = self._getUISettings() return DirectResponse.succeed( data=Zuul.marshal(settings.getSettingsData()))
def getInstanceData(self, uid): """ return all extra data for instance id """ facade = self._getFacade() data = facade.getInstanceData(uid) return DirectResponse(data=Zuul.marshal(data))
def getEventsCounts(self, uid): """ return all the event counts for this context """ facade = self._getFacade() data = facade.getEventsCounts(uid) return DirectResponse(data=Zuul.marshal(data))
def getIpAddresses(self, uid, start=0, params=None, limit=50, sort='ipAddressAsInt', page=None, dir='ASC'): """ Given a subnet, get a list of IP addresses and their relations. @type uid: string @param uid: Unique identifier of a subnet @type start: integer @param start: Offset to return the results from; used in pagination @type params: string @param params: Not used @type limit: integer @param limit: Number of items to return; used in pagination @type sort: string @param sort: (optional) Key on which to sort the return results; defaults to 'name' @type order: string @param order: Sort order; can be either 'ASC' or 'DESC' @rtype: DirectResponse """ if isinstance(params, basestring): params = unjson(params) instances = self.api.getIpAddresses(uid=uid, start=start, params=params, limit=limit, sort=sort, dir=dir) keys = ['name', 'netmask', 'pingstatus', 'snmpstatus', 'uid', 'device', 'interface', 'macAddress', 'interfaceDescription', 'manageDevice'] data = Zuul.marshal(instances.results, keys) return DirectResponse.succeed(data=data, totalCount=instances.total, hash=instances.hash_)
def getTransform(self, uid): """ returns a transform for the context """ facade = self._getFacade() data = facade.getTransform(uid) return DirectResponse(data=Zuul.marshal(data))
def getProductData(self, uid, prodname): """ return all extra data for product id """ facade = self._getFacade() data = facade.getProductData(uid, prodname) return DirectResponse(data=Zuul.marshal(data))
def getTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) nodes = [ITreeNode(m) for m in monitorfacade.query()] for monitor in nodes: apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) apps = appfacade.queryMasterDaemons() for app in apps: nodes.append(IInfo(app)) return Zuul.marshal(nodes) except URLError as e: log.exception(e) return DirectResponse.fail( "Error fetching daemons list: " + str(e.reason) )
def deleteUserCommand(self, uid, id): """ delete a user command """ facade = self._getFacade() data = facade.deleteUserCommand(uid, id) return DirectResponse.succeed(data=Zuul.marshal(data))
def setInfo(self, **data): """ Set attributes on an object. This method accepts any keyword argument for the property that you wish to set. The only required property is "uid". @type uid: string @keyword uid: Unique identifier of an object @rtype: DirectResponse @return: B{Properties}: - data: (dictionary) The modified object """ uid = data['uid'] del data['uid'] obj = self._getFacade()._getObject(uid) oldData = self._getInfoData(obj, data) info = self._getFacade().setInfo(uid, data) newData = self._getInfoData(obj, data) # Trac #29376: Consistently show thresholdType with threshold operations. thresholdType = obj.getTypeName() if isinstance( obj, ThresholdClass) else None audit(['UI', getDisplayType(obj), 'Edit'], obj, thresholdType=thresholdType, data_=newData, oldData_=oldData, skipFields_=( 'newId', )) # special case in TemplateFacade.setInfo() return DirectResponse.succeed(data=Zuul.marshal(info))
def getInstanceData(self, uid): """ return all extra data for instance id """ facade = self._getFacade() data = facade.getInstanceData(uid) return DirectResponse(data=Zuul.marshal(data) )
def getSequence(self, uid): """ returns the sequence order of keys for a given instance """ facade = self._getFacade() data = facade.getSequence(uid) audit('UI.EventClasses.SetSequence', uid, data_=data) return DirectResponse(data=Zuul.marshal(data))
def getInstances(self, uid, params=None): """ Returns event class mappings for the current context """ facade = self._getFacade() data = facade.getInstances(uid) return DirectResponse(data=Zuul.marshal(data))
def getSequence(self, uid): """ returns the sequence order of keys for a given instance """ facade = self._getFacade() data = facade.getSequence(uid) audit('UI.EventClasses.SetSequence', uid, data_=data) return DirectResponse(data=Zuul.marshal(data) )
def getInstances(self, uid, params=None): """ Returns event class mappings for the current context """ facade = self._getFacade() data = facade.getInstances(uid) return DirectResponse( data=Zuul.marshal(data) )
def addNewInstance(self, params=None): """ Add new event class mapping for the current context """ facade = self._getFacade() newInstance = facade.addNewInstance(params) audit('UI.EventClasses.AddInstance', params['newName'], data_=params) return DirectResponse.succeed(data=Zuul.marshal(newInstance))
def getApplicationConfigFiles(self, id): """ Returns all the configuration files for an application """ facade = self._getFacade() info = IInfo(facade.get(id)) files = info.configFiles return DirectResponse.succeed(data=Zuul.marshal(files))
def getProductsByManufacturer(self, uid, params={}): """ Returns products for the current context """ facade = self._getFacade() data = facade.getProductsByManufacturer(uid, params) return DirectResponse( data=Zuul.marshal(data) )
def getProductsByManufacturer(self, uid, params={}): """ Returns products for the current context """ facade = self._getFacade() data = facade.getProductsByManufacturer(uid, params) return DirectResponse(data=Zuul.marshal(data))