Skip to content

Instantly share code, notes, and snippets.

@candlerb
candlerb / addresses.py
Last active April 2, 2024 00:07
Netbox report to check for missing Primary IP Addresses
from extras.reports import Report
from dcim.models import Device
from virtualization.models import VirtualMachine
from ipam.constants import *
from ipam.models import IPAddress, Prefix
LOOPBACK_ROLES = [
IPADDRESS_ROLE_LOOPBACK,
IPADDRESS_ROLE_ANYCAST,
IPADDRESS_ROLE_VIP,
@candlerb
candlerb / gist:989c9b63b4da47556c0f5e19ce50b7b8
Created September 10, 2018 12:14
VDSL stats from Draytek Vigor 130
$ telnet 192.168.2.1
Trying 192.168.2.1...
Connected to 192.168.2.1.
Escape character is '^]'.
Account:admin
Password: ********
@candlerb
candlerb / missing-device-ports.py
Last active September 4, 2019 08:18
Report to highlight devices which are missing ports that are in the DeviceType template
# 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):
@candlerb
candlerb / fix-device-ports.py
Last active January 16, 2022 15:00
Standalone script to create all the missing device components which exist in DeviceType template but not in Device instances
import django
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'netbox.settings')
django.setup()
from dcim.models import Device, ConsolePort, ConsoleServerPort, PowerPort, PowerOutlet, Interface, RearPort, FrontPort, DeviceBay
for device in Device.objects.all():
# Based on Device.save()
ConsolePort.objects.bulk_create(
@candlerb
candlerb / add-device-ports.py
Last active March 30, 2025 12:37
Netbox script to add missing components from Device Type to all instances of Device
#!/opt/netbox/venv/bin/python
import django
import os
import sys
sys.path.append('/opt/netbox/netbox')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'netbox.settings')
django.setup()
from dcim.models import Device, ConsolePort, ConsoleServerPort, PowerPort, PowerOutlet, Interface, RearPort, FrontPort, DeviceBay
@candlerb
candlerb / missing-device-ports.py
Last active March 31, 2023 14:33
Netbox report to highlight devices which are missing components that are defined in the Device Type
# 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):
@candlerb
candlerb / natural-sort.py
Last active August 13, 2021 13:21
Test of natural sorting algorithm
import re
import unittest
def parse_natural(name):
res = re.split("(\d+)", name)
# first and last element is always a string; alternate values are numbers
for i in range(1, len(res), 2):
res[i] = int(res[i])
return res
@candlerb
candlerb / natural-sort-2.py
Last active May 10, 2019 13:39
Natural sorting with option of priority to line card
import re
import unittest
def parse_natural(name, line_card_first=False):
res = re.split("(\d+)", name)
if line_card_first and len(res) > 3:
res = ["", res[1]] + res
# first and last element is always a string; alternate values are numbers
for i in range(1, len(res), 2):
res[i] = int(res[i])
#!/bin/sh
host="$1"
REALM="LOCAL.EXAMPLE.NET"
LCREALM="local.example.net"
TESTUSER="nagiostest"
BASENAME="cn=users,dc=local,dc=example,dc=net"
if [ "$host" = "" ]; then
echo "Missing hostname"
exit 2
@candlerb
candlerb / cross-cables.py
Created June 23, 2019 15:41
Netbox report to highlight cables between sites and cables between racks (apart from rearport to rearport)
from extras.reports import Report
from dcim.models import Cable, RearPort
from dcim.constants import *
from circuits.models import CircuitTermination
CABLE_TYPES_OK_BETWEEN_RACKS = {
CABLE_TYPE_DAC_PASSIVE,
}
class CheckCableLocality(Report):