Package Products :: Package Zuul :: Package routers :: Module monitor
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.monitor

 1  ############################################################################## 
 2  # 
 3  # Copyright (C) Zenoss, Inc. 2013, all rights reserved. 
 4  # 
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  # 
 8  ############################################################################## 
 9   
10  import logging 
11   
12  from Products import Zuul 
13  from Products.ZenUtils.Ext import DirectResponse 
14  from Products.Zuul.interfaces import IInfo, ITreeNode 
15  from Products.Zuul.routers import TreeRouter 
16  from Products.ZenUtils.controlplane.client import ControlCenterError 
17   
18   
19  log = logging.getLogger('zen.MonitorRouter') 
20   
21   
22 -class MonitorRouter(TreeRouter):
23 """ 24 """ 25
26 - def _getFacade(self):
27 return Zuul.getFacade('monitors', self.context)
28
29 - def getTree(self, id):
30 """ 31 Returns the tree structure of the application (service) hierarchy where 32 the root node is the organizer identified by the id parameter. 33 34 @type id: string 35 @param id: Id of the root node of the tree to be returned 36 @rtype: [dictionary] 37 @return: Object representing the tree 38 """ 39 facade = self._getFacade() 40 monitors = facade.query() 41 nodes = map(ITreeNode, monitors) 42 data = Zuul.marshal(nodes) 43 return data
44
45 - def getInfo(self, id):
46 """ 47 Returns the serialized info object for the given id 48 @type: id: String 49 @param id: Valid id of a application 50 @rtype: DirectResponse 51 @return: DirectResponse with data of the application 52 """ 53 facade = self._getFacade() 54 monitor = facade.get(id) 55 data = Zuul.marshal(ITreeNode(monitor)) 56 return DirectResponse.succeed(data=data)
57
58 - def addCollector(self, id, sourceId, hubId, poolId):
59 """ 60 Adds a collector to the hub specified by hub id. 61 @type: id: String 62 @param id: Valid id of a hub 63 @rtype: DirectResponse 64 @return: DirectResponse Upon success 65 """ 66 facade = self._getFacade() 67 try: 68 monitor = IInfo(facade.addMonitor( 69 id, sourceId=sourceId, hubId=hubId, poolId=poolId 70 )) 71 except ControlCenterError as e: 72 log.error("Control Center error: %s", e.message) 73 return DirectResponse.fail(e.message) 74 return DirectResponse.succeed(data=Zuul.marshal(monitor))
75
76 - def getCollectors(self, query=None):
77 facade = self._getFacade() 78 collectors = [IInfo(collector) for collector in facade.query()] 79 return DirectResponse.succeed(data=Zuul.marshal(collectors))
80
81 - def getCollector(self, collectorString):
82 """ 83 Get a collector by name 84 @type collectorString: string 85 @param collectorString: name of collector to return 86 """ 87 facade = Zuul.getFacade('monitors', self.context) 88 collector = IInfo(facade.get(collectorString)) 89 return DirectResponse.succeed(data=Zuul.marshal(collector))
90