Skip to content

Instantly share code, notes, and snippets.

@Paktosan
Created February 6, 2024 08:47
Show Gist options
  • Save Paktosan/57fade1a179f0cab5a8cefa12d13f7e8 to your computer and use it in GitHub Desktop.
Save Paktosan/57fade1a179f0cab5a8cefa12d13f7e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import pynetbox
import os
from datetime import date, timedelta
# These checks are sorted by priority. If a check matches, the cable will not be reported in further checks.
API_LOC = ""
API_TOKEN = ""
if __name__ == '__main__':
netbox = pynetbox.api(API_LOC, token=API_TOKEN)
processed_cords = []
# Dangle Check
if netbox.version >= '3.3.0':
cables = netbox.dcim.cables.filter(unterminated=True)
for cable in cables:
processed_cords.append(cable.id)
if len(cable.a_terminations) == 0 and len(cable.b_terminations) == 0:
print(cable.url + " is completly dangling, can likely be removed.")
continue
print(cable.url + " is dangling on one side, please check!")
# Planned check
cables = netbox.dcim.cables.filter(status="planned")
for cable in cables:
if cable.id not in processed_cords:
last_change = date.fromisoformat(cable.last_updated.split("T")[0])
if (date.today() - last_change) > timedelta(days=365):
print(cable.url + " is planned and wasn't touched for over a year, please check for relevance!")
processed_cords.append(cable.id)
# Type Check
cables = netbox.dcim.cables.all()
for cable in cables:
if cable.id not in processed_cords and cable.type == "":
print(cable.url + " has no type set, please fix.")
processed_cords.append(cable.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment