You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a couple of problems with labels from a custom field, where the value it contains is a list. The example here is a custom field called "snmp_module" of type "multiple selection", linked to a choice set with strings.
Problem 1: the label value returned is a Python-style repr().
In order to get this into a simple comma-separated list (as required by snmp_exporter with multiple modules) I have to use a very ugly rewrite:
- source_labels: [__meta_netbox_custom_field_snmp_module]
target_label: __param_module
# Ugh: multiselect is of form ['foo', 'bar'] and we need foo,bar. There is no gsub.
- source_labels: [__param_module]
regex: "\\['(.*)'\\]"
target_label: __param_module
- source_labels: [__param_module]
regex: "(.*)', *'(.*)"
replacement: "$1,$2"
target_label: __param_module
- source_labels: [__param_module]
regex: "(.*)', *'(.*)"
replacement: "$1,$2"
target_label: __param_module
- source_labels: [__param_module]
regex: "(.*)', *'(.*)"
replacement: "$1,$2"
target_label: __param_module
... and this only works up to a fixed maximum number of values (4 here), as there's no "gsub" in prometheus rewriting.
Problem 2: when the custom field is unset the label gets the string value "None", whereas I would expect either empty string or the entire label to be omitted.
(This is minor: I could always match this value explicitly in a rewrite rule, and I'm unlikely to use "None" as a genuine choice value)
Proposal
For values of a multiple selection type, I'd like to see such a list returned as a plain comma-separated list of strings.
What about other types of custom field that might return a list? I can only see two that might make a difference:
JSON fields. These can stay as is. JSON is JSON, after all.
Multiple Object Selection. I haven't tested what these do today. Maybe simplest is to generate a comma-separated list of the str(...) representation of each object, so you get whatever the default display is. (I suppose it could also be a comma-separated list of object ID, or of slug for object classes which have slugs, but there's no obvious one-size-fits-all)
The question is whether the prometheus-sd plugin would have to dig into the definition of a custom field to determine whether it's JSON or not.
This issue has been automatically closed because it has been inactive for more than 60 days.
Please reopen if you still intend to submit this pull request.
Version
running under Netbox 3.7.4
Issues
I have a couple of problems with labels from a custom field, where the value it contains is a list. The example here is a custom field called "snmp_module" of type "multiple selection", linked to a choice set with strings.
Problem 1: the label value returned is a Python-style
repr()
.In order to get this into a simple comma-separated list (as required by snmp_exporter with multiple modules) I have to use a very ugly rewrite:
... and this only works up to a fixed maximum number of values (4 here), as there's no "gsub" in prometheus rewriting.
Problem 2: when the custom field is unset the label gets the string value
"None"
, whereas I would expect either empty string or the entire label to be omitted.(This is minor: I could always match this value explicitly in a rewrite rule, and I'm unlikely to use "None" as a genuine choice value)
Proposal
For values of a multiple selection type, I'd like to see such a list returned as a plain comma-separated list of strings.
What about other types of custom field that might return a list? I can only see two that might make a difference:
str(...)
representation of each object, so you get whatever the default display is. (I suppose it could also be a comma-separated list of object ID, or of slug for object classes which have slugs, but there's no obvious one-size-fits-all)The question is whether the prometheus-sd plugin would have to dig into the definition of a custom field to determine whether it's JSON or not.
References
Relates to #34, #65
The text was updated successfully, but these errors were encountered: