Skip to content

Instantly share code, notes, and snippets.

@renatoalmeidaoliveira
Created September 17, 2021 02:55
Show Gist options
  • Save renatoalmeidaoliveira/8ee323cad345447f651f6c6044b655a0 to your computer and use it in GitHub Desktop.
Save renatoalmeidaoliveira/8ee323cad345447f651f6c6044b655a0 to your computer and use it in GitHub Desktop.
A simple Netbox report that checks if all the enabled interfaces are connected. Creating a new section for each site.
from extras.reports import Report
from dcim.models import Device
from dcim.models import Site
class ConnectedInterfaces(Report):
description = "Check if all enabled interface are connected"
def __init__(self, *args, **kwargs):
for site in Site.objects.all():
site_name = site.name
setattr(self.__class__,
f'test_connected_interfaces_{site_name}',
staticmethod(self._connected_iterface_wrapper(site_name)))
super().__init__(*args, **kwargs)
def _connected_iterface_wrapper(self, site):
def run_report():
self._connected_interface(site)
return run_report
def _connected_interface(self, site):
site = Site.objects.get(name=site)
devices = site.devices.all()
for device in devices:
for iface in device.interfaces.all():
if iface.enabled is True:
if iface.is_connectable:
interface = iface.name
if len(iface.trace()) == 0:
self.log_warning(device, f"{interface} not connected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment