Skip to content

Feature: Add Site, SiteGroup, and Region as assignment targets with inheritance#115

Open
berlikm wants to merge 9 commits into
OpensourceICTSolutions:developmentfrom
berlikm:feature/site-region-inheritance
Open

Feature: Add Site, SiteGroup, and Region as assignment targets with inheritance#115
berlikm wants to merge 9 commits into
OpensourceICTSolutions:developmentfrom
berlikm:feature/site-region-inheritance

Conversation

@berlikm

@berlikm berlikm commented Jul 13, 2026

Copy link
Copy Markdown

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

  • Assign a Zabbix proxy once on a country-level SiteGroup (e.g. CH) → all devices in all Swiss sites inherit it automatically.
  • Assign tags (owner, device_class) at the DeviceRole level → role-based tag propagation without per-device config.
  • Assign hostgroups at the Site level with Jinja2 templates.

Changes

  • Assignment models expanded with limit_choices_to for Site/SiteGroup/Region/DeviceRole/Platform/Manufacturer/DeviceType/Cluster/ClusterType
  • inheritance_chain setting with 24 paths (full Device → Site → SiteGroup → Region → Role → Platform → Manufacturer → DeviceType chain)
  • resolve_inherited_zabbix_assignments() in inheritance.py — resolves all assignment types from the chain, nearest-to-farthest, with deduplication
  • Form updates for assignment target selection
  • Migration 0013 adds expanded assignment choices

Migration

0013_alter_zabbixhostgroupassignment_assigned_object_type_and_more

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.

berlikm added 3 commits July 14, 2026 14:15
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
berlikm force-pushed the feature/site-region-inheritance branch from 9533362 to d5f56e8 Compare July 14, 2026 14:34
Fixes inherited Site/SiteGroup/Region assignments reading custom fields from
the intermediate object instead of the actual Device/VM.
@berlikm

berlikm commented Jul 14, 2026

Copy link
Copy Markdown
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.

berlikm added 3 commits July 14, 2026 23:31
…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
berlikm added 2 commits July 15, 2026 12:35
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.
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