Skip to content

Instantly share code, notes, and snippets.

@candlerb
Last active September 4, 2019 08:18
Show Gist options
  • Save candlerb/ee7c0ca487d32f52dcbc397c5ce5ce5a to your computer and use it in GitHub Desktop.
Save candlerb/ee7c0ca487d32f52dcbc397c5ce5ce5a to your computer and use it in GitHub Desktop.
Report to highlight devices which are missing ports that are in the DeviceType template
# 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', 'interface_templates'),
('rearports', 'rearport_templates'),
('frontports', 'frontport_templates'),
('consoleports', 'consoleport_templates'),
('consoleserverports', 'consoleserverport_templates'),
('powerports', 'powerport_templates'),
('poweroutlets', 'poweroutlet_templates'),
('device_bays', 'device_bay_templates'),
]:
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)))
@MarcHagen
Copy link

This is a nice report, are you willing to share on https://github.com/netbox-community/reports?

@candlerb
Copy link
Author

candlerb commented Sep 4, 2019

I don't mind, but I would prefer that contributed reports remain separate: raised as netbox-community/customizations#16

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