Repository navigation
Conversation
fix: keep untracked host interfaces when flipping the default interface
This branch has not been deployed
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.
fix: keep untracked host interfaces when flipping the default interface
Related to #97.
Problem
HostSync.check_default_hostinterface()flips the default ("main") interface with a single atomic call:desired_hostinterfacesis built exclusively fromZabbixHostInterfaceobjects known to NetBox. Zabbix, however, treats theinterfacesproperty ofhost.update()as the complete, authoritative list: any interface currently on the host but absent from it is deleted. An interface that still carries items cannot be deleted, so Zabbix rejects the entire call:This affects any host that existed in Zabbix before being adopted by nbxsync — i.e. an existing host taken over by pre-filling
ZabbixServerAssignment.hostid. The plugin has no record of the existing interface, so it creates a second one as non-main, and from then on tries to promote its own interface by sending a list that silently omits the original.Two properties make this worse than a single failed API call:
The host never syncs at all.
check_default_hostinterface()runs first inSyncHostJob.run(), beforesync_host(). The exception propagates throughrun_zabbix_operation()and aborts the job, so host name, templates, macros and tags are never pushed. From the outside it looks like the sync runs but does nothing.It cannot recover. The branch is guarded by
nb_default_id != zbx_default_id. NetBox's interface can only become main through the very call being rejected, so the condition stays true and the identical error repeats every interval indefinitely.Change
Carry the interfaces NetBox doesn't know about along in the payload instead of dropping them, demoted to
main=0where NetBox supplies the default for that type. Removing stale interfaces is alreadyverify_hostinterfaces()'s responsibility; this method should only flip the main flag.zabbix_hostinterfacesis already fetched at the top of the method, so no additional API call is made.Behaviour is unchanged for hosts created by the plugin itself: they have no interfaces outside NetBox's view, the added loop appends nothing, and the payload is identical to before.
Verification
Reproduced and fixed against nbxsync 1.0.5, NetBox 4.6.8, Zabbix 7.0.30, on 6 SNMP hosts that had been created manually in Zabbix and were later taken over by nbxsync. Before: the same error on every scheduled run for ~20 hours,
last_sync_state: falseon all 6. After:Synchronization successfulon the next run, host names and templates pushed as configured, duplicate interfaces cleaned up byverify_hostinterfaces(), item history preserved. Still green three days and ~70 job runs later.The two hosts on the same server that had been created by the plugin were unaffected throughout, before and after.