Skip to content

Commit

Permalink
adding the ability to get the rack U position and feed it into labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-nscale authored and FlxPeters committed Jul 31, 2024
1 parent d05857f commit ba9ea5b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions netbox_prometheus_sd/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get_labels(self, obj):
utils.extract_contacts(obj, labels)
utils.extract_rack(obj, labels)
utils.extract_custom_fields(obj, labels)
utils.extract_rack_u_poistion(obj, labels)

This comment has been minimized.

Copy link
@candlerb

candlerb Oct 5, 2024

Contributor

s/poistion/position/ (also in the function definition in api/utils.py)


if hasattr(obj, "role") and obj.role is not None:
labels["role"] = obj.role.name
Expand Down
5 changes: 5 additions & 0 deletions netbox_prometheus_sd/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,8 @@ def extract_service_ports(obj, labels: LabelDict):
and len(obj.ports)
):
labels["ports"] = ",".join([str(port) for port in obj.ports])

def extract_rack_u_poistion(obj, labels: LabelDict):
"""Extract rack U poistion"""
if hasattr(obj, "position") and obj.position:
labels["rack_u_position"] = obj.position
3 changes: 3 additions & 0 deletions netbox_prometheus_sd/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def test_device_full_to_target(self):
self.assertDictContainsSubset(
{"__meta_netbox_custom_field_simple": "Foobar 123"}, data["labels"]
)
self.assertDictContainsSubset(
{"__meta_netbox_rack_u_position": "1.0"}, data["labels"]
)


class PrometheusIPAddressSerializerTests(TestCase):
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 @@ -191,7 +191,7 @@ def build_device_full(name, ip_octet=1):
device.tags.add("Tag1")
device.tags.add("Tag 2")
device.save()

device.position = "1.0"
Service.objects.create(device=device, name="ssh", protocol='tcp', ports=[22])
return device

Expand Down

0 comments on commit ba9ea5b

Please sign in to comment.