Inventory sync (NetBox)
A sync provider holds access to an external source such as NetBox. A versioned mapping configuration defines the entities, fields, and transforms; an on-demand job applies them to the inventory through extract → map → diff → upsert. For file-based import and export, see Inventory transfer.
Providers
Manage providers under Inventory → Sync. Click Add Provider and choose a type:
| Type | Configuration fields |
|---|---|
| NetBox | NetBox URL (required), API token (required, stored as a secret), Verify SSL |
| Custom API | Base URL (required), bearer token, auth header name |
Each provider has an enable switch, a Test Connection action (validates connectivity and configuration), and a status badge. The badge maps the backend operational status: ready shows as connected, degraded and bootstrap_failed show as error, anything else as disconnected. The Status tab also shows the last successful outbound write and the last error.
A NetBox provider record looks like:
{
"name": "netbox-main",
"provider_type": "netbox",
"is_enabled": true,
"config": {
"base_url": "https://netbox.example.com",
"page_size": 200,
"sync_mode": "pull_only"
}
}
sync_mode controls the direction of event-driven sync:
| Mode | Behaviour |
|---|---|
pull_only (default) | Piping reads from NetBox and accepts signed NetBox webhooks. Local inventory writes are never pushed back. |
bidirectional | Supported local writes are queued as outbound events and pushed to NetBox. Inbound webhooks still apply. |
Event-driven two-way sync currently covers NetBox dcim.site. Other NetBox models (devices, racks, IPs, VMs, tenants, and so on) are available to mapping configurations and sync jobs, but do not participate in the live two-way site flow. Keep only one enabled bidirectional NetBox provider per inventory scope.
Mapping configurations
Open Inventory → Sync → Mapping Configs. Each save creates a new immutable version. The list groups versions by configuration, marks the latest and opens older versions read-only ("Viewing vN — archived"). Concurrent saves return a conflict; the editor shows the author, changes and time of the newer version.
A configuration declares:
| Property | Values |
|---|---|
| Name | Display name |
| Provider | The sync provider it runs against |
| Direction | pull, push, or bidirectional |
| Conflict mode | netbox_wins, piping_wins, last_write_wins, field_level |
| Entity mappings | The list of source → target entity links |
Running jobs keep their pinned configuration version. The list and editor mark versions with active jobs.
Field mappings and transforms
An entity mapping links a source entity to a target entity, e.g. netbox.dcim.device → piping.inventory.device, and can be enabled or disabled per entity. Inside it, each field mapping has two slots:
- Forward transform — required; how the source value becomes the target value.
- Reverse transform — optional; without it the field is read-only in the target → source direction.
Transforms are expressions in a typed operator DSL, composed in the editor's Expression tab:
| Category | Operators |
|---|---|
| Identity / literal | identity, literal |
| String | concat, split_index, trim, lower, upper, template |
| Type | coerce |
| Lookup / reference | lookup, dereference |
| Normalization | date_format, tags_merge, mac_normalize, ipv4_prefix_canonical |
Only invertible operators may author a reverse transform; the API can suggest a matching reverse expression for a given forward transform. A field mapping can also be flagged round-trip critical, requiring the forward/reverse pair to reproduce the original value.
Preview and validation
The editor's Preview tab evaluates the selected entity mapping against a real sample record fetched from the provider (GET /api/v1/providers/{id}/sample-record?model=...). The preview returns the computed result plus blocking errors and non-blocking warnings — no inventory data is touched. A separate validation endpoint checks a whole set of entity mappings and returns structured diagnostics (code, message, path, severity).
Sync runs
Sync runs are started on demand — there is no built-in scheduler. From the provider's Status tab, enter a mapping version and click Sync Now, or call the API:
POST /api/v1/sync/jobs { "provider_id": "...", "mapping_version": "..." }
GET /api/v1/sync/jobs/{id}
GET /api/v1/sync/jobs/{id}/report
A job acquires a per-provider lock (one job per provider at a time), then runs extract → map → diff → upsert for each mapped resource. Job status is queued, running, completed, or failed; the report exposes per-run statistics.
Per-resource orphan handling decides what happens to records that exist on one side only: ignore, report, or delete. Treat delete as destructive.
Conflict policy
The conflict mode declared on a mapping configuration records the intended resolution policy:
| Mode | Intent |
|---|---|
netbox_wins | NetBox value overwrites Piping |
piping_wins | Piping value overwrites NetBox |
last_write_wins | Most recent change wins |
field_level | Resolve per field |
For the current event-driven dcim.site flow, same-field races between both sides are resolved by event processing order — the later applied inbound webhook or successful outbound write wins; no merge UI is involved. Use pull_only whenever NetBox is the source of truth, and enable bidirectional only when Piping is allowed to author the supported NetBox objects.
Live updates from NetBox
NetBox pushes changes to Piping via signed webhooks:
POST /api/v1/webhooks/netbox/{provider_id}
The handler verifies the x-hook-signature HMAC-SHA512 over the raw body, suppresses echoes of Piping-originated writes, deduplicates events, applies supported models, and records the outcome in the audit log. Raw webhook bodies are not persisted — only metadata and a body hash. Provider bootstrap (POST /api/v1/providers/{id}/bootstrap) creates or updates the webhook and event rule on the NetBox side when credentials allow.
In bidirectional mode, failed outbound pushes are retried and eventually moved to a dead-letter queue, visible through the provider status counters and requeueable via POST /api/v1/providers/{id}/outbox/replay.
REST API reference
| Method | Path | Purpose |
|---|---|---|
GET / POST | /api/v1/providers | List / create providers |
GET / PATCH / DELETE | /api/v1/providers/{id} | Read / update / delete a provider |
POST | /api/v1/providers/{id}/validate | Test connectivity and configuration |
GET | /api/v1/providers/{id}/status | Runtime status and outbox counters |
POST | /api/v1/providers/{id}/bootstrap | Create or update the NetBox webhook |
POST | /api/v1/providers/{id}/outbox/replay | Requeue dead-letter outbound events |
GET | /api/v1/providers/{id}/sample-record | Fetch a sample source record |
GET / POST | /api/v1/sync/mapping-configurations | List / create mapping configurations |
GET / PATCH / DELETE | /api/v1/sync/mapping-configurations/{id} | Read / version / delete a configuration |
POST | /api/v1/sync/mapping-configurations/preview | Preview a mapping against a sample record |
POST | /api/v1/sync/mapping-configurations/validate | Validate entity mappings |
POST | /api/v1/sync/mapping-configurations/suggest-reverse | Suggest a reverse transform |
GET | /api/v1/sync/operators | List transform DSL operators |
POST | /api/v1/sync/jobs | Start a sync job |
GET | /api/v1/sync/jobs/{id} | Read job status |
GET | /api/v1/sync/jobs/{id}/report | Read the job report |
POST | /api/v1/webhooks/netbox/{provider_id} | Receive signed NetBox webhooks |
See API reference for the full contract.