miaow2/netbox-config-diff

FR: Define file name template for config files in data source

Closed this issue · 3 comments

Hi. Great plugin, thanks for all your effort!

I am using netbox-config-diff with config files in a git data source. We use many virtual chassis in Netbox to represent switch stacks and VSS/SVL (Cisco virtual chassis) and we have an individual device in Netbox per member switch, with a naming convention like switch-name:1 (for switch 1 in the stack, and so on), and the Netbox virtual chassis name is the actual switch hostname. Also, we save our switch configs in the data source with the standard Cisco file naming, which is <switch hostname>-confg. Since netbox-config-diff looks for a file named "device name" it doesn't find our config files in the data source unless we rename them.

Would it be possible to implement some sort of file name template function to allow us to define which file to look for? Perhaps a jinja template with access to the device object data similar to the way that Netbox custom links can be defined?

Many thanks!

Hi @noziwatele, thanks for opening this issue,
its a good idea, I will think how to implement this

Hi @noziwatele I've just tried some workarounds and want to be sure that I understand your issue.
Correct me if I am wrong.

  1. In Datasource config files have name <switch hostname>-confg where <switch hostname> is the name of the virtual chassis?
  2. Devices have names <switch hostname>:<some number>?
  3. In the device's ConfigCompliance object page, do you have the error Not found file in DataSource for device?

Hi @miaow2, thanks for looking into this FR!

I just checked again to confirm and your 3 statements above are all correct.

One way I can imagine this being implemented is by having a File name field available when a Data Source is selected. And this File name field would allow Jinja template code, like the Link URL field in Netbox custom links, where an object variable containing the device object is passed to it and we could use some sort of conditional Jinja code to define the file name format to look for, e.g. {% if object.virtual_chassis %}{{ object.virtual_chassis }}-confg{% else %}{{ object.name }}{% endif %}

{{ object.name }} could be the default value to provide consistency with the current behaviour.