Last active
March 31, 2023 14:33
-
-
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
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
# 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also very helpful report, thanks!