Skip to content

Commit

Permalink
Update serializers.py more info for circuits attached to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrichbaum authored Aug 17, 2024
1 parent 4f72f30 commit 9faf74f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions netbox_prometheus_sd/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,31 @@ class Meta:
def get_labels(self, obj):
firstip = ""
firstipmask = ""
cid = ""
circuit_desc = ""
provider = ""
if obj.count_ipaddresses > 0:
ipsplit = str(obj.ip_addresses.first()).split("/", 1)
firstip = ipsplit[0]
firstipmask = ipsplit[1]

# should always have link_peers but...
if hasattr(obj, "link_peers") and obj.link_peers is not None:
# may be device not circuit.
if len(obj.link_peers) > 0:
if hasattr(obj.link_peers[0], "circuit"):
cid = obj.link_peers[0].circuit.cid
circuit_desc = obj.link_peers[0].circuit.description
provider=Provider.objects.filter(id=obj.link_peers[0].circuit.provider_id).first().name

labels = LabelDict(
{
"id": str(obj.id),
"devicename": str(obj.device.name),
"deviceid": str(obj.device.id),
"circuit_desc": circuit_desc,
"circuit_cid": cid,
"circuit_provider": provider,
"ip_address": firstip,
"ip_mask": firstipmask
}
Expand Down

0 comments on commit 9faf74f

Please sign in to comment.