繁体   English   中英

textFSM 模板中的可选字符串

[英]Optional string in textFSM template

我有一个 cli output by moxa switch show running-config 接口部分可能有也可能没有名称字符串。

interface ethernet 1/3
 shutdown
 name Unused
 speed-duplex Auto
 no flowcontrol
 media cable-mode auto
 no gmrp
 switchport access vlan  1
 rate-limit port-disable ingress rate none
 no ptp
!

interface ethernet 1/8
 shutdown
 speed-duplex Auto
 no flowcontrol
 media cable-mode auto
 no gmrp
 switchport access vlan  1
 rate-limit port-disable ingress rate none
 no ptp

这是我用于解析的 FSM 模板

Value port (\d\/\d)
Value state (shutdown|no shutdown)
Value desc (\S+)

Start
  ^interface ethernet ${port} -> Continue.Record
  ^.${state}
  ^.name.${desc}

但是这样接口名的output就下移了一行。 我怎样才能修复这个模板?

Output 示例

port    state        desc
------  -----------  ----------------
1/1
1/2     no shutdown  Cisco_2960_OTPSS
1/3     no shutdown  Mirror
1/8     shutdown     Unused
1/9     shutdown
        no shutdown  Proverka

在描述不完整的路由条目时,链接TextFSM 用法显示了一个与您的问题非常相似的示例:

...当出现下一个完整的路由条目时,确实应该写入不完整的路由条目,但同时应该将它们写入适当的路由。 应该做以下事情:一旦满足完整的路由条目,应该记下之前的值,然后继续处理相同的完整路由条目以获取其信息。

在您的上下文中:

^interface ethernet -> Continue.Record

在这里, Record操作告诉您写下变量的当前值。 由于此规则中没有变量,因此将写入先前值中的内容。 Continue操作表示继续使用当前行,就好像没有匹配一样。

Start
  ^interface ethernet -> Continue.Record
  ^interface ethernet ${port}
  ^.${state}
  ^.name.${desc}
port    state     desc
------  --------  ------
1/3     shutdown  Unused
1/8     shutdown

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM