Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use FuncMap to help transform data from the log, inside a template? #185

Open
mad-ady opened this issue Dec 16, 2022 · 0 comments

Comments

@mad-ady
Copy link

mad-ady commented Dec 16, 2022

Hello - I'm parsing a log that has a HEX representation of an ASCII string somewhere in the line. For instance: thing=313241414242, which decoded results in thing=12AABB. I'd like to parse this string and report the decoded ASCII string back to prometheus as a label.

The grok configuration looks something like this:

- type: counter
          name: thing_counter
          help: Test thing counter
          match: 'thing=(?<thing_hex>[0-9A-F]+)'
          retention: 5m
          path: 'thing.log'
          labels:
            host: 'thing_host'
            thing: "{{- printf \"%s\"  (hex.DecodeString .thing_hex)  -}}"

I'm trying to use the DecodeString function from the hex package. However, when I try to start grok_exporter, it complains that:

Failed to load ...: invalid configuration: failed to read metric label thing_counter: error parsing thing template: template: thing:1: function "hex" not defined: don't forget to put a . (dot) in front of grok fields, otherwise it will be interpreted as a function.

I'm not skilled in go, nor its templating engine, but I learned I have to use FuncMap to pass the names of the functions that I need to the template. Any suggestions on how I can use FuncMap from within grok_exporter to be able to access hex.DecodeString?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant