influxdata / telegraf

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

Support for space in gnmi path #15405

Closed dangleminh closed 3 months ago

dangleminh commented 6 months ago

Use Case

We are using gnmi input but seems space doesnt work for path, please see below:

[[inputs.gnmi.subscription]]
    name = "show_version"
    origin = "cli"
    subscription_mode = "sample"
    path = "show version"
    sample_interval = "10s"

Getting the error:

root@telegraf:/tmp# tail -n 10 /var/log/telegraf/telegraf.log
2024-05-27T12:53:55Z I! Available plugins: 233 inputs, 9 aggregators, 31 processors, 24 parsers, 60 outputs, 6 secret-stores
2024-05-27T12:53:55Z I! Loaded inputs: gnmi
2024-05-27T12:53:55Z I! Loaded aggregators: 
2024-05-27T12:53:55Z I! Loaded processors: 
2024-05-27T12:53:55Z I! Loaded secretstores: 
2024-05-27T12:53:55Z I! Loaded outputs: file influxdb_v2
2024-05-27T12:53:55Z I! Tags enabled: host=telegraf
2024-05-27T12:53:55Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegraf", Flush Interval:10s
2024-05-27T12:53:55Z D! [agent] Initializing plugins
2024-05-27T12:53:55Z E! [telegraf] Error running agent: could not initialize input inputs.gnmi: invalid string path show version: invalid node name: "show version"

Expected behavior

path is required space as every cli in the network OS contains space. Openconfig gnmic can support space as below:

root@telegraf:/etc/telegraf# gnmic -a <ip>:6030 -u <username> -p <password> --insecure  --gzip get --path "cli:/show version"
[
  {
    "source": "10.0.0.101:6030",
    "timestamp": 1716814647867157162,
    "time": "2024-05-27T12:57:27.867157162Z",
    "updates": [
      {
        "Path": "cli:show version",
        "values": {
          "show version": {
            "architecture": "i686",
            "bootupTimestamp": 1716573325.0758307,
            "configMacAddress": "00:00:00:00:00:00",
            "hardwareRevision": "",
            "hwMacAddress": "00:00:00:00:00:00",
            "imageFormatVersion": "1.0",
            "imageOptimization": "None",
            "internalBuildId": "9d8310d2-cc5a-4c85-b6ef-08ce13f0255f",
            "internalVersion": "4.31.2F-35442146.4312F",
            "isIntlVersion": false,
            "memFree": 791188,
            "memTotal": 1979896,
            "mfgName": "Arista",
            "modelName": "vEOS-lab",
            "serialNumber": "A71651D2A2FCA4E3B45AFC452C440CDF",
            "systemMacAddress": "0c:6e:eb:30:b0:13",
            "uptime": 241323.16,
            "version": "4.31.2F"
          }
        }
      }
    ]
  }
]
root@telegraf:/etc/telegraf# 

Actual behavior

Openconfig gnmic can support space as below:

root@telegraf:/etc/telegraf# gnmic -a <ip>:6030 -u <username> -p <password> --insecure  --gzip get --path "cli:/show version"
[
  {
    "source": "10.0.0.101:6030",
    "timestamp": 1716814647867157162,
    "time": "2024-05-27T12:57:27.867157162Z",
    "updates": [
      {
        "Path": "cli:show version",
        "values": {
          "show version": {
            "architecture": "i686",
            "bootupTimestamp": 1716573325.0758307,
            "configMacAddress": "00:00:00:00:00:00",
            "hardwareRevision": "",
            "hwMacAddress": "00:00:00:00:00:00",
            "imageFormatVersion": "1.0",
            "imageOptimization": "None",
            "internalBuildId": "9d8310d2-cc5a-4c85-b6ef-08ce13f0255f",
            "internalVersion": "4.31.2F-35442146.4312F",
            "isIntlVersion": false,
            "memFree": 791188,
            "memTotal": 1979896,
            "mfgName": "Arista",
            "modelName": "vEOS-lab",
            "serialNumber": "A71651D2A2FCA4E3B45AFC452C440CDF",
            "systemMacAddress": "0c:6e:eb:30:b0:13",
            "uptime": 241323.16,
            "version": "4.31.2F"
          }
        }
      }
    ]
  }
]
root@telegraf:/etc/telegraf# 

Additional info

No response

powersj commented 6 months ago

Hi,

The error comes from the gnxi library we use, which checks the node name against a regex. As the code comment states, hat regex comes from RFC 6020 which states:

Identifiers are used to identify different kinds of YANG items by
   name.  Each identifier starts with an uppercase or lowercase ASCII
   letter or an underscore character, followed by zero or more ASCII
   letters, digits, underscore characters, hyphens, and dots.
   Implementations MUST support identifiers up to 64 characters in
   length.  Identifiers are case sensitive.  The identifier syntax is
   formally defined by the rule "identifier" in [Section 12](https://datatracker.ietf.org/doc/html/rfc6020#section-12).  Identifiers
   can be specified as quoted or unquoted strings.

Note, spaces or whitespace are not included in this. There is a discussion about whitespace and escaping right before this section in 6.1.3. @srebhan will ask upstream for confirmation as to the support of whitespace.

srebhan commented 5 months ago

@dangleminh I asked for clarification of the standard in https://github.com/openconfig/reference/issues/209, let's wait for an answer and then see how we continue...

noredistribution commented 5 months ago

steering away from this convo a bit but any reason why you cannot use the EOS native + the OpenConfig paths to read the same info, for instance EOS version information is stored in /Eos/image


gnmic -a 10.1.1.1:6030 -u admin -p admin --gzip --insecure get --path "eos_native:/Eos/image"
[
  {
    "source": "10.1.1.1:6030",
    "timestamp": 1716995120650759369,
    "time": "2024-05-29T16:05:20.650759369+01:00",
    "prefix": "eos_native:Eos/image",
    "updates": [
      {
        "Path": "serialNum",
        "values": {
          "serialNum": "65312759-2bab-4913-9769-0aebaaf046dc"
        }
      },
      {
        "Path": "version",
        "values": {
          "version": "4.31.3M"
        }
      },
      {
        "Path": "buildHost",
        "values": {
          "buildHost": "dhcp-244-252-129.sjc.aristanetworks.com"
        }
      },
      {
        "Path": "buildTime",
        "values": {
          "buildTime": 1714379144000000000
        }
      },
      {
        "Path": "name",
        "values": {
          "name": "image"
        }
      },
      {
        "Path": "flavor",
        "values": {
          "flavor": "DEFAULT"
        }
      },
      {
        "Path": "release",
        "values": {
          "release": "36737551.4313M"
        }
      },
      {
        "Path": "variant",
        "values": {
          "variant": "US"
        }
      },
      {
        "Path": "arch",
        "values": {
          "arch": "x86_64"
        }
      },
      {
        "Path": "blessed",
        "values": {
          "blessed": true
        }
      },
      {
        "Path": "displayVersion",
        "values": {
          "displayVersion": "4.31.3M"
        }
      }
    ]
  }
]

serial number can be found in OC in /components/component/state/serial-no system mac address in OC in /components/component/state/base-mac-address MemAvailable and MemUtilized are in /components/component/state/memory

HTH!

josh-silvas commented 5 months ago

Just wanted to add on here, as I am running into the same issue, however, there doesn't appear to be a eos_native or openconfig spec on the information I need.

gnmic -a  10.10.10.10:6030 -u admin -p admin --insecure get --gzip --encoding json --path "cli:/show dot1x hosts"

Output:

[
  {
    "source": "10.10.10.10:6030",
    "timestamp": 1717620389701535774,
    "time": "2024-06-05T15:46:29.701535774-05:00",
    "updates": [
      {
        "Path": "cli:show dot1x hosts",
        "values": {
          "show dot1x hosts": {
            "intfSupplicantsDict": {
              "Ethernet10": {
                "supplicants": {
                  "aa:aa:de:ad:be:ef": {
                    "authMethod": "EAPOL",
                    "authStage": "SUCCESS",
                    "cachedAuthAtLinkDown": false,
                    "fallback": "NONE",
                    "reauthTimeoutSeen": false,
                    "supplicantMac": "aa:aa:de:ad:be:ef",
                    "vlanId": ""
                  }
                }
              }
            }
          }
        }
      }
    ]
  }
]

But I am receiving a similar error:

Error running agent: could not initialize input inputs.gnmi: invalid string path show dot1x hosts: invalid node name: "show dot1x hosts"
srebhan commented 5 months ago

@josh-silvas you are running a get but the plugin only supports subscriptions... Did you try with subscribing to that path?

telegraf-tiger[bot] commented 3 months ago

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!