NetBox
NetBox as the source of truth for hosts: connecting, sync and prune, matching agents to hosts, drift, webhooks, optional write-back and access through NetBox attributes.
On this page
Status. Tested: the client, sync, prune guard, matching, merge, drift, webhook receiver and write-back against a fake NetBox in the product's package tests on PostgreSQL. A test against a real NetBox container exists; it was not run for these docs. Not yet run: NetBox 3.7 and 4.0 to 4.5 against the real application (the version-dependent requests are covered by the fake).
NetBox owns host identity; Structam owns what it observes on the hosts. Structam reads devices and virtual machines from NetBox and never invents a host identity of its own: an agent on a host NetBox does not know appears as unmatched until NetBox has it. Structam writes to NetBox only into its own custom fields and journal entries, and only when write-back is on.
Supported: NetBox 3.7 to 4.7. The version is detected on every run from the API-Version header, and requests are adapted to it.
Connecting
Save the connection on Integrations → NetBox (integrations.manage), or set the environment (configuration reference). A saved setting replaces the environment (except the two intervals) until you delete it.
| Setting | Variable | |
|---|---|---|
| URL | STRUCTAM_NETBOX_URL | https://netbox.example.com |
| Read token | STRUCTAM_NETBOX_TOKEN (or _FILE) | v1 (40 hex characters) or v2 (nbt_<key>.<secret>) |
| Webhook secret | STRUCTAM_NETBOX_WEBHOOK_SECRET (or _FILE) | verifies X-Hook-Signature; without it webhooks are refused |
| TLS | STRUCTAM_NETBOX_VERIFY_TLS, STRUCTAM_NETBOX_CA_FILE | a private CA replaces the system roots |
| Filters | STRUCTAM_NETBOX_DEVICE_FILTER, STRUCTAM_NETBOX_VM_FILTER | NetBox query strings, for example status=active&tenant=noc |
The read token needs view on dcim.device, dcim.interface, dcim.site, dcim.platform, dcim.devicerole, ipam.ipaddress, tenancy.tenant, extras.tag, virtualization.virtualmachine, virtualization.vminterface and virtualization.cluster. Test it with Test connection, or:
structam netbox test # both tokens, the version, and whether NetBox's rq workers run (webhooks need them)
structam netbox status # configuration source, last runs, host and drift countsTokens are sealed in the database, never returned by the API, and bound to the URL and TLS settings they were saved with: changing the URL, turning verification off or trusting another CA needs the tokens again, so nobody with integrations.manage can point a saved token at a server they control.
Sync
| Task | When | What |
|---|---|---|
| full sync | every STRUCTAM_NETBOX_SYNC_INTERVAL (15 min) | every device and virtual machine, their interfaces and addresses, sites, tenants, platforms, roles, clusters and tags; prune; drift |
| poll | every STRUCTAM_NETBOX_POLL_INTERVAL (60 s) | objects changed since the last poll, with a 60 s overlap |
| webhooks | as NetBox sends them | "re-read object N" hints, drained every 2 s |
One node at a time runs each task. Webhooks only speed things up: NetBox never retries them, so the poll finds every change anyway. Objects are always re-read from the API with Structam's own token; a webhook body is never trusted. Hosts are written in batches of at most 100. Every run that did something is listed on Integrations → NetBox and audited as netbox.sync. Run a full sync now with Sync now or:
structam netbox sync # the node holding the sync task runs it; -here runs it in this process
structam netbox runs -n 10What a sync changes:
- Identity fields (name, site, tenant, role, status, tags, primary IPs and so on) of each host, keyed by NetBox type and id. A field NetBox did not send keeps its value; a field NetBox sends empty clears it, because a tag that is gone must stop granting scoped access. A change to name, site, tenant, role, status, tags or primary IP is a
host.identity_changedchange event. - Prune (
STRUCTAM_NETBOX_PRUNE=decommission, the default): a host NetBox no longer returns, or whose status isdecommissioning, becomesdecommissioned. Hosts are never deleted. A full run that saw no host, or would decommission more than half of 10 or more managed hosts, refuses to prune (statusrefused).noneturns pruning off. Hosts outside the device and VM filters count as gone from NetBox. - Merges: an unmatched host (one an agent created) that NetBox now has is merged into the NetBox host. Its change events stay with it, because they are hash-chained; the NetBox host's timeline shows both.
Matching agents to hosts
When an agent enrols, and when a sync looks at unmatched hosts, these rules are tried, strongest first:
- the join token's bound host (a token made with Onboard this host);
- NetBox custom field
structam_agent_idequal to the agent's id; - DMI serial number (placeholders such as
To Be Filled By O.E.M.do not count); - an agent IP address equal to a NetBox interface address;
- a MAC address equal to a NetBox interface MAC;
- name, FQDN or short name, case-insensitive (a name matching several NetBox objects is ambiguous).
If two rules point at different hosts, or one rule matches several, nothing binds: the agent waits under Agents → Unmatched with the candidates. Loopback, link-local and multicast addresses, the Docker and Podman default bridges (172.17.0.0/16, 10.88.0.0/16) and zero or broadcast MACs are not evidence. A host that already has a live agent is never picked (drift agent.duplicate_claim is recorded instead), nor one whose agent was revoked unless the token is bound to it, nor one outside the join token's scope. Matching by hand on the Agents page is audited.
Drift
Each full run recomputes the findings on Integrations → NetBox → Drift, filtered by your host scope:
| Kind | Meaning |
|---|---|
agent.hostname_mismatch | the agent's host name differs from NetBox's |
agent.ip_not_in_netbox | the agent reports an address NetBox does not list for the host |
agent.serial_mismatch | the DMI serial differs from NetBox's |
agent.platform_mismatch | the observed OS family differs from the NetBox platform |
agent.duplicate_claim | a second agent claims a host that has a live agent |
host.no_agent | an active NetBox host matching STRUCTAM_NETBOX_EXPECT_AGENT_FILTER has had no agent for 24 h |
ip.not_in_netbox | discovery found an unmatched address that no NetBox host holds (discovery) |
STRUCTAM_NETBOX_EXPECT_AGENT_FILTER is * (every active host) or keys site, tenant, role, platform, tag, status and type (device or vm), for example role=server&tag=linux. Empty turns host.no_agent off.
Webhooks
structam netbox bootstrap -webhook # creates the webhook and its event rule in NetBox (needs the write token)This creates a webhook to https://structam.example.com/api/v1/ingest/netbox (your public URL) with the webhook secret, and an event rule on devices, virtual machines, interfaces, VM interfaces, IP addresses and (on 4.2 and later) MAC addresses for create, update and delete. To set it up by hand: method POST, content type application/json, the same URL and secret. Requests are verified with HMAC-SHA512 over the raw body (X-Hook-Signature) before the body is read, and limited to 4 MiB.
Write-back (optional)
With STRUCTAM_NETBOX_WRITEBACK=on (or the setting) and a separate write token, Structam keeps its own custom fields on devices and virtual machines up to date (group Structam, not editable in the NetBox UI):
| Field | Type | Written when |
|---|---|---|
structam_agent_id | text | the agent changes |
structam_agent | select: online, offline, never, revoked | the state changes |
structam_last_seen | date | at most once a day |
structam_url | URL | the host's Structam page changes |
structam_os | text | the observed OS changes |
structam_pending_changes | integer | it crosses 0 or changes by 10 or more |
Every NetBox write bumps last_updated, writes a changelog entry and fires event rules, so Structam writes only on these transitions, every 60 s, in bulk requests of up to 100 objects. With STRUCTAM_NETBOX_JOURNAL=on, approved and rejected high-severity changes also become journal entries, at most 10 per host per hour. Webhook events caused by the write token's user are dropped, so write-back never feeds itself. Structam edits no other NetBox field.
Create the fields first:
structam netbox bootstrap # custom fields and their choice set (idempotent)The write token needs change on dcim.device and virtualization.virtualmachine and add on extras.journalentry. Bootstrap also needs add and change on extras.customfield and extras.customfieldchoiceset, and with -webhook add on extras.webhook and extras.eventrule.
Discovery proposals
NetBox prefixes tagged structam-discover are cached by the full sync and proposed on Discovery as sweep targets. They are never swept on their own (discovery).
Access through NetBox attributes
Scoped role grants match hosts by NetBox site, tenant and tags with the prefix STRUCTAM_RBAC_TAG_PREFIX (structam-). Whoever can edit those attributes in NetBox decides which scoped Structam users see a host (access control).
Questions the docs do not answer?
Ask the people who build Structam. Installation media and licences come from KazLabs.