Feature: Add Site, SiteGroup, and Region as assignment targets with inheritance#115
Open
berlikm wants to merge 9 commits into
Open
Conversation
This was referenced Jul 13, 2026
berlikm
force-pushed
the
feature/site-region-inheritance
branch
3 times, most recently
from
July 14, 2026 13:22
5805bbe to
9533362
Compare
Adds Site, SiteGroup, and Region as valid assignment targets for all ZabbixServerAssignment, ZabbixHostgroupAssignment, ZabbixTemplateAssignment, ZabbixTagAssignment, ZabbixMacroAssignment, and ZabbixHostInventory objects. This allows assignments made at the Site/SiteGroup/Region level to be inherited by all devices and VMs at that site or below, via the existing inheritance_chain mechanism. Changes: - Constants: Site/SiteGroup/Region added to ASSIGNMENT_MODELS, ASSIGNMENT_TYPE_TO_FIELD, PATH_LABELS - Forms: All 7 assignment forms get Site/SiteGroup/Region DynamicModelChoiceField + FieldSet - Settings: inheritance_chain extended with Site/SiteGroup/Region resolution paths - Jobs: SyncHostJob._prepare_assignment() creates detached copies for inherited assignments - HostSync: _get_sync_target() resolves actual Device/VM for Jinja2 rendering - HostSync: get_tag_attributes() deduplicates tags by (tag, value) to prevent Zabbix 7 rejecting duplicate pairs inherited from multiple sources - HostInterfaceSync: get_create_params() falls back to the device's primary IP when the interface has no IP assigned (e.g. when inherited from SiteGroup) - HostInterfaceSync: errors are caught per-interface so one failing interface does not prevent the remaining interfaces and templates from being synced - Inheritance: ConfigGroup interface expansion removed; interfaces are now resolved naturally via the inheritance chain with primary IP fallback - SyncBase: _is_inherited_copy guard prevents save()/update_sync_info() on inherited copies - Views: ZabbixSiteTabView, ZabbixSiteGroupTabView, ZabbixRegionTabView added - Tests: 9 new tests for inheritance resolution Tested: all 1076 existing tests pass. Verified end-to-end on dev NetBox.
- Filter inherited/direct ZabbixServerAssignment and ZabbixHostInterface by zabbixserver - Resolve ConfigGroup interface IP from primary_ip4/primary_ip6 - Add seen-set cycle guard to resolve_path
- Fixes silent dropping of Site/SiteGroup assignments
berlikm
force-pushed
the
feature/site-region-inheritance
branch
from
July 14, 2026 14:34
9533362 to
d5f56e8
Compare
Fixes inherited Site/SiteGroup/Region assignments reading custom fields from the intermediate object instead of the actual Device/VM.
berlikm
force-pushed
the
feature/site-region-inheritance
branch
from
July 14, 2026 15:01
d5f56e8 to
2a32715
Compare
This was referenced Jul 14, 2026
Author
|
This PR is part of the zero-touch provisioning feature set described in #121. Please see that issue for the full architecture and motivation. |
This was referenced Jul 14, 2026
…stinterfaces resolve_inherited_zabbix_assignments() returns OrderedDict for all collections (tags, macros, templates, hostinterfaces, hostgroups). Iterating an OrderedDict yields keys (integers), not values. This caused tags to be skipped entirely and templates to never attach. Add _get_all_objects() helper that handles both dict and list by checking for .values() attribute. Also pass object=sync_target to assigned_tag.render() so Jinja2 templates render against the actual device/VM, not the Role/Site. This fix belongs in PR OpensourceICTSolutions#115 because it changes resolve_inherited_zabbix_ assignments() to return OrderedDicts. PR OpensourceICTSolutions#113 (exclude_tag) and OpensourceICTSolutions#110 (device context) layer on top and inherit the fix.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 15, 2026
merge() now explicitly coerces inherited_map.values() to a list, so every
all_objects collection is guaranteed to be a plain list. HostSync consumers
read them directly via self.context.get('all_objects', {}).get(key, []) or [],
dropping the _get_all_objects dict/list shim entirely.
Adds test_get_template_attributes_reads_plain_list to guard against a
regression to dict-only access of all_objects collections.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
…ce context in tag render - Add 'or []' to all dict.get() calls on all_objects to handle None (from PR OpensourceICTSolutions#115 fix #A: normalize all_objects collections to lists) - Change assigned_tag.render() to render(object=sync_target) (from PR OpensourceICTSolutions#110: device context was reverted in exclusion commit)
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. From PR OpensourceICTSolutions#115 fix #A: normalize all_objects collections to lists.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. From PR OpensourceICTSolutions#115 fix #A: normalize all_objects collections to lists.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
berlikm
added a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 16, 2026
Add 'or []' to all dict.get() calls on all_objects to handle None. Mirrors PR OpensourceICTSolutions#115 fix #A.
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.
Summary
Adds Site, SiteGroup, and Region as first-class assignment targets for all nbxSync objects (ZabbixServerAssignment, ZabbixProxyAssignment, ZabbixTagAssignment, etc.). Devices and VMs inherit assignments from their Site → SiteGroup → Region chain.
What this enables
CH) → all devices in all Swiss sites inherit it automatically.Changes
limit_choices_tofor Site/SiteGroup/Region/DeviceRole/Platform/Manufacturer/DeviceType/Cluster/ClusterTypeinheritance_chainsetting with 24 paths (full Device → Site → SiteGroup → Region → Role → Platform → Manufacturer → DeviceType chain)resolve_inherited_zabbix_assignments()ininheritance.py— resolves all assignment types from the chain, nearest-to-farthest, with deduplication0013adds expanded assignment choicesMigration
Dependencies
Base PR — all other PRs in #121 depend on this. Merge first.
Testing
All existing tests pass. E2E verified on dev NetBox + Zabbix 7.0.28: country-level proxy assignment correctly inherited by all devices under all sites in that country.
Part of #121.