Search code examples
pythonpyparsingbnfnetscaler

Convert Netscaler show output to BNF for parsing


I am new to pyparsing, need to help with the below output to parse into a dictionary object

MONLB01> sh lb vserver montest_4567_VS2
    montest_4567_VS2 (167.22.55.130:4567) - TCP    Type: ADDRESS
    State: DOWN
    Effective State: DOWN
    Client Idle Timeout: 9000 sec
    Down state flush: ENABLED
    Configured Method: ROUNDROBIN
    Mode: IP
    Persistence: NONE
    Connection Failover: DISABLED
1) montest_6248_S3 (177.24.41.3: 6248) - TCP State: DOWN      Weight: 1
2) montest_6248_S4 (177.24.41.3: 6248) - TCP State: DOWN      Weight: 1
   Done

UPDATE

    from pyparsing import \
    Literal, Word, ZeroOrMore, Group, Dict, Optional, \
    printables, ParseException, restOfLine
    import pprint


    inibnf = None
    def inifile_BNF():
    <!!!!!Parsing Logic!!!Need Help here>
    return inibnf


pp = pprint.PrettyPrinter(2)
def test( strng ):
   print strng
    try:
        iniFile = file(strng)
        iniData = "".join( iniFile.readlines() )
        bnf = inifile_BNF()
        tokens = bnf.parseString( iniData )
        pp.pprint( tokens.asList() )

    except ParseException, err:
        print err.line
        print " "*(err.column-1) + "^"
        print err

iniFile.close()
ini = test("netscalerout.txt")

from the above i need to write the parsing logic using pyparsing library


Solution

  • i figured out, textFSM is best suited for this.