contrib reports

758 views
Skip to first unread message

Brian Candler

unread,
Oct 13, 2017, 7:57:07 AM10/13/17
to NetBox
Are there any takers for the idea for a set of contributed reports, either in a contrib/ directory in Netbox or in a separate repo?  This would be helpful for those of us who don't really grok Django ORM very well.

Here's one to kick off: checking for devices and VMs which should have a primary IP address but don't (i.e. they have one or more active, non-management addresses, but none selected as primary)

Dave Noonan

unread,
Oct 13, 2017, 8:00:14 AM10/13/17
to Brian Candler, NetBox
I'm interested but know absolutely nothing about how to use that.  Can you point me at a doc?  Is it in the NetBox docs?

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/16facfdd-8225-4722-a1a1-eab35eb94990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Candler

unread,
Oct 13, 2017, 8:29:58 AM10/13/17
to NetBox
The "reports" function is documented here:

In Netbox 2.2, you drop the python file (like the example I posted) into the netbox/reports/ directory and then it's available in the UI, or you can run from CLI or API.

As for writing django ORM code, you're probably best looking at as many examples in the existing Netbox code as you can find, plus:

Brian Candler

unread,
Oct 19, 2017, 3:42:40 PM10/19/17
to NetBox
On Friday, 13 October 2017 12:57:07 UTC+1, Brian Candler wrote:

Here's one to kick off: checking for devices and VMs which should have a primary IP address but don't (i.e. they have one or more active, non-management addresses, but none selected as primary)


FYI, I've updated this report to highlight IP addresses with a prefixlen that's inconsistent with the enclosing Prefix object. 

Augusto Carlson

unread,
Oct 31, 2017, 1:11:47 PM10/31/17
to NetBox
Hi!

I have not used reports yet. A contrib directory would be nice.

I'm trying using reports for the first time using your file.

Thank you!

Regards,
Augusto

Pett Computers

unread,
Nov 3, 2017, 5:01:07 PM11/3/17
to NetBox

Brian Candler

unread,
Nov 4, 2017, 4:19:36 AM11/4/17
to NetBox
Can you run it from the command line instead? This may give a better error report.

cd /opt/netbox/netbox
python3 manage.py runreport addresses

(replace 'python3' with 'python' if running python2)

Also useful if you could say what Netbox version and what OS you are running it under.

Frank Mogaddedi

unread,
Nov 9, 2017, 8:01:18 AM11/9/17
to NetBox

Since I run into the exact same issue – here’s mine. The errors are the same if I use the documentation’s devices example. Also: My reports directory is in /opt/Netbox_reports, and I’ve set the REPORTS_ROOT accordingly.

 

# python3 manage.py runreport addresses

Traceback (most recent call last):

  File "manage.py", line 10, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 356, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute

    output = self.handle(*args, **options)

  File "/opt/netbox-2.2.4/netbox/extras/management/commands/runreport.py", line 19, in handle

    reports = get_reports()

  File "/opt/netbox-2.2.4/netbox/extras/reports.py", line 49, in get_reports

    module = importlib.import_module('reports.{}'.format(module_name))

  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 986, in _gcd_import

  File "<frozen importlib._bootstrap>", line 969, in _find_and_load

  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked

ImportError: No module named 'reports.addresses'

 

However, if I stick the reports in /opt/netbox/netbox/reports and uncomment the REPORT_ROOT variable in the config, it all looks pretty good

 

Is it a bug or did I do something stupid?

 

            Frank

--

You received this message because you are subscribed to the Google Groups "NetBox" group.

To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/59ca3c16-62ac-47a4-be34-175a476c979d%40googlegroups.com.

Brian Candler

unread,
Nov 9, 2017, 4:41:16 PM11/9/17
to NetBox
On Thursday, 9 November 2017 13:01:18 UTC, Frank M wrote:


However, if I stick the reports in /opt/netbox/netbox/reports and uncomment the REPORT_ROOT variable in the config, it all looks pretty good

 

Is it a bug or did I do something stupid?


I only ever put the reports in /opt/netbox/netbox/reports/ and didn't touch REPORTS_ROOT

If you tried a different location: did you remember to create an empty file __init__.py in that directory?

Frank Mogaddedi

unread,
Nov 10, 2017, 4:56:12 AM11/10/17
to NetBox

Yes, I did. And if I don’t have any .py files in my own reports directory, I do get the appropriate “there are no reports here” message.

 

I just know that if I don’t stick them in a separate directory, the day will come where I forget to copy them out on a Netbox update ;)

 

            Frank

--

You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.

Brian Candler

unread,
Feb 13, 2019, 4:18:26 AM2/13/19
to NetBox
Here is another report: it checks all devices to see if they are missing any components which are in the corresponding DeviceType template.


It's horrendously inefficient, but does the job.  Probably some prefetch_related() would speed it up, but I hate the Django ORM enough as it is.
Message has been deleted

Brady Lamprecht

unread,
Feb 13, 2019, 4:41:30 PM2/13/19
to NetBox
Brian,

Would you please add this to the netbox-community/report repository on GitHub?

Brian Candler

unread,
Feb 14, 2019, 4:27:05 PM2/14/19
to NetBox
I wasn't aware of that, thanks!

Rob Nield

unread,
Sep 3, 2019, 6:53:00 PM9/3/19
to NetBox
Not even sure what question to ask here.. 

Are they docs on the syntax or is that covered by understand the constructs of python?

Does the API contain the constants that are used in the reports?

Brian Candler

unread,
Sep 4, 2019, 3:13:42 AM9/4/19
to NetBox
On Tuesday, 3 September 2019 23:53:00 UTC+1, Rob Nield wrote:
Are they docs on the syntax or is that covered by understand the constructs of python?


Correct, reports are Python code.  Database access uses the ORM layer of Django.
 
Does the API contain the constants that are used in the reports?

See netbox/*/constants.py

Any given report will import the constants it needs, e.g. import ipam.constants
Reply all
Reply to author
Forward
0 new messages