1

我有 moxa switch 的 cli 输出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}

但是这样接口名称的输出会下移一行。我怎样才能修复这个模板?

输出示例

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
4

1 回答 1

0

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

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

在您的上下文中:

^interface ethernet -> Continue.Record

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

Start
  ^interface ethernet -> Continue.Record
  ^interface ethernet ${port}
  ^.${state}
  ^.name.${desc}
port    state     desc
------  --------  ------
1/3     shutdown  Unused
1/8     shutdown
于 2021-04-17T11:50:04.233 回答