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
3 changes: 2 additions & 1 deletion 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 "host" not in prometheus_sd_config
):
continue

Expand All @@ -50,8 +51,8 @@ def to_representation(self, data):

class PrometheusTargetsMixin:
def get_targets(self, obj):
target = obj.name
prometheus_sd_config = getattr(obj, "_injected_prometheus_sd_config", {})
target = prometheus_sd_config.get("host", obj.name)

port = prometheus_sd_config.get("port", None)
if port and isinstance(port, int):
Expand Down
4 changes: 2 additions & 2 deletions netbox_prometheus_sd/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_endpoint_virtual_machine(self):

self.assertIsNotNone(data[0]["targets"])
self.assertIsNotNone(data[0]["labels"])
# Full vm contains two entry in the config context so we have to double the number of vm
self.assertEqual(len(data), 120)
# Full vm contains three entry in the config context so we have to triple the number of vm
self.assertEqual(len(data), 180)

def test_endpoint_ip_address(self):
"""Ensure ip address endpoint returns a valid response"""
Expand Down
2 changes: 2 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,8 @@ 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.assertEqual(data_list[2]["targets"], ["another.host.xyz:4244"])
for data in data_list:
self.assertTrue(
utils.dictContainsSubset(
Expand Down
1 change: 1 addition & 0 deletions netbox_prometheus_sd/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def build_vm_full(name, ip_octet=1):
"prometheus-plugin-prometheus-sd": [
{"metrics_path": "/not/metrics", "port": 4242, "scheme": "https"},
{"port": 4243},
{"host": f"another.host.xyz", "port": 4244},
]
},
)
Expand Down