Archived community.zenoss.org | full text search
Skip navigation
2574 Views 5 Replies Latest reply: Nov 15, 2011 10:43 AM by kenhen93 RSS
kenhen93 Rank: White Belt 100 posts since
Sep 27, 2011
Currently Being Moderated

Oct 14, 2011 1:55 PM

Parser Help/Questions

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

 

docs/DOC-3168

 

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

  • cgriebel Rank: Green Belt 175 posts since
    Nov 29, 2007
    Currently Being Moderated
    1. Oct 17, 2011 12:17 PM (in response to kenhen93)
    Re: Parser Help/Questions

    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

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points