【问题标题】:Is there a way to record multiple values for a single key with TextFSM?有没有办法用 TextFSM 为单个键记录多个值?
【发布时间】:2021-12-13 14:24:02
【问题描述】:

我是 TextFSM 的新手,我正在尝试使用 TextFSM 解析 BigIP F5 配置。最终结果仅捕获与虚拟服务器关联的多个配置文件中的一个配置文件。我正试图把他们全部抓起来。

我已经尝试了很多 TextFSM 命令组合,但也许我只是无法理解它是如何正常工作的。

输入

ltm virtual /Common/Cust_A_Virtual_Server {
    destination /Common/10.10.10.10:443
    ip-protocol tcp
    mask 255.255.255.255
    pool /Common/Cust_A_pool
    profiles {
        /Common/Cust_A_SSL {
            context clientside
        }
        /Common/Cust_A_http { }
        /Common/tcp { }
    }
    rules {
        /Common/Cust_A_iRule
    }
    source 0.0.0.0/0
    translate-address enabled
    translate-port enabled
    vlans {
        /Common/Cust_A_v1100
    }
    vlans-enabled
}

当前结果

{
    "virtual": "Cust_A_Virtual_Server",
    "virtualpart": "Common",
    "vprof": "tcp",
    "vprofpart": "Common"
}

期望的结果

{
    "virtual": "Cust_A_Virtual_Server",
    "virtualpart": "Common",
    "vprof": ["Cust_A_SSL","Cust_A_http","tcp"]
    "vprofpart": ["Common","Common","Common"]
}

我使用下面的 TextFSM 模板来获得高于“当前结果”

Value Filldown virtual (\S+)
Value Filldown virtualpart (\S+)
Value Required vprof ([a-zA-Z\/\-0-9.]+(?!:))
Value vprofpart (\S+)

Start
  ^ltm\svirtual\s\/${virtualpart}\/${virtual} -> Continue
  ^\s+profiles\s[{]\n+ -> Continue.Record
  ^\s+\/${vprofpart}\/${vprof}\s[{] -> Continue.Record

【问题讨论】:

    标签: python networking ansible f5 python-textfsm


    【解决方案1】:

    我不熟悉 TextFSM,但想知道是否不是从 bigip.conf 中提取,而是从 REST API 中获取并重新处理该输出?

    获取 https:///mgmt/tm/ltm/virtual/

    GET https:///mgmt/tm/ltm/virtual//profiles

    【讨论】:

    • 很遗憾,我们不能使用 REST API,因为我们有一系列设备在不支持 REST/SOAP API 的不同版本上运行。我们唯一的选择是扫描配置文件。 bigip.conf 的任何配置解析器(基于 RegEx/TextFSM)都会有所帮助
    【解决方案2】:

    这里有两件事可以提供帮助:List optionthe state transition。 模板:

    Value virtual (\S+)
    Value virtualpart (\S+)
    Value List vprof (\S+)
    Value List vprofpart (\S+)
    
    Start
      ^ltm\svirtual\s/${virtualpart}/${virtual}
      ^\s+profiles -> Profiles
    
    Profiles
      ^\s+/${vprofpart}/${vprof}\s{
      ^\s+rules -> Record Start
    

    结果:

     {'virtual': 'Cust_A_Virtual_Server',
      'virtualpart': 'Common',
      'vprof': ['Cust_A_SSL', 'Cust_A_http', 'tcp'],
      'vprofpart': ['Common', 'Common', 'Common']}
    

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 2020-12-14
      • 1970-01-01
      • 2018-11-14
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 2017-06-24
      相关资源
      最近更新 更多