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

Fix dynamic label regex parsing behaviour #176

Merged
merged 5 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ Label value: 202739

### Custom Label RegEx

To override the default behavior a `interface_description_regex` can be supplied.
To override the default behavior a `interface_description_regex` can be supplied. This parameter can be given at a global level or per device. To use per-device regexes the target devices need to be defined in the exporter config. Per-device regex cannot be used in combination with `-config.ignore-targets`.

#### Example
The default regex `\[([^=\]]+)(=[^\]]+)?\]` would match interface descriptions like `"Description [foo] [bar=123]".
If we use `[[\s]([^=\[\]]+)(=[^,\]]+)?[,\]]` we can now match for `Description [foo, bar=123]` instead.
The default regex `\[([^=\]]+)(=[^\]]+)?\]` would match interface descriptions like `"Description [foo] [bar=123]"`.
If we use `[[\s]([^=\[\]]+)(=[^,\]]+)?[,\]]` we can now match for `"Description [foo, bar=123]"` instead.


### Grafana Dashboards
Expand Down
16 changes: 12 additions & 4 deletions junos_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ func newJunosCollector(devices []*connector.Device, connectionManager *connector

if *dynamicIfaceLabels {
regex := defaultIfDescReg
if cfg.Devices[index].IfDescReg != "" {
regex = regexp.MustCompile(cfg.Devices[index].IfDescReg)
} else if cfg.IfDescReg != "" {
regex = regexp.MustCompile(cfg.IfDescReg)
if cfg.IfDescReg != "" {
regex, err = regexp.Compile(cfg.IfDescReg)
if err != nil {
log.Errorf("Global dynamic label regex invalid: %s", cfg.IfDescReg)
regex = defaultIfDescReg
}
} else if !(*ignoreConfigTargets) && index < len(cfg.Devices) && cfg.Devices[index].IfDescReg != "" {
regex, err = regexp.Compile(cfg.Devices[index].IfDescReg)
if err != nil {
log.Errorf("Device specific dynamic label regex invalid: %s", cfg.Devices[index].IfDescReg)
regex = defaultIfDescReg
}
}

err = l.CollectDescriptions(d, cl, regex)
Expand Down