Last active
January 10, 2023 19:26
-
-
Save candlerb/d78886b93b36e570e1098eb1d346b76e to your computer and use it in GitHub Desktop.
Netbox report to identify devices which are missing items from device type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update model related names