Add orphaned_device_status and orphaned_vm_status config options - #514
Merged
Merged
Conversation
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.
semx
reviewed
Sep 9, 2026
semx
left a comment
Collaborator
There was a problem hiding this comment.
Verified: merges onto development, suite green, and the two options are unset by default. One part is not behind them, though: the "restore status to active" block in inventory.py runs for every previously orphaned device or VM that reappears, whether or not orphaned_device_status/orphaned_vm_status is configured. Today such an object keeps whatever status it has (a user may have set planned or offline deliberately); with this change it is forced back to active on the next run. Could you only restore the status when the corresponding option is set, i.e. when it was netbox-sync that changed it? With that the default path stays unchanged and I can take it.
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 isdecommissioning.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 stringsmodule/netbox/inventory.py: Status change logic intag_all_the_things(), guarded byprune_enabledsettings-example.ini: Documentation for both optionsDesign: Why the
prune_enabledguardThe status change is only applied when
prune_enabledisTrue. This is critical for source failure protection.When a source (e.g., vCenter) becomes unreachable,
netbox-sync.pyalready disables pruning: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 todecommissioningduring a transient source outage would cause downstream systems to remove monitoring for ALL affected devices/VMs — exactly when monitoring is most needed.The
prune_enabledguard ensures:decommissioningactiveWithout this guard, a vCenter outage could silently decommission hundreds of VMs, removing them from monitoring systems at the worst possible moment.
Scope
NBDeviceandNBVM— other prunable objects (interfaces, IPs, MAC addresses, etc.) do not have astatusfielddata_modelallowed-values list inobject_classes.pyTesting
prune_enabled=True-> status changes to configured valueprune_enabled=False(source down) -> status NOT changed, monitoring preserved{"value": "...", "label": "..."})decommissioning->activewhen VM reappearsdecommissioningconfirmed as valid status for bothNBVMandNBDevicedata modelsConfig example