1
2
3
4
5
6
7
8
9
10
11 __doc__ = """ServiceTester
12
13 Simple utility class for testing out zenhub services.
14 Sample usage (at the bottom of a service):
15
16 if __name__ == '__main__':
17 from Products.ZenHub.ServiceTester import ServiceTester
18 tester = ServiceTester(PingPerformanceConfig)
19 def printer(config):
20 for ip in config.monitoredIps:
21 print '\t', ip
22 tester.printDeviceProxy = printer
23 tester.showDeviceInfo()
24
25 Note that the service instance can be found as an attribute
26 on the tester object.
27
28 ie tester.service == PingPerformanceConfig(dmd, 'localhost')
29 """
30
31 from pprint import pprint
32 import logging
33 log = logging.getLogger('zen.ServiceTester')
34
35 import Globals
36
37 from Products.ZenUtils.Utils import setLogLevel
38 from Products.ZenUtils.ZCmdBase import ZCmdBase
39
40
42 doesLogging = False
43
51
53 ZCmdBase.buildOptions(self)
54 self.parser.add_option('--monitor', dest='monitor', default='localhost',
55 help="Specify the collector to collect against.")
56 self.parser.add_option('-d', '--device', dest='device',
57 help="Show the configs for a single device")
58
61
63 if self.options.device:
64 name = self.options.device
65 config = self.service.remote_getDeviceConfigs([name])
66 if config:
67 print "Config for %s =" % name
68 self.printDeviceProxy(config[0])
69 else:
70 log.warn("No configs found for %s", name)
71 else:
72 devices = sorted(x.id for x in self.service.remote_getDeviceConfigs())
73 print "Device list = %s" % devices
74
76 """
77 Device proxies don't report their interal state very well. This
78 should be overwritten by the zenhub service writer.
79 """
80 pprint(proxy)
81