Event Processor Not Applying Transformation as Expected
I am experiencing an issue with gNMIc where the configured event processor does not seem to apply the specified jq transformation. Despite a straightforward configuration aiming to test the processor functionality, the output remains unchanged from the input, suggesting that the processor might not be triggered or is not applying the transformation correctly.
Configuration Details:
username: cisco
password: cisco
port: 50051
timeout: 5s
skip-verify: false
tls-ca: ./ca.cert.pem
log-file: /tmp/gnmic.log
debug: true
targets:
192.168.2.104:
timeout: 2s
subscriptions:
- system-name
outputs:
- stdout
subscriptions:
system-name:
paths:
- "/System/name"
stream-mode: sample
sample-interval: 30s
encoding: json
outputs:
stdout:
type: file
file-type: stdout
event-processors:
- event-jq-processor
processors:
event-jq-processor:
event-jq:
expression: '.[] | {test: "output is working"}'
debug: true
Expected Output:
{"test": "output is working"}
Actual Output:
{
"source": "192.168.2.104",
"subscription-name": "system-name",
"timestamp": 1712973442344331082,
"time": "2024-04-13T01:57:22.344331082Z",
"updates": [
{
"Path": "device:System",
"values": {
"System": {
"name": "LEAF2"
}
}
}
]
}
Steps to Reproduce:
- Configure gnmic using the above YAML configuration.
- Execute the command gnmic --config gnmic.yaml subscribe.
- Observe the output, which should have been transformed by the event processor but remains unchanged.
Additional Information: gNMIc version: 0.36.2 Operating System: Ubuntu 22.04.4 LTS gnmic.log
Expected Behavior: The output should be transformed by the event-jq processor according to the specified expression, showing {"test": "output is working"} instead of the untransformed JSON data from the subscription.
Actual Behavior: The processor does not modify the output as expected. The raw data from the subscription is displayed instead of the transformed data.
Unfortunately that's not how event processors function:
- Processors apply only when the output format is set to
event, the default format isjson. - Processors should always output a list of event messages (you cannot create an arbitrary json object using them)
In your case, the processor is not being applied at all (
format: eventmissing) and even if you set the format it will result in an error because what it returns is not a list of event messages.
If your goal is to return an arbitrary message (json or other) you can use the field msg-template: under your file output. It takes a Gotemplate that rendered with each received message as input.
Hello! Can U put here some basic example of msg-template usage? Thank you!
I used TCP output to forward raw JSON and processed them with PyJQ. Works great. Thank you 🙂
Hello! Can U put here some basic example of msg-template usage? Thank you!
subscriptions:
sub1:
paths:
- /interface/statistics
outputs:
out1:
type: file
format: event
msg-template: |
{{range .}}
{{if index .values "/interface/statistics/in-octets"}}
Name: {{.name}}
Interface Name: {{(index .tags "interface_name")}}
Source: {{(index .tags "source")}}
Subscription Name: {{(index .tags "subscription-name")}}
InOctets: {{ index .values "/interface/statistics/in-octets" }}
{{- end}}
{{- end}}
This should print:
Name: sub1
Interface Name: ethernet-1/1
Source: $YOUR_ROUTER_NAME
Subscription Name: sub1
InOctets: 3857
Hello! Can U put here some basic example of msg-template usage? Thank you!
subscriptions: sub1: paths: - /interface/statistics outputs: out1: type: file format: event msg-template: | {{range .}} {{if index .values "/interface/statistics/in-octets"}} Name: {{.name}} Interface Name: {{(index .tags "interface_name")}} Source: {{(index .tags "source")}} Subscription Name: {{(index .tags "subscription-name")}} InOctets: {{ index .values "/interface/statistics/in-octets" }} {{- end}} {{- end}}This should print:
Name: sub1 Interface Name: ethernet-1/1 Source: $YOUR_ROUTER_NAME Subscription Name: sub1 InOctets: 3857
Thanks a lot! And a small clarification - does the template supports gotemplate functions, string processing, for example? https://docs.gomplate.ca/functions/strings/ Thanks again!
Yes all gomplate functions are imported