Documentation
¶
Index ¶
- Constants
- 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 CreateLLDPCable(nb cableWriter, aInterfaceID, bInterfaceID uint) (*netboxtool.NBCable, 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 IsLLDPCable(c *netboxtool.NBCable) bool
- 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
- type CustomFieldWrite
- type EventRuleWrite
- type NBChoiceSet
- type NBEventRule
- type NBWebhook
- type WebhookWrite
Constants ¶
const CableLabelLLDP = "lldp"
CableLabelLLDP is the dcim.Cable.label written on cables created from LLDP neighbors. device-sync only creates, retargets, or deletes cables with this exact label so operator-drawn cables stay untouched.
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 webhooks, event rules and fields, and patches mutable attributes (custom field 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 CreateLLDPCable ¶ added in v1.0.3
func CreateLLDPCable(nb cableWriter, aInterfaceID, bInterfaceID uint) (*netboxtool.NBCable, error)
CreateLLDPCable creates a cable between two interfaces and marks it as LLDP-owned.
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 IsLLDPCable ¶ added in v1.0.3
func IsLLDPCable(c *netboxtool.NBCable) bool
IsLLDPCable reports whether c is owned by LLDP auto-cabling.
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, the factum webhook, and its event rule when they are missing or have drifted.
type CustomFieldWrite ¶ added in v1.0.4
type CustomFieldWrite struct {
Name string
Type string
Label string
Description string
GroupName string
Required bool
ObjectTypes []string
ChoiceSetID uint
}
CustomFieldWrite is the body for creating a custom field.
type EventRuleWrite ¶ added in v1.0.4
type EventRuleWrite struct {
Name string
Enabled bool
ObjectTypes []string
EventTypes []string
ActionType string
ActionObjectID uint
}
EventRuleWrite is the body for creating extras.EventRule.
type NBChoiceSet ¶ added in v1.0.4
NBChoiceSet is extras.CustomFieldChoiceSet. ExtraChoices are [value, label] pairs Netbox stores on the set (not on the custom field).
type NBEventRule ¶ added in v1.0.4
type NBEventRule struct {
NetboxID uint
Name string
Enabled bool
ObjectTypes []string
EventTypes []string
ActionType string
ActionObjectID uint
// Conditions is the optional JSON condition object; nil/empty means
// the rule fires for every matching event.
Conditions any
}
NBEventRule is extras.EventRule — binds object types and event types to an action (typically a webhook). ActionObjectID is the extras.Webhook id when ActionType is "webhook".
func (*NBEventRule) HasConditions ¶ added in v1.0.4
func (r *NBEventRule) HasConditions() bool
HasConditions reports whether the rule has a non-empty condition object that would restrict which events actually fire.
func (*NBEventRule) HasEvent ¶ added in v1.0.4
func (r *NBEventRule) HasEvent(eventType string) bool
HasEvent reports whether the rule lists eventType (e.g. "object_deleted").
func (*NBEventRule) HasObjectType ¶ added in v1.0.4
func (r *NBEventRule) HasObjectType(objectType string) bool
HasObjectType reports whether the rule lists objectType (e.g. "dcim.device").
type NBWebhook ¶ added in v1.0.4
type NBWebhook struct {
NetboxID uint
Name string
PayloadURL string
HTTPMethod string
HTTPContentType string
BodyTemplate string
}
NBWebhook is extras.Webhook — the destination half of Netbox 3.7+'s webhook/event-rule split. Object types and events live on NBEventRule.