1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 __doc__='''zenx.py
16
17 Provide sendevent, get config, save perf data, etc services to remote daemons
18 via xmlrpc.
19 '''
20
21 import time
22 from sets import Set
23 import socket
24
25 import Globals
26 from Products.ZenEvents.EventServer import EventServer
27
28 from Products.ZenEvents.Event import Event
29
30 from twisted.internet import reactor, defer
31 from twisted.python import failure
32 from twisted.web import xmlrpc, server
33
34 XML_RPC_PORT = 8081
35
36 -class ZenX(EventServer, xmlrpc.XMLRPC):
37
38 totalTime = 0.
39 totalEvents = 0
40 maxTime = 0.
41 name = 'zenx'
42
47
48
49
57
61
64
67
70
72 ''' EventServer is calling this in a separate thread to handle
73 requests in self.q
74 '''
75 method, data, result, ts = args
76 try:
77 retval = method(*data)
78 if retval is None:
79 retval = ''
80 reactor.callFromThread(result.callback, retval)
81 except Exception, ex:
82 self.log.exception(ex)
83 reactor.callFromThread(result.errback,
84 xmlrpc.Fault(self.FAILURE, str(ex)))
85
86
87
88 - def xmlrpc_getPageChecks(self, monitorName=socket.getfqdn()):
89 return self.execute(self.getPageChecks, (monitorName,))
90
91 - def getPageChecks(self, monitorName=socket.getfqdn()):
92 monitor = getattr(self.dmd.Monitors.Performance, monitorName, '')
93 if monitor:
94 import pprint
95 result = monitor.getPageChecks()
96
97
98 self.log.info('--------------')
99 self.log.info(pprint.pformat(result))
100 self.log.info('--------------')
101 else:
102 raise 'No performance monitor named %s' % monitorName
103 return result
104
105
106
107
116
117
118 if __name__ == '__main__':
119 z = ZenX()
120 z.main()
121