Last active
September 4, 2019 08:18
-
-
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
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', '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))) |
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
This is a nice report, are you willing to share on https://github.com/netbox-community/reports?