Skip to content

Add orphaned_device_status and orphaned_vm_status config options#514

Open
berlikm wants to merge 1 commit into
bb-Ricardo:developmentfrom
berlikm:feature/orphaned-status-dev
Open

Add orphaned_device_status and orphaned_vm_status config options#514
berlikm wants to merge 1 commit into
bb-Ricardo:developmentfrom
berlikm:feature/orphaned-status-dev

Conversation

@berlikm

@berlikm berlikm commented Jul 10, 2026

Copy link
Copy Markdown

Closes #458

Summary

Adds two new config options to automatically set the NetBox status of orphaned devices and VMs, as discussed in #458.

When a device/VM is orphaned (no longer reported by its source), the status is changed to the configured value (e.g., decommissioning). This enables downstream systems (like Zabbix monitoring via nbxSync) to react to the status change — for example, removing the host from monitoring when the status is decommissioning.

When an orphaned object reappears in a source, the status is restored to active.

Changes

  • module/netbox/config.py: Two new config options (orphaned_device_status, orphaned_vm_status), both optional strings
  • module/netbox/inventory.py: Status change logic in tag_all_the_things(), guarded by prune_enabled
  • settings-example.ini: Documentation for both options

Design: Why the prune_enabled guard

The status change is only applied when prune_enabled is True. This is critical for source failure protection.

When a source (e.g., vCenter) becomes unreachable, netbox-sync.py already disables pruning:

if source.settings.enabled and not source.init_successful:
    prune_enabled = False
    log.warning(f"disabling pruning as source {source.name} is unavailable")

However, the orphaned tagging in tag_all_the_things() still runs regardless — all objects from the unavailable source get the "orphaned" tag. Without the guard, changing the status to decommissioning during a transient source outage would cause downstream systems to remove monitoring for ALL affected devices/VMs — exactly when monitoring is most needed.

The prune_enabled guard ensures:

Scenario Tag added? Status changed? Monitoring impact
Source down (temporary) Yes (existing behavior) No (guard blocks) None — monitoring continues
Source healthy, VM genuinely deleted Yes Yes - to decommissioning Downstream removes host
VM reappears in source Tag removed Restored to active Downstream re-enables

Without this guard, a vCenter outage could silently decommission hundreds of VMs, removing them from monitoring systems at the worst possible moment.

Scope

  • Only affects NBDevice and NBVM — other prunable objects (interfaces, IPs, MAC addresses, etc.) do not have a status field
  • Config options are optional — if unset, behavior is unchanged (backward compatible)
  • Status values are validated by the existing data_model allowed-values list in object_classes.py

Testing

  • Config parsing verified: both options parse correctly from YAML
  • Regex matching verified: cluster name patterns match correctly
  • Guard logic verified via simulation:
    • prune_enabled=True -> status changes to configured value
    • prune_enabled=False (source down) -> status NOT changed, monitoring preserved
  • Dict-style status handling verified (NetBox API returns {"value": "...", "label": "..."})
  • Un-orphaning restore verified: decommissioning -> active when VM reappears
  • decommissioning confirmed as valid status for both NBVM and NBDevice data models

Config example

netbox:
  orphaned_device_status: decommissioning
  orphaned_vm_status: decommissioning

Closes bb-Ricardo#458

Adds two new config options to automatically set the NetBox status of
orphaned devices and VMs. When a device/VM is orphaned (source no
longer reports it), the status is changed to the configured value
(e.g. 'decommissioning'). When the object reappears in a source,
the status is restored to 'active'.

The status change is guarded by prune_enabled — if a source is
unavailable (failed to initialize), pruning is disabled which prevents
the status change. This protects against false decommissioning during
transient source outages.

Only affects NBDevice and NBVM — other prunable objects (interfaces,
IPs, etc.) don't have a status field.
@berlikm berlikm requested a review from bb-Ricardo as a code owner July 10, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant