Documentation
¶
Index ¶
- func ApplyCable(db *gorm.DB, netboxID uint, cable *netboxtool.NBCable) (created, updated, deleted, skipped int, err error)
- func ApplySite(db *gorm.DB, netboxID uint, site *netboxtool.NetboxSite) (created, updated, deleted int, err error)
- func Check(c *util.ConfigRoot, opts CheckOptions, reporter jobevent.Reporter) error
- func CheckDB(nb checkAPI, settings *models.Settings, opts CheckOptions, ...) error
- func DeleteConnectionByNetboxID(db *gorm.DB, netboxID uint) (int, error)
- func DeleteDeviceByNetboxID(db *gorm.DB, netboxID uint, vm bool) (int, error)
- func DeleteSiteByNetboxID(db *gorm.DB, netboxID uint) (int, error)
- func FetchRemoteConfig(factumConfig *util.ConfigFactum) (*util.ConfigNetbox, error)
- func FindOrCreateTenant(nb *netboxtool.NetboxClient, customer models.Customer) (*netboxtool.NBTenant, error)
- func RemoteClient(factumConfig *util.ConfigFactum) (*netboxtool.NetboxClient, error)
- func Sync(c *util.ConfigRoot, name string, reporter jobevent.Reporter) error
- func SyncCable(db *gorm.DB, netboxID uint, reporter jobevent.Reporter) error
- func SyncDB(db *gorm.DB, name string, reporter jobevent.Reporter) error
- func SyncSite(db *gorm.DB, netboxID uint, reporter jobevent.Reporter) error
- type CheckOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCable ¶
func ApplyCable(db *gorm.DB, netboxID uint, cable *netboxtool.NBCable) (created, updated, deleted, skipped int, err error)
ApplyCable upserts or removes one Connection. cable == nil means the object is gone or not interface-to-interface — delete the local row. Unresolved endpoints also drop the local row (skip=1) rather than leave a stale Connection pointing at the old terminations.
func ApplySite ¶
func ApplySite(db *gorm.DB, netboxID uint, site *netboxtool.NetboxSite) (created, updated, deleted int, err error)
ApplySite upserts or removes one Site. site == nil means gone / Default / no coordinates — delete the local row.
func Check ¶
func Check(c *util.ConfigRoot, opts CheckOptions, reporter jobevent.Reporter) error
Check verifies Netbox webhooks/event rules and the custom fields factum needs. Without Update it only reports. With Update it creates missing fields and patches mutable attributes (type is never changed).
func CheckDB ¶
func CheckDB(nb checkAPI, settings *models.Settings, opts CheckOptions, reporter jobevent.Reporter) error
CheckDB is Check against an already-built client and Settings row.
func DeleteConnectionByNetboxID ¶
DeleteConnectionByNetboxID removes one Connection by its Netbox cable id and marks optical paths that used it stale. No-op if none matches.
func DeleteDeviceByNetboxID ¶
DeleteDeviceByNetboxID removes one netbox-sourced device (or VM) by its Netbox primary key. Used by the webhook delete path: Netbox has already removed the object, so it cannot be re-fetched and upserted. Returns 1 if a row was deleted, 0 if none matched (already gone, or cf_source != "netbox" — matching deleteMissingDevices' guard). vm must match the object's table: Netbox's dcim.Device and virtualization.VirtualMachine IDs are independent sequences, so a device and a VM can share a NetboxID.
func DeleteSiteByNetboxID ¶
DeleteSiteByNetboxID removes one Site by its Netbox id. No-op if none matches.
func FetchRemoteConfig ¶
func FetchRemoteConfig(factumConfig *util.ConfigFactum) (*util.ConfigNetbox, error)
FetchRemoteConfig pulls the Netbox API connection settings from the primary, authenticated with factumConfig.Token (checked against the primary's Settings.FactumApiToken - see web.Controller.checkServiceToken).
func FindOrCreateTenant ¶
func FindOrCreateTenant(nb *netboxtool.NetboxClient, customer models.Customer) (*netboxtool.NBTenant, error)
FindOrCreateTenant returns the Netbox tenant for customer, matched via the same "source"="factum"/"source_id"=<customer.ID> custom fields syncCustomersToNetbox uses. Provisioning paths (currently web.ApiServiceElineUpdate, when it assigns a service's L2VPN to its customer's tenant) call this directly instead of waiting for the next scheduled Netbox sync, so a customer's first service still gets a tenant even if Netbox sync hasn't run since the customer was created.
This runs synchronously in a user-facing request, so it looks the tenant up via nb.GetTenant's filtered REST call rather than nb.GetTenants' full tenant-table fetch - the latter used to mean every service update paid for pulling every Netbox tenant just to find one. GetTenants is only consulted on a miss, to adopt an existing same-name tenant (or pick a unique slug) instead of POSTing a name that already exists.
func RemoteClient ¶
func RemoteClient(factumConfig *util.ConfigFactum) (*netboxtool.NetboxClient, error)
RemoteClient fetches util.ConfigNetbox from the primary and builds a netboxtool.NetboxClient from it.
func Sync ¶
Fetch all devices (with their interfaces, addresses and tags) from Netbox and update the factum database.
If name is specified, only that device is synced. Otherwise every device is synced and any device previously imported from Netbox (cf_source == "netbox") that no longer exists there is removed, together with its interfaces, addresses and tags.
Interfaces, addresses and tags belonging to a synced device are always reconciled against Netbox: anything no longer present there is removed from factum, whether the sync is for a single device or all of them.
func SyncCable ¶
SyncCable applies one Netbox cable to factum's Connection table: refetch by id, upsert if both ends resolve to synced interfaces, otherwise remove any local row for that netbox_id. Used by the webhook; full sync still goes through syncCables.
func SyncDB ¶
SyncDB is Sync against an already-connected database, for callers that already hold a shared *gorm.DB (currently just the Netbox webhook handler, web.ApiNetboxWebhook) - opening a brand new, unbounded connection pool on every single webhook call is what exhausted Postgres's max_connections under a burst of Netbox webhooks.
Types ¶
type CheckOptions ¶
type CheckOptions struct {
Update bool
}
CheckOptions controls Check. Update=false (default) only reports. Update=true creates/updates custom fields that drift from the catalogue.