0

我正在尝试确定如何测试 junos 偶尔使用的节点属性。在这种特殊情况下,我想查找在 20w 和 1y 之间关闭的所有 BGP 会话。秒值包含在节点属性中,但我无法弄清楚如何访问它以进行测试。

我已经尝试了使用整个显式 xpath 的各种方法,一直到我在代码下面的内容。

这是我试图访问的 xpath(为简洁而编辑):

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.2R3/junos">
    <bgp-information xmlns="http://xml.juniper.net/junos/18.2R3/junos-routing">
        <bgp-peer junos:style="terse" heading="Peer                     AS      InPkt     OutPkt    OutQ   Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...">
            <elapsed-time junos:seconds="263788">3d 1:16:28</elapsed-time>
        </bgp-peer>
    </bgp-information>
</rpc-reply>
test_bgp_summ:
  - rpc: get-bgp-summary-information
  - iterate:
      xpath: /bgp-information/bgp-peer
      id: ./peer-address
      tests:
        - in-range: //@junos:seconds, 12096000, 31449600
          err: ""
          info: 'Peer session <{{id_0}}> is likely stale'
4

1 回答 1

0

您需要在测试中包含经过时间节点:

show_bgp_sum:
  - command: show bgp summary
  - iterate:
      xpath: '//bgp-information/bgp-peer'
      id: ./peer-address
      tests:
        - exists: elapsed-time/@seconds
          err: "elpased-time doesn't exist"
          info: "Elapsed-time is: <{{post['elapsed-time/@seconds']}}>"

和输出:

                   "passed": [
                        {
                            "actual_node_value": "1309804", 
                            "id": {
                                "./peer-address": "10.10.12.100"
                            }, 
                            "message": "Elapsed-time is: <1309804>", 
                            "post": {
                                "elapsed-time/@seconds": "1309804"
                            }, 
                            "pre": {
                                "elapsed-time/@seconds": "1309802"
                            }
                        }, 
于 2019-11-27T00:33:51.200 回答