Add orphaned_device_status and orphaned_vm_status config options#514
Open
berlikm wants to merge 1 commit into
Open
Add orphaned_device_status and orphaned_vm_status config options#514berlikm wants to merge 1 commit into
berlikm wants to merge 1 commit into
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.
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