influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.57k stars 5.57k forks source link

gNMI - failed to parse JSON value #15975

Open rmcleitao opened 1 week ago

rmcleitao commented 1 week ago

Relevant telegraf.conf

[[inputs.gnmi.subscription]]
name = "cisco_gnmi_client"
origin = "rfc7951"
path = "/Cisco-IOS-XE-wireless-client-oper:client-oper-data/common-oper-data"
subscription_mode = "sample"
sample_interval = "120s"

[[inputs.gnmi.tag_subscription]]
name = "descr"
origin = "rfc7951"
path = "/Cisco-IOS-XE-wireless-client-oper:client-oper-data/common-oper-data/ap-name"
subscription_mode = "sample"
sample_interval = "120s"
match = "elements"
elements = ["common-oper-data"]

[[inputs.gnmi.tag_subscription]]
name = "descr"
origin = "rfc7951"
path = "/Cisco-IOS-XE-wireless-client-oper:client-oper-data/common-oper-data/username"
subscription_mode = "sample"
sample_interval = "120s"
match = "elements"
elements = ["common-oper-data"]

[[inputs.gnmi.subscription]]
name = "cisco_gnmi_client"
origin = "rfc7951"
path = "/Cisco-IOS-XE-wireless-client-oper:client-oper-data/common-oper-data/co-state"
subscription_mode = "sample"
sample_interval = "120s"

Logs from Telegraf

2024-10-03T07:33:52Z E! [inputs.gnmi] Processing update path:{origin:"rfc7951"  elem:{name:"Cisco-IOS-XE-wireless-client-oper:client-oper-data"}  elem:{name:"common-oper-data"  key:{key:"client-mac"  value:"30:03:c8:b7:00:00"}}  elem:{name:"username"}}  val:{json_ietf_val:"\"MCH\\mabconline\""} failed: failed to parse JSON value: invalid character 'm' in string escape code
(...)
2024-10-03T07:51:52Z E! [inputs.gnmi] Processing update path:{origin:"rfc7951"  elem:{name:"Cisco-IOS-XE-wireless-client-oper:client-oper-data"}  elem:{name:"common-oper-data"  key:{key:"client-mac"  value:"16:8a:62:88:00:00"}}  elem:{name:"username"}}  val:{json_ietf_val:"\"mch\\salesx\""} failed: failed to parse JSON value: invalid character 's' in string escape code

System info

From Telegraf 1.26.3 up to Telegraf 1.32.0

Docker

No response

Steps to reproduce

  1. Make a gNMI request where the response tag has "\" in the value

Expected behavior

Tags should get the correct value: username= "MCH\mabconline\" username = "mch\salesx\"

Actual behavior

Tags get the correct value: username= None username = None

Additional info

Using Cisco YANG Suite it returns correctly:

Request:

{
  "path": [
    {
      "origin": "rfc7951",
      "elem": [
        {
          "name": "Cisco-IOS-XE-wireless-client-oper:client-oper-data"
        },
        {
          "name": "common-oper-data",
          "key": {
            "client-mac": ""
          }
        },
        {
          "name": "ap-name"
        }
      ]
    },
    {
      "origin": "rfc7951",
      "elem": [
        {
          "name": "Cisco-IOS-XE-wireless-client-oper:client-oper-data"
        },
        {
          "name": "common-oper-data",
          "key": {
            "client-mac": ""
          }
        },
        {
          "name": "username"
        }
      ]
    }
  ],
  "encoding": "JSON_IETF"
}

Response:

val {
  json_ietf_val: "{"client-mac":"30:03:c8:b7:00:00","ap-name":"0298-X-AP000","ms-ap-slot-id":1,"ms-radio-type":"client-dot11ax-5ghz-prot","wlan-id":1,"client-type":"dot11-client-normal","co-state":"client-status-run","aaa-override-passphrase":false,"is-tvi-enabled":false,"wlan-policy":{"current-switching-mode":"local","wlan-switching-mode":"local","central-authentication":"client-authentication-type-central","central-dhcp":false,"central-assoc-enable":false,"vlan-central-switching":false,"is-fabric-client":false,"is-guest-fabric-client":false,"upn-bit-flag":[null]},"username":"MCH\\mabconline","guest-lan-client-info":{"wired-vlan":0,"phy-ifid":0,"idle-time-seconds":0},"method-id":"dot1x-auth-id","l3-vlan-override-received":false,"upn-id":0,"is-locally-administered-mac":false,"idle-timeout":0,"idle-timestamp":"1970-01-01T00:00:00+00:00"}"
}
srebhan commented 1 week ago

Next steps: reproduce locally.