netenglabs / suzieq

Using network observability to operate and design healthier networks
https://www.stardustsystems.net/
Apache License 2.0
775 stars 105 forks source link

[Feature]: custom netbox queries / add nautobot 2.X support #921

Open gioccher opened 5 months ago

gioccher commented 5 months ago

Suzieq version

0.22.0

Install Type

container

Feature type

Extend sq-poller

Use case

Import devices from netbox based on arbitrary filters, not just tags. It also has the welcome side effect of adding support for Nautobot 2.X (the query syntax of netbox and nautobot 1.X is equivalent and so the current netbox source can be used for nautobot deployments, but it doesn't work for nautobot 2.X)

Proposed functionality/solution

The netbox source allows specifying one or more tags to pick the devices to include in the inventory. The approach I'm proposing is to allow the SuzieQ user to specify the filters that will be sent to netbox. Could be a list of tags, a list of sites, and/or a list of any other attributes...

This makes the Netbox source more flexible, and also makes it work for all the Nautobot versions

Example: this is a sample netbox source configuration

sources:
- name: nautobot
  token: env:NAUTOBOT_TOKEN
  url: env:NAUTOBOT_URL
  tag:
  - next_gen
  type: netbox
  period: 3600

and this is the equivalent config that uses the proposed filters mechanism

sources:
- name: nautobot
  token: env:NAUTOBOT_TOKEN
  url: env:NAUTOBOT_URL
  filters:
  - tag=next_gen
  type: netbox
  period: 3600

both produce an API request like this GET https://demo.nautobot.com/api/dcim/devices/?tag=next_gen

Another example that really shows the flexibility of this approach:

sources:
- name: nautobot
  token: env:NAUTOBOT_TOKEN
  url: env:NAUTOBOT_URL
  filters:
  - role=core
  - status=active
  - tags=next_gen
  - tags=whatever
  - depth=1
  type: netbox
  period: 3600

which produces an API call like GET https://demo.nautobot.com/api/dcim/devices/?role=core&status=active&tags=next_gen&tags=whatever&depth=1

It's up to the user to lookup the netbox/nautobot documentation and pick the parameters that make most sense for the use-case. https://demo.nautobot.com/api/docs/#/dcim/dcim_devices_list https://demo.netbox.dev/static/docs/rest-api/filtering/

External dependencies

No response

Additional Context