微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用 JMESPATH 中的值拉出不同的 Key

如何解决用 JMESPATH 中的值拉出不同的 Key

我设法使用 Cisco genie 提取了一些界面统计信息,下面是 JSON(对长 JSON 表示歉意)。

如您所见,接口名称不是静态的。我可以知道如何使用 json_query 提取接口名称和其他统计信息吗?

我使用了这个查询 msg.genie.interface.*.{Bandwidth: bandwidth,crc: counters.in_errors,mac: mac_address,duplex: duplex_mode,speed: port_speed,vrf: vrf,oper: oper_status},结果是这样的。

我只是缺少接口名称。关于如何在输出中包含接口名称的任何建议?

JMESPath 查询

msg.genie.interface.*.{Bandwidth: bandwidth,oper: oper_status}

输出

[
  {
    "Bandwidth": 1000000,"crc": 0,"mac": "2cab.eb8c.59ff","duplex": "auto","speed": "auto speed","vrf": "Mgmt-intf","oper": "down"
  },{
    "Bandwidth": 1000000,"mac": "2cab.eb8c.5970","duplex": "full","speed": "1000mbps","vrf": null,"oper": "up"
  }
]

来自 Cisco genie pull 的完整 JSON:

{
    "msg": {
        "changed": false,"Failed": false,"genie": {
            "interface": {
                "GigabitEthernet0": {
                    "auto_negotiate": true,"bandwidth": 1000000,"counters": {
                        "in_broadcast_pkts": 0,"in_crc_errors": 0,"in_errors": 0,"in_mac_pause_frames": 0,"in_multicast_pkts": 0,"in_octets": 0,"in_pkts": 0,"last_clear": "never","out_errors": 0,"out_mac_pause_frames": 0,"out_octets": 0,"out_pkts": 0,"rate": {
                            "in_rate": 0,"in_rate_pkts": 0,"load_interval": 300,"out_rate": 0,"out_rate_pkts": 0
                        }
                    },"delay": 10,"duplex_mode": "auto","enabled": false,"encapsulation": {
                        "encapsulation": "arpa"
                    },"flow_control": {
                        "receive": false,"send": false
                    },"mac_address": "2cab.eb8c.59ff","mtu": 1500,"oper_status": "down","phys_address": "2cab.eb8c.59ff","port_channel": {
                        "port_channel_member": false
                    },"port_speed": "auto speed","switchport_enable": false,"type": "RP management port","vrf": "Mgmt-intf"
                },"GigabitEthernet0/0/0": {
                    "accounting": {
                        "arp": {
                            "chars_in": 1253820,"chars_out": 1347648,"pkts_in": 20897,"pkts_out": 21057
                        },"cdp": {
                            "chars_in": 93408529,"chars_out": 93849340,"pkts_in": 198326,"pkts_out": 220327
                        },"ip": {
                            "chars_in": 43533539576,"chars_out": 243171224580,"pkts_in": 51407196,"pkts_out": 272100765
                        },"ipv6": {
                            "chars_in": 351879534,"chars_out": 0,"pkts_in": 2933568,"pkts_out": 0
                        },"other": {
                            "chars_in": 1330840333,"chars_out": 95196860,"pkts_in": 18437333,"pkts_out": 241382
                        },"spanning tree": {
                            "chars_in": 2276096512,"pkts_in": 35564008,"pkts_out": 0
                        }
                    },"auto_negotiate": true,"in_multicast_pkts": 27276714,"in_octets": 45638217915,"in_pkts": 78759308,"out_octets": 243268978899,"out_pkts": 272342613,"rate": {
                            "in_rate": 25000,"in_rate_pkts": 5,"out_rate": 73000,"out_rate_pkts": 5
                        }
                    },"duplex_mode": "full","enabled": true,"encapsulation": {
                        "encapsulation": "dot1q","first_dot1q": "1"
                    },"mac_address": "2cab.eb8c.5970","oper_status": "up","phys_address": "2cab.eb8c.5970","port_speed": "1000mbps","type": "ISR4321-2x1GE"
                }
            }
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。