gpt4 book ai didi

python - 将 Netscaler 显示输出转换为 BNF 进行解析

转载 作者:行者123 更新时间:2023-11-28 17:40:46 25 4
gpt4 key购买 nike

我是 pyparsing 的新手,需要帮助将下面的输出解析成字典对象

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

更新

    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")

从上面我需要使用pyparsing库编写解析逻辑

最佳答案

我想通了,textFSM 最适合这个。

关于python - 将 Netscaler 显示输出转换为 BNF 进行解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com