1
2
3
4
5
6
7
8
9
10
11
12
13
14 import logging
15 log = logging.getLogger('zen.ZenRRD.CommandParser')
16
17 from pprint import pformat
18
20
24
26 args = (pformat(self.events), pformat(self.values))
27 return "ParsedResults\n events: %s\n values: %s}" % args
28
30
33
35 """
36 Process the results of a running a command.
37
38 @type cmd: Products.ZenRRD.zencommand.Cmd
39
40 @param cmd: the results of running a command, with the
41 configuration from ZenHub
42 @param results: the values and events from the command output
43 @return: None.
44 """
45 raise NotImplementedError
46
47
48 ParserCache = {}
49
62
75
77 """
78 Import and create the parser for this command
79 """
80 err = ImportError("%s not found" % name)
81 try:
82 return _getParser(name)
83 except ImportError, err:
84 msg = "%s is not a core parser. Attempting to import it from " \
85 "installed zenpacks."
86 log.debug(msg, name)
87 return _getPackParser(name)
88
89
91 "Get the list of all parsers"
92
93 def looksLikeAPlugin(f):
94 if not f.startswith('_') and f.endswith('.py'):
95 return f[:-3]
96
97 import os
98 from Products.ZenUtils.Utils import zenPath
99 result = []
100 for d, ds, fs in os.walk(zenPath('Products','ZenRRD', 'parsers')):
101 for f in fs:
102 plugin = looksLikeAPlugin(f)
103 if plugin:
104 plugin = os.path.join(d, plugin)
105 plugin = plugin.split(os.path.sep)
106 plugin = plugin[plugin.index('parsers') + 1:]
107 plugin = '.'.join(plugin)
108 result.append(plugin)
109
110 for pack in dmd.ZenPackManager.packs():
111 root = pack.path('parsers')
112 for d, ds, fs in os.walk(root):
113 for f in fs:
114 plugin = looksLikeAPlugin(f)
115 if plugin:
116 plugin = os.path.join(d, plugin)
117 plugin = plugin.split(os.path.sep)
118 plugin = plugin[plugin.index('ZenPacks'):]
119 plugin = '.'.join(plugin)
120 result.append(plugin)
121 return sorted(result)
122