Skip to content

Instantly share code, notes, and snippets.

@candlerb
Last active January 10, 2023 19:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candlerb/d78886b93b36e570e1098eb1d346b76e to your computer and use it in GitHub Desktop.
Save candlerb/d78886b93b36e570e1098eb1d346b76e to your computer and use it in GitHub Desktop.
Netbox report to identify devices which are missing items from device type
# Identify devices which are missing components from the device type definition
from extras.reports import Report
from dcim.models import Device
class MissingDeviceTypeComponents(Report):
name = "Missing Device Type Components"
description = "Find devices which are missing components that are in the device type template"
def test_add_ports(self):
for device in Device.objects.all():
dt = device.device_type
for item, templateitem in [
('consoleports', 'consoleporttemplates'),
('consoleserverports', 'consoleserverporttemplates'),
('powerports', 'powerporttemplates'),
('poweroutlets', 'poweroutlettemplates'),
('interfaces', 'interfacetemplates'),
('rearports', 'rearporttemplates'),
('frontports', 'frontporttemplates'),
('devicebays', 'devicebaytemplates'),
]:
names = {i.name for i in getattr(device, item).all()}
templatenames = {i.name for i in getattr(dt, templateitem).all()}
missing = templatenames - names
if missing:
self.log_warning(device, "Missing %s %r" % (item, sorted(missing)))
@candlerb
Copy link
Author

Update model related names

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