Commit b5ea560f authored by Adrian Schollmeyer's avatar Adrian Schollmeyer
Browse files

Add reports patchpanels.py and switches.py


Signed-off-by: Adrian Schollmeyer's avatarAdrian 'nex' Schollmeyer <adrian.schollmeyer@fem.tu-ilmenau.de>
parent 6a6747fb
......@@ -9,3 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* ArubaApNetworkIntegration (ensure valid network configuration and uplink connection)
* `devices.py` report
* DeviceUplinkConnection (ensure valid uplink connection for regular devices)
* `patchpanels.py` report
* PatchpanelConventions (ensure naming conventions for patchpanels)
* `switches.py` report
* SwitchConventions (ensure naming conventions for switches)
import re
from circuits.models import *
from dcim.choices import DeviceStatusChoices
from dcim.models import *
from ipam.models import *
from extras.reports import Report
class PatchpanelConventions(Report):
description = \
"Validate that every patchpanel adheres to certain conventions"
# Adhering to
# https://wiki.fem.tu-ilmenau.de/technik/dienste/netbox/policy/doku#server-_und_patchracks
naming_convention_re = re.compile(
r"^(Patchpanel\s)?\w+-Br(-(\w+))*/(SM|MM|K)/[a-zA-Z0-9_ -]+"
r"(/[0-9]+)?"
r"(//\w+-Br(-(\w+))*/(SM|MM|K)/[a-zA-Z0-9_ -]+"
r"(/[0-9]+)?)*$"
)
def test_patchpanel_matches_naming_convention(self):
for device in Device.objects.filter(
device_role__slug__contains = "patchpanel"):
device_name = str(device.name)
re_match = self.naming_convention_re.match(device_name)
if re_match is None:
self.log_failure(device, f"Name '{device_name}' is invalid")
else:
self.log_success(device, "Name matches")
import re
from circuits.models import *
from dcim.choices import DeviceStatusChoices
from dcim.models import *
from ipam.models import *
from extras.reports import Report
class SwitchConventions(Report):
description = \
"Validate that every switch adheres to certain conventions"
# Adhering to
# https://wiki.fem.tu-ilmenau.de/technik/dienste/netbox/policy/doku
naming_convention_re = re.compile(
r"^\w+-switch-\d+$"
)
def test_switch_matches_naming_convention(self):
for device in Device.objects.filter(
device_role__slug__contains = "access-switch"):
device_name = str(device.name)
re_match = self.naming_convention_re.match(device_name)
if re_match is None:
self.log_failure(device, f"Name '{device_name}' is invalid")
else:
self.log_success(device, "Name matches")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment