Skip to content
Open
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
1 change: 1 addition & 0 deletions netbox_prometheus_sd/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def to_representation(self, data):
"port" not in prometheus_sd_config
and "metrics_path" not in prometheus_sd_config
and "scheme" not in prometheus_sd_config
and "params" not in prometheus_sd_config
):
continue

Expand Down
8 changes: 8 additions & 0 deletions netbox_prometheus_sd/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def extract_prometheus_sd_config(obj, labels):
if scheme and isinstance(scheme, str):
labels["__scheme__"] = scheme

params = prometheus_sd_config.get("params", None)
if params and isinstance(params, dict):
for key, value in params.items():
if isinstance(value, list):
labels[f"__param_{key}"] = ",".join(value)
else:
labels[f"__param_{key}"] = str(value)


def extract_parent(obj, labels: LabelDict):
labels["parent"] = obj.parent.name
Expand Down
8 changes: 8 additions & 0 deletions netbox_prometheus_sd/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_vm_full_to_target(self):
self.assertEqual(data_list[0]["targets"], ["vm-full-01.example.com:4242"])

self.assertEqual(data_list[1]["targets"], ["vm-full-01.example.com:4243"])
self.assertTrue(
utils.dictContainsSubset(
{
"__param_target": "other.host.xyz",
},
data_list[1]["labels"],
)
)
for data in data_list:
self.assertTrue(
utils.dictContainsSubset(
Expand Down
2 changes: 1 addition & 1 deletion netbox_prometheus_sd/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def build_vm_full(name, ip_octet=1):
data={
"prometheus-plugin-prometheus-sd": [
{"metrics_path": "/not/metrics", "port": 4242, "scheme": "https"},
{"port": 4243},
{"port": 4243, "params": {"target": "other.host.xyz"}},
]
},
)
Expand Down