### Get RPC with multiple paths (alternative format) Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/get.md This example demonstrates retrieving data from multiple paths using separate `--path` flags, similar to the first example but presented in the main examples section. ```bash gnmic -a get --path "/state/port[port-id=*]" \ --path "/state/router[router-name=*]/interface[interface-name=*]" ``` -------------------------------- ### Using gnmic Prompt Mode with Pre-set Flags Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/prompt_suggestions.md This example demonstrates how to launch gnmic's prompt mode with several global flags already specified. The prompt will then start with these flags pre-set. ```bash gnmic --insecure --username admin --password admin --address 10.1.0.11 prompt ``` -------------------------------- ### Start a basic collector Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/collector.md Starts a gnmic collector using a specified configuration file. ```bash gnmic --config collector.yaml collect ``` -------------------------------- ### Local File Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of configuring the file loader for a local file in YAML format. Includes path, interval, and metrics enablement. ```yaml loader: type: file # path to the file path: ./targets-config.yaml # watch interval at which the file # is read again to determine if a target was added or deleted. interval: 30s # if true, registers fileLoader prometheus metrics with the provided # prometheus registry enable-metrics: false ``` -------------------------------- ### Remote HTTP File Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of configuring the file loader for a remote HTTP file. Includes path, interval, and metrics enablement. ```yaml loader: type: file # path to the file path: http://user:pass@server.com/path/to/targets-file.yaml # watch interval at which the file # is read again to determine if a target was added or deleted. interval: 30s # if true, registers fileLoader prometheus metrics with the provided # prometheus registry enable-metrics: false ``` -------------------------------- ### Simple Get RPC Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/get.md A basic example of sending a Get RPC request to retrieve data from a specified path. Ensure you replace `` with the actual target address. ```bash gnmic -a get --path "/state/port[port-id=*]" ``` -------------------------------- ### Remote SFTP File Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of configuring the file loader for a remote SFTP file. Includes path, interval, and metrics enablement. ```yaml loader: type: file # path to the file path: sftp://user:pass@server.com/path/to/targets-file.yaml # watch interval at which the file # is read again to determine if a target was added or deleted. interval: 30s # if true, registers fileLoader prometheus metrics with the provided # prometheus registry enable-metrics: false ``` -------------------------------- ### Targets File Format - YAML Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of a targets file in YAML format, defining target IP addresses and their configurations. ```yaml 10.10.10.10: username: admin insecure: true 10.10.10.11: username: admin 10.10.10.12: 10.10.10.13: 10.10.10.14: ``` -------------------------------- ### Start gNMI Prompt with Juniper Models Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/prompt_suggestions.md Start gNMI and generate path suggestions for Juniper MX configuration tree. ```bash gnmic --file junos/conf --dir common prompt ``` -------------------------------- ### ProtoJSON Output Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/output_intro.md Example of data formatted in protojson for file or NATS/STAN/Kafka outputs. ```json { "update": { "timestamp": "1595491618677407414", "prefix": { "elem": [ { "name": "configure" }, { "name": "system" } ] }, "update": [ { "path": { "elem": [ { "name": "name" } ] }, "val": { "stringVal": "sr123" } } } ] } } ``` -------------------------------- ### Start gNMI Prompt with Nokia YANG Models Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/prompt_suggestions.md Start gNMI in prompt mode and load Nokia YANG modules for path auto-suggestions. ```bash gnmic --file YANG/nokia-combined \ --dir YANG \ prompt ``` -------------------------------- ### Event Output Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/output_intro.md Example of data formatted as an event for file, NATS/STAN, or Kafka outputs. ```json [ { "name": "sub1", "timestamp": 1595491586073072000, "tags": { "source": "172.17.0.100:57400", "subscription-name": "sub1" } "values": { "/configure/system/name": "sr123" } } ] ``` -------------------------------- ### ProtoText Output Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/output_intro.md Example of data formatted in prototext for file or NATS/STAN/Kafka outputs. ```yaml update: { timestamp: 1595491704850352047 prefix: { elem: { name: "configure" } elem: { name: "system" } } update: { path: { elem: { name: "name" } } val: { string_val: "sr123" } } } ``` -------------------------------- ### Targets File Format - JSON Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of a targets file in JSON format, defining target IP addresses and their configurations. ```json { "10.10.10.10": { "username": "admin", "insecure": true }, "10.10.10.11": { "username": "admin", }, "10.10.10.12": {}, "10.10.10.13": {}, "10.10.10.14": {} } ``` -------------------------------- ### Remote FTP File Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/target_discovery/file_discovery.md Example of configuring the file loader for a remote FTP file. Includes path, interval, and metrics enablement. ```yaml loader: type: file # path to the file path: ftp://user:pass@server.com/path/to/targets-file.yaml # watch interval at which the file # is read again to determine if a target was added or deleted. interval: 30s # if true, registers fileLoader prometheus metrics with the provided # prometheus registry enable-metrics: false ``` -------------------------------- ### XPATH Path Example Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/path.md Displays a path in XPATH format. ```bash /state/sfm[sfm-slot=*]/hardware-data/firmware-revision-status ``` -------------------------------- ### gnmic Docker Compose Example Source: https://github.com/openconfig/gnmic/blob/main/docs/install.md A Docker Compose configuration file example for running gnmic, mounting a configuration file and setting up a network. ```yaml version: '2' networks: gnmic-net: driver: bridge services: gnmic-1: image: ghcr.io/openconfig/gnmic:latest container_name: gnmic-1 networks: - gnmic-net volumes: - ./gnmic.yaml:/app/gnmic.yaml command: "subscribe --config /app/gnmic.yaml" ``` -------------------------------- ### Start gNMI Prompt with OpenConfig Models Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/prompt_suggestions.md Start gNMI in prompt mode with OpenConfig models, excluding the ietf-interfaces module. ```bash gnmic --file release/models \ --dir third_party \ --exclude ietf-interfaces \ prompt ``` -------------------------------- ### JSON Output Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/output_intro.md Example of data formatted in JSON for file, NATS/STAN/Kafka, or UDP/TCP outputs. ```json { "source": "172.17.0.100:57400", "subscription-name": "sub1", "timestamp": 1595491557144228652, "time": "2020-07-23T16:05:57.144228652+08:00", "prefix": "configure/system", "updates": [ { "Path": "name", "values": { "name": "sr123" } } ] } ``` -------------------------------- ### Event jq processor configuration example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/event_processors/event_jq.md This is a configuration example for the event-jq processor. It shows the placement of the 'condition' and 'expression' fields within the processor configuration. ```yaml processors: # processor name sample-processor: # processor type event-jq: # condition of application of the processor condition: # jq expression to transform/filter/enrich the message expression: # boolean enabling extra logging debug: ``` -------------------------------- ### InfluxDB Target Template Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/influxdb_output.md This GoTemplate example shows how to customize the target field in InfluxDB when using the `add-target` option. It prioritizes the `subscription-target` if available, otherwise it defaults to the source host. ```go-template {{- if index . "subscription-target" -}} {{ index . "subscription-target" }} {{- else -}} {{ index . "source" | host }} {{- end -}} ``` -------------------------------- ### OTLP Output Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/otlp_output.md Define an OTLP output in the gnmic configuration file. This example shows various settings for endpoint, protocol, TLS, batching, and metric naming. ```yaml outputs: output1: # required type: otlp # required, address of the OTLP collector endpoint: localhost:4317 # string, transport protocol. Only "grpc" is supported. # defaults to "grpc" protocol: grpc # duration, defaults to 10s. # RPC timeout for each export request. timeout: 10s # tls config tls: # string, path to the CA certificate file, # this will be used to verify the server certificate when `skip-verify` is false ca-file: # string, client certificate file. cert-file: # string, client key file. key-file: # boolean, if true, the client will not verify the server # certificate against the available certificate chain. skip-verify: false # integer, defaults to 1000. # number of events to buffer before sending a batch to the collector. # events are sent every `interval` or when the batch is full, whichever comes first. batch-size: 1000 # duration, defaults to 5s. # time interval between export requests. interval: 5s # integer, defaults to 2x batch-size. # size of the internal event buffer. buffer-size: 2000 # integer, defaults to 3. # number of retries per export request on failure. max-retries: 3 # string, to be used as the metric namespace metric-prefix: "" # boolean, if true the subscription name will be prepended to the metric name after the prefix. append-subscription-name: false # boolean, if true, string type values are exported as gauge metrics with value=1 # and the string stored as an attribute named "value". # if false, string values are dropped. strings-as-attributes: false # boolean, defaults to false. # if true, the leading "/" on the gNMI path is stripped before "/" -> "_" conversion, # so metric names do not start with "_" (see Metric naming below). strip-leading-underscore: false # list of tag keys to place as OTLP Resource attributes. # these tags are excluded from data point attributes. # defaults to empty (all tags become data point attributes). resource-tag-keys: # - device # - vendor # - model # - site # - source # list of regex patterns matched against the value key (metric path). # if any pattern matches, the metric is exported as a monotonic cumulative Sum (counter). # unmatched metrics are exported as Gauges. # defaults to empty (all metrics are Gauges). counter-patterns: # - "counter" # - "octets|packets|bytes" # - "errors|discards|drops" # map of string:string, additional static attributes to add to the OTLP Resource. resource-attributes: # key: value # map of string:string, HTTP headers (or gRPC metadata) to include with every export request. # Use this to set tenant/org identifiers required by multi-tenant backends such as # Grafana Mimir, Loki, or Tempo. headers: # X-Scope-OrgID: my-tenant # integer, defaults to 1. # number of workers processing events. num-workers: 1 # boolean, defaults to false. # enables debug logging. debug: false # boolean, defaults to false. # enables the collection and export (via prometheus) of output specific metrics. enable-metrics: false # list of processors to apply on the message before writing event-processors: ``` -------------------------------- ### gNMI Path Example Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/path.md Displays a path formatted according to gNMI Path Conventions. ```bash elem:{name:"state"} elem:{name:"sfm" key:{key:"sfm-slot" value:"*"}} elem:{name:"hardware-data"} elem:{name:"firmware-revision-status"} ``` -------------------------------- ### Get All Configured Inputs Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/configuration.md Retrieves all configured inputs. The response is returned in JSON format. ```APIDOC ## GET /api/v1/config/inputs ### Description Request all the configured inputs. ### Method GET ### Endpoint /api/v1/config/inputs ### Response #### Success Response (200) Returns the outputs configuration as json ``` -------------------------------- ### Example Output of diff set-to-notifs Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/diff/diff_set_to_notifs.md This example shows the output format of the `diff set-to-notifs` command, indicating additions ('+') and removals ('-') of gNMI paths and values when comparing a SetRequest against device notifications. It highlights differences in specific paths and values. ```text SetToNotifsDiff(-want/SetRequest, +got/Notifications): - /lacp/interfaces/interface[name=Port-Channel9]/config/interval: "FAST" - /lacp/interfaces/interface[name=Port-Channel9]/config/name: "Port-Channel9" - /lacp/interfaces/interface[name=Port-Channel9]/name: "Port-Channel9" - /network-instances/network-instance[name=VrfBlue]/config/name: "VrfBlue" - /network-instances/network-instance[name=VrfBlue]/config/type: "openconfig-network-instance-types:L3VRF" - /network-instances/network-instance[name=VrfBlue]/name: "VrfBlue" m /system/config/hostname: - "violetsareblue" + "rosesarered" ``` -------------------------------- ### Get All Configured Outputs Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/configuration.md Retrieves all configured outputs. The response is returned in JSON format. ```APIDOC ## GET /api/v1/config/outputs ### Description Request all the configured outputs. ### Method GET ### Endpoint /api/v1/config/outputs ### Response #### Success Response (200) Returns the outputs configuration as json ``` -------------------------------- ### Run gnmic Get Command using Docker Source: https://github.com/openconfig/gnmic/blob/main/docs/install.md Example of running a gnmic 'get' command using the Docker image, connecting to a router with specified credentials and insecure mode. ```bash docker run \ --network host \ --rm ghcr.io/openconfig/gnmic get --log --username admin --password admin --insecure --address router1.local --path /interfaces ``` -------------------------------- ### Example Response: All Targets (200 OK) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/targets.md A successful response to the list all targets request, showing details for multiple targets including their configuration and subscriptions. ```json { "192.168.1.131:57400": { "config": { "name": "192.168.1.131:57400", "address": "192.168.1.131:57400", "username": "admin", "password": "****", "timeout": 10000000000, "insecure": true, "skip-verify": false, "buffer-size": 1000, "retry-timer": 10000000000 }, "subscriptions": { "sub1": { "name": "sub1", "paths": [ "/interface/statistics" ], "mode": "stream", "stream-mode": "sample", "encoding": "json_ietf", "sample-interval": 1000000000 } } }, "192.168.1.131:57401": { "config": { "name": "192.168.1.131:57401", "address": "192.168.1.131:57401", "username": "admin", "password": "****", "timeout": 10000000000, "insecure": true, "skip-verify": false, "buffer-size": 1000, "retry-timer": 10000000000 }, "subscriptions": { "sub1": { "name": "sub1", "paths": [ "/interface/statistics" ], "mode": "stream", "stream-mode": "sample", "encoding": "json_ietf", "sample-interval": 1000000000 } } } } ``` -------------------------------- ### Build the event-add-hostname plugin Source: https://github.com/openconfig/gnmic/blob/main/examples/plugins/event-add-hostname/README.md Build the plugin executable from the source code. Ensure you are in the plugin's directory. ```bash cd examples/plugins/event-add-hostname go build -o event-add-hostname ``` -------------------------------- ### Get RPC with origin and path Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/get.md Specify the origin and path for the Get RPC request using the format `"origin:path"`. Ensure the path starts with a `/` after the origin value. ```bash gnmic -a --insecure \ get --path "openconfig-interfaces:/interfaces/interface" ``` -------------------------------- ### gNMI Get Request with Tunnel Server Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/tunnel_server.md Execute a gNMI Get RPC using the tunnel server. gNMIc waits for targets to register before initiating the RPC. This example demonstrates fetching system name from registered targets. ```bash $ gnmic --config tunnel_server_config.yaml \ --use-tunnel-server \ get \ --path /configure/system/name 2022/03/09 10:12:34.729037 [gnmic] version=dev, commit=none, date=unknown, gitURL=, docs=https://gnmic.openconfig.net 2022/03/09 10:12:34.729063 [gnmic] using config file "tunnel_server_config.yaml" 2022/03/09 10:12:34.730472 [gnmic] waiting for targets to register with the tunnel server... 2022/03/09 10:12:36.435521 [gnmic] tunnel server discovered target {ID:sr1 Type:GNMI_GNOI} 2022/03/09 10:12:36.436332 [gnmic] tunnel server discovered target {ID:sr2 Type:GNMI_GNOI} 2022/03/09 10:12:36.731125 [gnmic] adding target {"name":"sr1","address":"sr1","username":"admin","password":"NokiaSrl1!","timeout":10000000000,"insecure":true,"skip-verify":false,"subscriptions":["sub1"],"retry-timer":10000000000,"log-tls-secret":false,"gzip":false,"token":""} 2022/03/09 10:12:36.731158 [gnmic] adding target {"name":"sr2","address":"sr2","username":"admin","password":"NokiaSrl1!","timeout":10000000000,"insecure":true,"skip-verify":false,"subscriptions":["sub1"],"retry-timer":10000000000,"log-tls-secret":false,"gzip":false,"token":""} 2022/03/09 10:12:36.731651 [gnmic] sending gNMI GetRequest: prefix='', path='[elem:{name:"configure"} elem:{name:"system"} elem:{name:"name"}]', type='ALL', encoding='JSON', models='[]', extension='[]' to sr1 2022/03/09 10:12:36.731742 [gnmic] sending gNMI GetRequest: prefix='', path='[elem:{name:"configure"} elem:{name:"system"} elem:{name:"name"}]', type='ALL', encoding='JSON', models='[]', extension='[]' to sr2 2022/03/09 10:12:36.732337 [gnmic] dialing tunnel connection for tunnel target "sr2" 2022/03/09 10:12:36.732572 [gnmic] dialing tunnel connection for tunnel target "sr1" [sr1] [ [sr1] { [sr1] "source": "sr1", [sr1] "timestamp": 1646849561604621769, [sr1] "time": "2022-03-09T10:12:41.604621769-08:00", [sr1] "updates": [ [sr1] { [sr1] "Path": "configure/system/name", [sr1] "values": { [sr1] "configure/system/name": "sr1" [sr1] } [sr1] } [sr1] ] [sr1] } [sr1] ] [sr2] [ [sr2] { [sr2] "source": "sr2", [sr2] "timestamp": 1646849562004804732, [sr2] "time": "2022-03-09T10:12:42.004804732-08:00", [sr2] "updates": [ [sr2] { [sr2] "Path": "configure/system/name", [sr2] "values": { [sr2] "configure/system/name": "sr2" [sr2] } [sr2] } [sr2] ] [sr2] } [sr2] ] ``` -------------------------------- ### gNMIc Configuration for Asciigraph Output Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/asciigraph_output.md Example gNMIc configuration demonstrating the use of the 'asciigraph' output type with a 'rate' event processor. This setup collects interface statistics and calculates their rates. ```yaml targets: clab-nfd33-spine1-1: username: admin password: NokiaSrl1! skip-verify: true subscriptions: sub1: paths: - /interface[name=ethernet-1/3]/statistics/out-octets - /interface[name=ethernet-1/3]/statistics/in-octets stream-mode: sample sample-interval: 1s encoding: ascii outputs: out1: type: asciigraph caption: in/out octets per second event-processors: - rate processors: rate: event-starlark: script: rate.star ``` -------------------------------- ### Default Configuration File Search Paths Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/configuration_intro.md This example shows the default search paths for gnmic configuration files. It also demonstrates how to specify a custom configuration file using the --config flag. ```bash # config file default path is : # $PWD/.gnmic.[yml, toml, json], or # $HOME/.gnmic.[yml, toml, json], or # $XDG_CONFIG_HOME/.gnmic.[yml, toml, json], or # $XDG_CONFIG_HOME/gnmic/.gnmic.[yml, toml, json] gnmic capabilities # read `cfg.yml` file located in the current directory gnmic --config ./cfg.yml capabilities ``` -------------------------------- ### gNMIc Configuration with Local Flags Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/configuration_file.md This YAML example illustrates how to include local flags, such as the 'path' for the 'get' command, within a gNMIc configuration file. Local flags are prefixed with the command name. ```yaml address: "router.lab:57400" username: admin password: NokiaSrl1! insecure: true get-path: /configure/system/name # `get` command local flag ``` -------------------------------- ### STAN Input Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/inputs/stan_input.md This YAML configuration defines a STAN input for gnmic. It specifies connection details, subject, queue group, authentication, and message format. Adjust parameters like `address`, `subject`, and `format` based on your STAN setup. ```yaml inputs: input1: # string, required, specifies the type of input type: stan # STAN subscriber name # If left empty, it will be populated with the string from flag --instance-name appended with `--stan-sub`. # If --instance-name is also empty, a random name is generated in the format `gnmic-$uuid` # note that each stan worker (subscriber) will get name=$name-$index name: "" # string, comma separated STAN servers addresses address: localhost:4222 # The subject name gnmic STAN consumers subscribe to. subject: telemetry # subscribe queue group all gnmic STAN input workers join, # so that STAN server can load share the messages between them. queue: # string, STAN username username: # string, STAN password password: # duration, wait time before reconnection attempts connect-time-wait: 2s # string, the STAN cluster name. defaults to test-cluster cluster-name: # integer, interval (in seconds) at which # a connection sends a PING to the server. min=1 ping-interval: # integer, number of PINGs without a response # before the connection is considered lost. min=2 ping-retry: # string, consumed message expected format, one of: proto, event format: event # bool, enables extra logging debug: false # integer, number of stan consumers to be created num-workers: 1 # list of processors to apply on the message when received, # only applies if format is 'event' event-processors: # []string, list of named outputs to export data to. # Must be configured under root level `outputs` section outputs: ``` -------------------------------- ### List Subscription Configurations Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/collector/collector_api.md Returns a list of all configured subscription definitions. Use this to view the current setup of all subscriptions. ```bash GET /api/v1/config/subscriptions ``` -------------------------------- ### Install gnmic CLI Source: https://github.com/openconfig/gnmic/blob/main/README.md Installs the gnmic CLI tool. Ensure you have curl installed. ```bash bash -c "$(curl -sL https://get-gnmic.openconfig.net)" ``` -------------------------------- ### Install Specific gnmic Version (Linux/Mac OS) Source: https://github.com/openconfig/gnmic/blob/main/docs/install.md Installs a specific version of gnmic by providing the version number with the -v flag to the installation script. ```bash bash -c "$(curl -sL https://get-gnmic.openconfig.net)" -- -v 0.5.0 ``` -------------------------------- ### Streaming Subscription with Target-Defined Interval Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/subscribe.md This example demonstrates a basic streaming subscription where the sample interval is defined within the target's configuration. Use this for continuous data retrieval at a predefined rate. ```bash gnmic -a sub --path /state/port[port-id=*]/statistics ``` -------------------------------- ### Build the event-gnmi-get plugin Source: https://github.com/openconfig/gnmic/blob/main/examples/plugins/event-gnmi-get/README.md Navigate to the plugin directory and build the executable using go build. ```bash cd examples/plugins/event-gnmi-get go build -o event-gnmi-get ``` -------------------------------- ### Example Response: No Targets Found (404 Not Found) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/targets.md This response indicates that no active targets were found matching the query. ```json { "errors": [ "no targets found" ] } ``` -------------------------------- ### Install gnmic using Packages (Linux) Source: https://github.com/openconfig/gnmic/blob/main/docs/install.md Installs gnmic using pre-built deb/rpm packages for Linux distributions that support them. ```bash bash -c "$(curl -sL https://get-gnmic.openconfig.net)" -- --use-pkg ``` -------------------------------- ### Example: Combining Processors with Conditional Subprocessors Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/event_processors/event_combine.md Demonstrates defining multiple regular processors and two event-combine processors. pipeline1 applies proc2 conditionally based on subscription, while pipeline2 also applies proc2 conditionally. ```yaml processors: proc1: event-allow: condition: '.tags.interface_name == "ethernet-1/1"' proc2: event-strings: value-names: - ".*" transforms: - path-base: apply-on: "name" proc3: event-convert: value-names: - ".*octets$" type: int pipeline1: event-combine: processors: - name: proc1 - condition: '.tags["subscription-name"] == "sub1"' name: proc2 - name: proc3 pipeline2: event-combine: processors: - condition: '.tags["subscription-name"] == "sub2"' name: proc2 - name: proc3 ``` -------------------------------- ### Start collector with Pyroscope profiling Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/collector.md Starts a gnmic collector with Pyroscope profiling enabled, specifying the server address and application name. ```bash gnmic --config collector.yaml collect \ --pyroscope-server-address http://pyroscope:4040 \ --pyroscope-application-name my-collector ``` -------------------------------- ### Single stream/sample subscription (Prototext) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/subscriptions.md Configure a single subscription for port statistics using sample stream mode with a 5-second interval and byte encoding in Prototext format. ```text subscribe: { subscription: { path: { elem: { name: "state" } elem: { name: "port" } elem: { name: "statistics" } } mode: SAMPLE sample_interval: 5000000000 } encoding: BYTES } ``` -------------------------------- ### Enable API Server via Command Line Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/api_intro.md Use this command-line flag to enable the API server and specify the listening address and port. ```bash gnmic --config gnmic.yaml subscribe --api ":7890" ``` -------------------------------- ### Run gNMIc with the plugin Source: https://github.com/openconfig/gnmic/blob/main/examples/plugins/event-gnmi-get/README.md Configure gNMIc to load the plugin binary from a specified path. ```bash gnmic --config gnmic.yaml subscribe -P /path/to/plugin/bin ``` -------------------------------- ### ONCE subscription (Prototext) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/subscriptions.md Configure subscriptions for system name and version to be retrieved once, using byte encoding in Prototext format. ```text subscribe: { subscription: { path: { elem: { name: "configure" } elem: { name: "port" } elem: { name: "name" } } } subscription: { path: { elem: { name: "state" } elem: { name: "system" } elem: { name: "version" } } } mode: ONCE encoding: BYTES } ``` -------------------------------- ### Full gNMI Command with Nokia Target Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/prompt_suggestions.md Example of a full gNMI command including target details and prompt mode with Nokia YANG models. ```bash gnmic --address 10.1.0.11 --insecure --username admin --password admin \ prompt \ --file ~/7x50_YangModels/YANG/nokia-combined \ --dir ~/7x50_YangModels/YANG ``` -------------------------------- ### Once Subscription Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/subscribe.md This command sets up a subscription that retrieves data only once. Use this for fetching a snapshot of data at a specific point in time. ```bash gnmic -a sub --path "/state/port[port-id=*]/statistics" \ --mode once ``` -------------------------------- ### Configure processor to trigger Get request directly Source: https://github.com/openconfig/gnmic/blob/main/examples/plugins/event-gnmi-get/README.md This configuration defines the event-gnmi-get processor to directly trigger gNMI Get requests to the target node. ```yaml processors: proc1: event-gnmi-get: debug: true encoding: ascii data-type: all paths: - path: "platform/chassis/type" tag-name: "chassis-type" - path: "platform/chassis/hw-mac-address" tag-name: "hw-mac-address" - path: "system/name/host-name" tag-name: "hostname" ``` -------------------------------- ### Deploy Containerlab with gNMIc and Multiple Outputs Source: https://github.com/openconfig/gnmic/blob/main/docs/deployments/single-instance/containerlab/multiple-outputs.md Use this command to deploy the Containerlab topology. Ensure you are in the deployment directory. ```bash git clone https://github.com/openconfig/gnmic.git cd gnmic/examples/deployments/1.single-instance/5.multiple-outputs/containerlab sudo clab deploy -t multiple-outputs.clab.yaml ``` -------------------------------- ### gNMI Get RPC to All Targets Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/tunnel_server.md Execute a gNMI Get RPC to retrieve system name from all registered targets. This command targets the gNMI server running on gNMIc. ```bash $ gnmic -a localhost:57400 --insecure get \ --path /configure/system/name ``` -------------------------------- ### Enter Interactive Navigation Prompt Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/path.md Launches the interactive navigation prompt for exploring paths within a YANG file. ```bash gnmic path --file nokia-state-combined.yang --search ``` -------------------------------- ### Get gNMI Data Source: https://github.com/openconfig/gnmic/blob/main/docs/basic_usage.md Retrieve a snapshot of data from the target device using the `get` command with a specified path. The output is a JSON object containing the requested data. ```bash gnmic -a 10.1.0.11:57400 -u admin -p admin --insecure \ get --path /state/system/platform ``` -------------------------------- ### Streaming Subscription with On-Change Mode and Heartbeat Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/subscribe.md This example configures a streaming subscription to receive updates only when data changes, with a specified heartbeat interval. Use this for efficient monitoring of dynamic data. ```bash gnmic -a sub --path "/state/port[port-id=*]/statistics" \ --stream-mode on-change \ --heartbeat-interval 1m ``` -------------------------------- ### Start gnmic server with TLS disabled Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/listen.md Use this command to start gnmic as a server listening on all interfaces without TLS support. Ensure the address and port are correctly specified. ```bash gnmic listen -a 0.0.0.0:57400 ``` -------------------------------- ### Configure Plugin Binary Path and Glob Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/event_processors/event_plugin.md Specifies the directory to load plugin binaries from and a glob pattern to match them. The start-timeout sets a limit for plugin initialization. ```yaml plugins: # path to load plugin binaries from. path: /path/to/plugin/bin # glob to match binaries against. glob: "*" # sets a start timeout for plugins. start-timeout: 0s ``` -------------------------------- ### Get System Name from Multiple Targets Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/targets/targets.md Demonstrates using the `get` command to retrieve the system name from two different routers. The output is prefixed with the target address for clarity. ```shell ❯ gnmic -a router1.lab.net:57400 \ -a router2.lab.net:57400 \ get --path /configure/system/name [router1.lab.net:57400] { [router1.lab.net:57400] "source": "router1.lab.net:57400", [router1.lab.net:57400] "timestamp": 1593009759618786781, [router1.lab.net:57400] "time": "2020-06-24T16:42:39.618786781+02:00", [router1.lab.net:57400] "updates": [ [router1.lab.net:57400] { [router1.lab.net:57400] "Path": "configure/system/name", [router1.lab.net:57400] "values": { [router1.lab.net:57400] "configure/system/name": "gnmic_r1" [router1.lab.net:57400] } [router1.lab.net:57400] } [router1.lab.net:57400] ] [router1.lab.net:57400] } [router2.lab.net:57400] { [router2.lab.net:57400] "source": "router2.lab.net:57400", [router2.lab.net:57400] "timestamp": 1593009759748265232, [router2.lab.net:57400] "time": "2020-06-24T16:42:39.748265232+02:00", [router2.lab.net:57400] "updates": [ [router2.lab.net:57400] { [router2.lab.net:57400] "Path": "configure/system/name", [router2.lab.net:57400] "values": { [router2.lab.net:57400] "configure/system/name": "gnmic_r2" [router2.lab.net:57400] } [router2.lab.net:57400] } [router2.lab.net:57400] ] [router2.lab.net:57400] } ``` -------------------------------- ### Example Response: Single Target (200 OK) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/api/targets.md A successful response for a single target query, detailing its configuration and active subscriptions. ```json { "config": { "name": "192.168.1.131:57400", "address": "192.168.1.131:57400", "username": "admin", "password": "****", "timeout": 10000000000, "insecure": true, "skip-verify": false, "buffer-size": 1000, "retry-timer": 10000000000 }, "subscriptions": { "sub1": { "name": "sub1", "paths": [ "/interface/statistics" ], "mode": "stream", "stream-mode": "sample", "encoding": "json_ietf", "sample-interval": 1000000000 } } } ``` -------------------------------- ### gNMI Get RPC for Multiple Targets Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/gnmi_server.md Use this command to retrieve data from multiple specified targets using the gNMI Get RPC. The targets are provided as a comma-separated list. ```bash gnmic -a gnmic-server:57400 get --path /interfaces \ --target router1,router2,router3 ``` -------------------------------- ### Deploy Containerlab with NATS Output Source: https://github.com/openconfig/gnmic/blob/main/docs/deployments/single-instance/containerlab/nats-output.md Clone the repository, navigate to the deployment directory, and deploy the Containerlab topology using the provided command. This sets up the gNMI instance, NATS server, and SR Linux nodes. ```bash git clone https://github.com/openconfig/gnmic.git cd gnmic/examples/deployments/1.single-instance/1.nats-output/containerlab sudo clab deploy -t nats.clab.yaml ``` -------------------------------- ### ONCE subscription (CLI) Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/subscriptions.md Use the gnmic CLI to subscribe to system name and version in once mode with byte encoding. ```shell gnmic sub --path /configure/system/name \ --path /state/system/version \ --mode once \ --encoding bytes ``` -------------------------------- ### Generated YAML Configuration Payload Example Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/generate.md An example of a YAML configuration payload generated by the `gnmic generate` command for the specified path. This payload can be used with the `gnmic set` command for updates or replacements. ```yaml - config: ip: "" prefix-length: "" ip: "" vrrp: vrrp-group: - config: accept-mode: "false" advertisement-interval: "100" preempt: "true" preempt-delay: "0" priority: "100" virtual-address: "" virtual-router-id: "" interface-tracking: config: priority-decrement: "0" track-interface: "" virtual-router-id: "" ``` -------------------------------- ### gNMI Get RPC Target Output Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/outputs/gnmi_output.md This JSON represents the output received from a gNMI Get RPC when querying for targets. It includes details like address, username, and security settings for each target. ```json [ { "timestamp": 1626759382486891218, "time": "2021-07-20T13:36:22.486891218+08:00", "prefix": "gnmic:targets[name=clab-gw-srl1:57400]", "updates": [ { "Path": "address", "values": { "address": "clab-gw-srl1:57400" } }, { "Path": "username", "values": { "username": "admin" } }, { "Path": "insecure", "values": { "insecure": "false" } }, { "Path": "skip-verify", "values": { "skip-verify": "true" } }, { "Path": "timeout", "values": { "timeout": "10s" } } ] }, { "timestamp": 1626759382486900697, "time": "2021-07-20T13:36:22.486900697+08:00", "prefix": "gnmic:targets[name=clab-gw-srl2:57400]", "updates": [ { "Path": "address", "values": { "address": "clab-gw-srl2:57400" } }, { "Path": "username", "values": { "username": "admin" } }, { "Path": "insecure", "values": { "insecure": "false" } }, { "Path": "skip-verify", "values": { "skip-verify": "true" } }, { "Path": "timeout", "values": { "timeout": "10s" } } ] } ] ``` -------------------------------- ### Deploy Containerlab with Kafka Output Source: https://github.com/openconfig/gnmic/blob/main/docs/deployments/single-instance/containerlab/kafka-output.md Use this command to deploy the Containerlab environment, including gNMI and Kafka. ```bash git clone https://github.com/openconfig/gnmic.git cd gnmic/examples/deployments/1.single-instance/2.kafka-output/containerlab sudo clab deploy -t kafka.clab.yaml ``` -------------------------------- ### gNMI Get RPC for Internal Configuration Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/gnmi_server.md Retrieve internal gNMIc server configuration using the Get RPC. This is applicable for paths like 'targets' and 'subscriptions' when the Origin field is set to 'gnmic'. ```bash gnmic -a gnmic-server:57400 get --path gnmic:/targets ``` ```bash gnmic -a gnmic-server:57400 get --path gnmic:/subscriptions ``` -------------------------------- ### Compare multiple paths with Get RPC Source: https://github.com/openconfig/gnmic/blob/main/docs/cmd/diff/diff.md Compares specified paths across multiple targets using the Get RPC. Multiple --path flags can be used to specify different data sets. ```bash gnmic --insecure \ --ref router1 \ --compare router2,router3 \ diff --path "/state/ports[port-id=*]" \ --path "/state/router[router-name=*]/interface[interface-name=*]" ``` -------------------------------- ### Complete Collector Configuration Example Source: https://github.com/openconfig/gnmic/blob/main/docs/user_guide/collector/collector_configuration.md A comprehensive example of the gNMI collector configuration, including API server, clustering, gNMI server, tunnel server, tunnel target matches, targets, subscriptions, outputs, and processors. ```yaml # API server (required) api-server: address: :7890 timeout: 10s enable-metrics: true # Clustering (optional, for HA) clustering: cluster-name: production-cluster instance-name: collector-1 locker: type: consul address: consul.service.consul:8500 session-ttl: 10s # gNMI server gnmi-server: address: :57400 skip-verify: true cache: type: oc expiration: 60s # Tunnel server tunnel-server: address: :57401 # Tunnel target matches tunnel-target-matches: srl-devices: id: router1 type: "GNMI_GNOI" subscriptions: - interfaces outputs: - prometheus # Targets targets: spine1: address: 10.0.0.1:57400 username: admin password: admin skip-verify: true subscriptions: - interfaces - bgp outputs: - prometheus # Subscriptions subscriptions: interfaces: paths: - /interfaces/interface/state/counters mode: stream stream-mode: sample sample-interval: 10s bgp: paths: - /network-instances/network-instance/protocols/protocol/bgp mode: stream stream-mode: on-change # Outputs outputs: prometheus: type: prometheus listen: :9804 path: /metrics event-processors: - trim-prefixes # Processors processors: trim-prefixes: event-strings: value-names: - ".*" transforms: - trim-prefix: apply-on: name prefix: /interfaces/interface/state/ ```