NetBox is a popular DCIM, and is often used as the “Source of Truth” for your network. PRTG is a monitoring platform, often used for network monitoring (although they have sensors for plenty of other devices). This post will outline some ways of integrating NetBox and PRTG.
In this post I am using:
In NetBox I have a number of sites. For this example I have a site named “PRTG Site” in NetBox, as well as in PRTG. To “connect” these two I have to create a field in NetBox where I can input the PRTG ID.
So I create a custom field named “PRTG ID” in NetBox.
In PRTG I create my corresponding group:
And in NetBox I add the PRTG ID to my site:
Now I need to make sure any update in NetBox is reflected in PRTG.
The NetBox site has a number of statuses available. A site can be “Active”, “Planned”, “Staging”, “Decommissioning”, and “Retired”. In this example I expect the site to be monitored in PRTG when the status is “Active”. Any other status I expect the site to not be monitored in PRTG.
To achieve this I need to configure a webhook in NetBox. This will fire on any change on a NetBox site, and triggering a pause/resume in PRTG depending on the status.
The PRTG API defines the URL for pausing/resuming an object.
/api/pause.htm?id=objectid&action=1 resumes monitoring.
/api/pause.htm?id=objectid&action=0 stops monitoring. All PRTG API calls require a username and passhash as well. So a simple webhook would look like this:
Note that using jinja2 code in the payload URL is a new feature of NetBox 3.2. Being able to create your URL from jinja2 code you can skip middleware having to “translate” the URL to a different URL. This can simplify your webhook configuration and administration.
If I now change the NetBox site status from “Active” to “Planned”, I can check PRTG and see the site paused.
If you want to provide a message with the webhook you can add
&pausemsg=youmessage to the webhook configuration.
And I can resumed the monitoring again by setting the site status to “Active”.
Using the new feature of templated payload URL in NetBox, integrating a system like PRTG becomes easy. This example is relatively simple. It would make more sense to add another custom field to the Site model where you can define the Monitoring status of a site. This way a site could still be in an “Active” status, but the monitoring could be stopped using a status in the custom field. Or, if you want to play with the new custom statuses in NetBox 3.2 you could add a “Stopped monitoring” status to the Site model.