Oct 14, 2011 1:55 PM
Parser Help/Questions
-
Like (0)
Hi,
I am trying to create my own command parser and I have few question that I was hoping someone could help answer. I used this document
to learn how to make a parser and I also studied the existing df.py parser and kind of modeled my parser after so
for the 'scanners' plugin, what is the purpose of the '\d+' in (?P<availableBlocks>\d+). I understand what \d+ means in terms of python regex but is that \d+ the regex of the variable <availableBlocks> or is that saying it has trailing digits after the variable?
Also in the df.py example there as a line called componentSplit which seemed to tell where to start parsing. Is that right? My parser starts on the first line so I commented this line out. Is that the right way to do it or should I keep it and just leave it empty like so: componentSplit = ''"
Basically I am trying parse an output like so
Fri, 14 Oct 2011 13:23:25 EDT: Instance1
Performance_1=0|Performance_2=224|
Here is an small example of the parser I wrote:
from Products.ZenRRD.ComponentCommandParser import ComponentCommandParser
class custom_parse(ComponentCommandParser):
# componentSplit = ''
componentScanner = '^\w{3}\,\s\d{1,}\s\w{3}\s\d{4}\s\d{1,}\:\d{2}\:\d{2}\s\w{3}\:\s(?P<component>)'
scanners = [
r' Performance_1=(?P<Performance_1>\d+)\|Performance_2=(?P<Performance_2>\d+)\|'
]
componentScanValue = 'Instance_Number'
The zenoss created a pyc file for parser.py. I am currently getting the following error
2011-10-14 08:52:31,768 INFO zen.ZenHub: Worker reports 2011-10-14 08:52:31,767 ERROR zen.hub: getDeviceCommands() exception for device p01-rtb-ckp01.prod.root
Traceback (most recent call last):
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 140, in getDataSourceCommands
cmdinfo = getDeviceCommands(dev)
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 88, in getDeviceCommands
threshs = getComponentCommands(dev, cache, cmds, dev.getDmd())
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 39, in getComponentCommands
parser = ploader.create()
File "/zenoss/zenoss/Products/DataCollector/Plugins.py", line 111, in create
traceback=traceback.format_exc().splitlines())
PluginImportError: ('Traceback (most recent call last):', ' File "/zenoss/zenoss/Products/DataCollector/Plugins.py", line 102, in create', ' self.modPath)', ' File "/zenoss/zenoss/Products/DataCollector/Plugins.py", line 164, in importPlugin', ' return getattr(mod, clsname)', "AttributeError: 'module' object has no attribute 'custom_parse'")
Thanks for any help
I believe the filename and the class name need to match. I've run into this myself. Either rename the class to "parser" or rename the .py file to custom_parse.py and you'll get further along.
Chock
Thanks, let me give that a try
I found some syntax errors in my regex and reworked it. I am like 99% sure my regex is right as it works on some regex websites.
I am now getting an error
Traceback (most recent call last):
File "/opt/zenoss/Products/ZenHub/zenhub.py", line 656, in <module>
z.main()
File "/opt/zenoss/Products/ZenHub/zenhub.py", line 623, in main
reactor.run()
File "/zenoss/zenoss/lib/python/twisted/internet/base.py", line 1048, in run
self.mainLoop()
File "/zenoss/zenoss/lib/python/twisted/internet/base.py", line 1057, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/zenoss/zenoss/lib/python/twisted/internet/base.py", line 705, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/zenoss/zenoss/Products/ZenHub/services/Procrastinator.py", line 37, in _doNow
d = self.cback(device)
File "/zenoss/zenoss/Products/ZenHub/services/PerformanceConfig.py", line 169, in pushConfig
cfg = self.getDeviceConfig(device)
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 125, in getDeviceConfig
return getDeviceCommands(device)
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 88, in getDeviceCommands
threshs = getComponentCommands(dev, cache, cmds, dev.getDmd())
File "/zenoss/zenoss/Products/ZenHub/services/CommandConfig.py", line 50, in getComponentCommands
dpc.data = parser.dataForParser(comp, dp)
File "/zenoss/zenoss/Products/ZenRRD/ComponentCommandParser.py", line 36, in dataForParser
return dict(componentScanValue = getattr(context, self.componentScanValue))
exceptions.AttributeError: InstanceNumber
I still cannot find any info on what the componentsplit is
The componentScanValue is supposed to equal the component value in the command that you create within the zenoss GUI, right?
Can anyone please help me with this? I don't know where to go from here.
I got this to work by commenting some lines out of the componentcommandparser.py
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||