1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__ = """ServiceTester
15
16 Simple utility class for testing out zenhub services.
17 Sample usage (at the bottom of a service):
18
19 if __name__ == '__main__':
20 from Products.ZenHub.ServiceTester import ServiceTester
21 tester = ServiceTester(PingPerformanceConfig)
22 def printer(config):
23 for ip in config.monitoredIps:
24 print '\t', ip
25 tester.printDeviceProxy = printer
26 tester.showDeviceInfo()
27
28 Note that the service instance can be found as an attribute
29 on the tester object.
30
31 ie tester.service == PingPerformanceConfig(dmd, 'localhost')
32 """
33
34 from pprint import pprint
35 import logging
36 log = logging.getLogger('zen.ServiceTester')
37
38 import Globals
39
40 from Products.ZenUtils.ZCmdBase import ZCmdBase
41
42
44 doesLogging = False
45
53
55 ZCmdBase.buildOptions(self)
56 self.parser.add_option('--monitor', dest='monitor', default='localhost',
57 help="Specify the collector to collect against.")
58 self.parser.add_option('-d', '--device', dest='device',
59 help="Show the configs for a single device")
60
62 """
63 Change the logging level to allow for more insight into the
64 in-flight mechanics of Zenoss.
65
66 @parameter level: logging level at which messages display (eg logging.INFO)
67 @type level: integer
68 """
69 rootlog = logging.getLogger()
70 rootlog.setLevel(level)
71 for handler in rootlog.handlers:
72 if isinstance(handler, logging.StreamHandler):
73 handler.setLevel(level)
74
77
79 if self.options.device:
80 name = self.options.device
81 config = self.service.remote_getDeviceConfigs([name])
82 if config:
83 print "Config for %s =" % name
84 self.printDeviceProxy(config[0])
85 else:
86 log.warn("No configs found for %s", name)
87 else:
88 devices = sorted(x.id for x in self.service.remote_getDeviceConfigs())
89 print "Device list = %s" % devices
90
92 """
93 Device proxies don't report their interal state very well. This
94 should be overwritten by the zenhub service writer.
95 """
96 pprint(proxy)
97