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
6 changes: 3 additions & 3 deletions netbox_prometheus_sd/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Meta:
def get_labels(self, obj):
labels = LabelDict(
{
"status": obj.status,
"model": obj.__class__.__name__,
"name": obj.name,
"id": str(obj.id),
Expand All @@ -94,6 +93,7 @@ def get_labels(self, obj):
utils.extract_rack(obj, labels)
utils.extract_custom_fields(obj, labels)
utils.extract_rack_u_poistion(obj, labels)
utils.extract_status(obj, labels)

if hasattr(obj, "role") and obj.role is not None:
labels["role"] = obj.role.name
Expand Down Expand Up @@ -132,7 +132,6 @@ class Meta:
def get_labels(self, obj):
labels = LabelDict(
{
"status": obj.status,
"model": obj.__class__.__name__,
"name": obj.name,
"id": str(obj.id),
Expand All @@ -147,6 +146,7 @@ def get_labels(self, obj):
utils.extract_services(obj, labels)
utils.extract_contacts(obj, labels)
utils.extract_custom_fields(obj, labels)
utils.extract_status(obj, labels)

if hasattr(obj, "role") and obj.role is not None:
labels["role"] = obj.role.name
Expand Down Expand Up @@ -208,7 +208,6 @@ def get_labels(self, obj):
"""Get IP address labels"""
labels = LabelDict(
{
"status": obj.status,
"model": obj.__class__.__name__,
"ip": self.extract_ip(obj),
"id": str(obj.id),
Expand All @@ -217,6 +216,7 @@ def get_labels(self, obj):
if obj.role:
labels["role"] = obj.role

utils.extract_status(obj, labels)
utils.extract_tags(obj, labels)
utils.extract_tenant(obj, labels)
utils.extract_custom_fields(obj, labels)
Expand Down
6 changes: 6 additions & 0 deletions netbox_prometheus_sd/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def extract_parent(obj, labels: LabelDict):
extract_tenant(obj.parent, labels)
extract_cluster(obj.parent, labels)
extract_contacts(obj.parent, labels)
extract_status(obj.parent, labels)


def extract_service_ips(obj, labels: LabelDict):
Expand All @@ -190,3 +191,8 @@ def extract_rack_u_poistion(obj, labels: LabelDict):
"""Extract rack U poistion"""
if hasattr(obj, "position") and obj.position:
labels["rack_u_position"] = str(obj.position)

def extract_status(obj, labels: LabelDict):
"""Extract status"""
if hasattr(obj, "status") and obj.status is not None:
labels["status"] = obj.status
5 changes: 5 additions & 0 deletions netbox_prometheus_sd/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ def test_device_service_full_to_target(self):
{"__meta_netbox_primary_ip6": "2001:db8:1701::2"}, data["labels"]
)
)
self.assertTrue(
utils.dictContainsSubset(
{"__meta_netbox_status": "active"}, data["labels"]
)
)

def test_vm_service_full_to_target(self):
vm = utils.build_vm_full("vm-full-01.example.com")
Expand Down