Report Templates

1,747 views
Skip to first unread message

Mark Mahacek

unread,
Jul 11, 2018, 2:56:28 PM7/11/18
to NetBox
Does anyone have a repository of report templates/samples to share?  I am new to Netbox and python and am having issues getting started with reports.  Specifically I am looking at some mentioned in the documentation (verify all IP addresses have a parent prefix and minimum number of VLANs per site.)  I also found that the same report in the documentation doesn't work (submitted a PR to fix the documentation).

Wes Hegge

unread,
Jul 11, 2018, 5:01:38 PM7/11/18
to NetBox

Mark,

The problem with the documentation is the STATUS_ACTIVE constant.  It should be DEVICE_STATUS_ACTIVE.

As for a repository, I would be interested too.  I have just started to figure out Reports with little Python experience myself (Perl programmer). 

These commands have helped me:

Launch Netbox Shell
  ./manage.py nbshell

then
  lsmodels()
  help(<model>)

HTH,

Wes

Mark Mahacek

unread,
Jul 11, 2018, 5:58:08 PM7/11/18
to NetBox
That got me going in the right direction.  I had not tried the shell, and had to modify my manage.py to point to the correct version of python.
Here is one of my reports to share:


from dcim.constants import DEVICE_STATUS_ACTIVE
from dcim.models import Device
from extras.reports import Report


class DeviceIP4Report(Report):
    description
= "Check that every device has a primary IPv4 address assinged"


   
def test_primary_ip4(self):
       
for device in Device.objects.filter(status=DEVICE_STATUS_ACTIVE):
           
if device.primary_ip4_id is None:
               
self.log_failure(device, "{} missing primary IPv4 address.")
           
else:
               
self.log_success(device)

Brian Candler

unread,
Jul 12, 2018, 3:36:32 AM7/12/18
to NetBox
There are a couple of sample reports here:

One checks for missing primary IPv4/IPv6 address (but only if the device already has at least one-management IPv4 or IPv6 address). The other checks that the prefix length of each IP address matches the enclosing subnet.


Mark Mahacek

unread,
Jul 12, 2018, 1:40:36 PM7/12/18
to NetBox
Awesome.  Starting to get the hang of this.  Here is an update of the device IP report I previously posted.  https://gist.github.com/mmahacek/9db2af00070c35f19ed4209359e6c069
Reply all
Reply to author
Forward
0 new messages