Re: netbox_prometheus integration

142 views
Skip to first unread message
Message has been deleted

Brian Candler

unread,
May 15, 2021, 4:23:06 AM5/15/21
to NetBox
Looking at that blog, they are running a script "netbox-prometheus-sd.py" to export data from Netbox and write it to a JSON file that can be picked up by prometheus' file service discovery mechansm.  The script itself is here, which also tells you that you need to create a custom field on your Device and VM objects.

Therefore, making this work can be split into two parts:
1. running the netbox-prometheus-sd.py script and adjusting the config until it successfully writes out JSON listing the devices/VMs to be scraped
2. updating your prometheus config to read the JSON and scrape using it

I did something similar myself: https://github.com/candlerb/netbox-prometheus - you can try that instead if you like.  But I'm not providing support: feel free to use and/or modify, but any problems with python, pynetbox or prometheus are yours to solve.

Daniaal hamid

unread,
May 15, 2021, 7:40:31 AM5/15/21
to NetBox
Brian:

even though i configured the ipv4 and custom fields requirements as it said in the document
this is the error after running netbox-prometheus.py.

netbox-prometheus-sd.py: error: the following arguments are required: url, token, output

Brian Candler

unread,
May 15, 2021, 8:57:59 AM5/15/21
to NetBox
"error: the following arguments are required: url, token, output"

That's a very clear error message.  If you go back to the blog post, it shows you an example of how to run the command:

La ligne de commande à lancer est typiquement la suivante :

$ netbox-prometheus-sd.py https://nebox.your-company.com/ 'API_TOKEN' '/path/to/generated/output.json'

hamid daniali

unread,
May 16, 2021, 1:39:45 AM5/16/21
to NetBox
brian:

 python3 netbox-prometheus-sd.py http://192.168.50.142:8085  'c6d547ee5116216eb56fd0cdb8dd55a8ac812bic' '/path/to/generated/output.json'

Traceback (most recent call last):
  File "netbox-prometheus-sd.py", line 8, in <module>
    import netaddr


this the new error after importing as the quoted format.


Brian Candler

unread,
May 16, 2021, 3:43:08 AM5/16/21
to NetBox
It's saying you need to install the 'netaddr' package.  Also looking at the code I can see you need to install 'pynetbox' as well.
Message has been deleted
Message has been deleted

hamid daniali

unread,
May 16, 2021, 4:44:16 AM5/16/21
to NetBox
i ve installed netaddr as you ve said but now i have this error msg

File "netbox-prometheus-sd.py", line 8, in <module>
    import netaddr
  File "/usr/lib/python2.7/site-packages/netaddr/__init__.py", line 18, in <module>
    from netaddr.core import (AddrConversionError, AddrFormatError,
  File "/usr/lib/python2.7/site-packages/netaddr/core.py", line 11, in <module>
    from netaddr.compat import _callable, _iter_dict_keys
  File "/usr/lib/python2.7/site-packages/netaddr/compat.py", line 93, in <module>
    import importlib_resources as _importlib_resources

ImportError: No module named importlib_resources



Brian Candler

unread,
May 16, 2021, 4:58:32 AM5/16/21
to NetBox
I can see you're running this script with python 2, which went end-of-life more than a year ago. All modern python scripts need to be run under python3.

This isn't a general Python support list, so this will be my last post on this thread.  If you need help running a Python script (which is not part of Netbox) then there are other resources you can use.
Message has been deleted

hamid daniali

unread,
May 16, 2021, 6:56:29 AM5/16/21
to NetBox
brian: 

python3 netbox-prometheus-sd.py http://192.168.58.142:8085 'c6d547ee5116216eb56fd0cdb8dd55a8ac812bcc' '/opt/targets.json'

i recieve just [] in the targets.json

but when i check my /api/dcim/devices  i have this report brian.c12.png
c14.PNG

hamid daniali

unread,
May 17, 2021, 6:52:29 AM5/17/21
to NetBox
brain :
don't you have anyidea about why my output JSON is just like [ ]
what i have been dismissed?
Reply all
Reply to author
Forward
0 new messages