簡體   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