IP Fabric Netbox Plugin – How to strip the re0 from Juniper Routers

Larger Juniper routers have two hardware control planes, known as routing engines. These can be seen on some models as a removable slot in the chassis. Each has its own management IP, storage etc and can be seen as an independant compute node. If one fails, the other takes over.

When IP Fabric connects to the router to extract the data it talks to the active RE and the resulting hostname will be re[0|1].routername. If just using IP Fabric via the GUI this doesn’t present any real challenge. When ingesting the IP Fabric data into netbox it can be a problem. Other systems using the netbox data will know the device as routername. So there will be a mismatch. Its also a bit annoying to have to keep writing regex that strips out the re0 or re1 (which can change during a failover).

The IP Fabric netbox plugin includes the concept of transform maps which control the data flowing between the two systems. In the ‘device’ transform map you can select the field Maps tab and edit the entry for hostname. The following jinja2 template will strip the unwanted prefix:

{% if "re0." in object.hostname or "re1." in object.hostname %}{{ object.hostname[4:] }}{% else %}{{object.hostname}}{% endif %}

If you already have data in netbox that includes the re0 running the ingestion with the above will create modify objects to clean up netbox. This works because it is the serial number (sn) that is the coalesce field and not the hostname so netbox is able to process this based on the serial number being the same.

Transform maps are more than useful, they are essential for most setups where the data in IP Fabric is different to that in netbox. For example the following part number transform map template within the pid/part_id field map deals with the situation where the IP Fabric data doesn’t contain a part ID (which is fine in the source but not permitted in netbox).

{% if object.pid and object.pid != "None" %}{{ object.pid }}{% else %}unknown{% endif %}

If you have used an interesting transform map jina2 template please post it below in the comments to help others.

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started