Skip to content

Instantly share code, notes, and snippets.

@candlerb
Last active March 31, 2023 14:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candlerb/c5b8774701e6d0d0f33415c7257c7d05 to your computer and use it in GitHub Desktop.
Save candlerb/c5b8774701e6d0d0f33415c7257c7d05 to your computer and use it in GitHub Desktop.
Netbox report to highlight devices which are missing components that are defined in the Device Type
# Install as reports/missing-device-ports.py
# Run as: python3 manage.py runreport missing-device-ports
from extras.reports import Report
from dcim.models import Device
class MissingDevicePorts(Report):
description = "Find devices which are missing ports that are in the device type template"
def test_add_ports(self):
for d in Device.objects.all():
dt = d.device_type
for item, templateitem in [
('interfaces', 'interfacetemplates'),
('rearports', 'rearporttemplates'),
('frontports', 'frontporttemplates'),
('consoleports', 'consoleporttemplates'),
('consoleserverports', 'consoleserverporttemplates'),
('powerports', 'powerporttemplates'),
('poweroutlets', 'poweroutlettemplates'),
('devicebays', 'devicebaytemplates'),
]:
names = {i.name for i in getattr(d, item).all()}
templatenames = {i.name for i in getattr(dt, templateitem).all()}
missing = templatenames - names
if missing:
self.log_warning(d, "Missing %s %r" % (item, sorted(missing)))
@vahem2lu
Copy link

Also very helpful report, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment