1
2
3
4
5
6
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
23 """
24 """
25
27 return Zuul.getFacade('monitors', self.context)
28
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
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
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
77 facade = self._getFacade()
78 collectors = [IInfo(collector) for collector in facade.query()]
79 return DirectResponse.succeed(data=Zuul.marshal(collectors))
80
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