Skip to content

Fix: Add SiteGroup parent traversal to inheritance chain#112

Closed
berlikm wants to merge 5 commits into
OpensourceICTSolutions:developmentfrom
berlikm:fix/sitegroup-parent-inheritance
Closed

Fix: Add SiteGroup parent traversal to inheritance chain#112
berlikm wants to merge 5 commits into
OpensourceICTSolutions:developmentfrom
berlikm:fix/sitegroup-parent-inheritance

Conversation

@berlikm

@berlikm berlikm commented Jul 13, 2026

Copy link
Copy Markdown

Summary

The inheritance chain included ('region', 'parent') for traversing the Region hierarchy, but had no equivalent for SiteGroup. A ZabbixServerAssignment on a parent SiteGroup (e.g. 'CH') was invisible to devices at sites in child groups (e.g. 'CH-STA-L26').

Fix

Add two new entries to the inheritance chain:

  • ('group', 'parent') — resolves SiteGroup.parent from any object that has a direct SiteGroup reference
  • ('site', 'group', 'parent') — resolves device.site.group.parent, traversing the full SiteGroup hierarchy

Also adds matching entries in PATH_LABELS and docs/configuration.md.

Files changed

  • nbxsync/__init__.py — Added ['group', 'parent'] and ['site', 'group', 'parent'] to default settings
  • nbxsync/settings.py — Added ('site', 'group', 'parent') to defaults
  • nbxsync/constants/path_labels.py — Added path labels
  • docs/configuration.md — Updated inheritance_chain example

Testing

All 1076 existing tests pass. Verified on dev NetBox — a device at site CH-STA-L26 inherits ZabbixServerAssignment from parent SiteGroup CH.

Dependencies

This PR is built on top of PR #115 (Site/Region inheritance). Once #115 is merged, this PR can be rebased to show only its own 1 commit.

@berlikm
berlikm force-pushed the fix/sitegroup-parent-inheritance branch 2 times, most recently from 9d32877 to d8c69ad Compare July 14, 2026 13:23
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 fix/sitegroup-parent-inheritance branch from d8c69ad to fac2951 Compare July 14, 2026 14:34
berlikm added 2 commits July 14, 2026 14:54
Fixes inherited Site/SiteGroup/Region assignments reading custom fields from
the intermediate object instead of the actual Device/VM.
The inheritance chain included ('region', 'parent') for traversing the
Region hierarchy, but had no equivalent for SiteGroup. A ZabbixServerAssignment
on a parent SiteGroup (e.g. 'CH') was invisible to devices at sites in
child groups (e.g. 'CH-STA-L26').

Adds ('group', 'parent') and ('site', 'group', 'parent') to the chain,
mirroring the existing ('region', 'parent') pattern. Updates path_labels
with matching labels.

Tested: all 1092 existing tests pass. Verified on dev NetBox — device
at site CH-STA-L26 now inherits ZabbixServerAssignment from SiteGroup CH.
@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

berlikm commented Jul 15, 2026

Copy link
Copy Markdown
Author

Closing in favor of PR #124 (recursive SiteGroup/Region/DeviceRole ancestry). PR #112's one-hop ('site', 'group', 'parent') traversal is fully replaced by _walk_ancestors which walks the full hierarchy recursively with cycle detection. Part of #121.

@berlikm berlikm closed this Jul 15, 2026
@berlikm
berlikm deleted the fix/sitegroup-parent-inheritance branch July 16, 2026 07:21
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