Feature: Add tag-based host exclusion via exclude_tag setting#113
Open
berlikm wants to merge 5 commits into
Open
Feature: Add tag-based host exclusion via exclude_tag setting#113berlikm wants to merge 5 commits into
berlikm wants to merge 5 commits into
Conversation
berlikm
force-pushed
the
feature/exclude-tag
branch
2 times, most recently
from
July 14, 2026 13:24
2d95ca4 to
e9b4ef1
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/exclude-tag
branch
2 times, most recently
from
July 14, 2026 14:48
91a5918 to
1bd513c
Compare
Fixes inherited Site/SiteGroup/Region assignments reading custom fields from the intermediate object instead of the actual Device/VM.
Adds a new exclude_tag plugin setting that allows excluding hosts from Zabbix sync entirely via a ZabbixTag assigned to any object in the inheritance chain (Role, Platform, Site, SiteGroup, Manufacturer, or directly on a Device/VM). When a ZabbixTagAssignment with a tag matching exclude_tag is present in the resolved assignments, SyncHostJob skips sync entirely. If the host was previously synced, it is deleted from Zabbix. The tag itself is filtered before Jinja2 rendering in get_tag_attributes(), so it never reaches Zabbix as a host tag. The setting defaults to '' (disabled), so existing deployments are unaffected. This follows the same pattern as no_alerting_tag — a signal tag that controls sync behavior without being pushed to Zabbix. Tested: 7 new tests covering exclusion enabled/disabled, tag present absent, and delete-on-exclude behavior. All 1092 existing tests pass.
berlikm
force-pushed
the
feature/exclude-tag
branch
from
July 14, 2026 15:01
1bd513c to
334ec6a
Compare
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 a commit
to berlikm/nbxsync
that referenced
this pull request
Jul 15, 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
# Conflicts: # nbxsync/utils/sync/hostsync.py
berlikm
force-pushed
the
feature/exclude-tag
branch
from
July 16, 2026 07:33
578ea5b to
334ec6a
Compare
Author
Conflict resolution note for rebaseWhen rebasing this PR after #115 lands, there will be a conflict in
Correct resolution: Combine both — keep the exclude_tag filtering from this PR, but use #115's exclude_tag = self.pluginsettings.exclude_tag
for assigned_tag in (self.context.get('all_objects', {}).get('tags', []) or []):
if exclude_tag and assigned_tag.zabbixtag.tag == exclude_tag:
continueVerified in the integration-test branch: 1135 tests pass, E2E confirmed. |
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 a new
exclude_tagplugin setting that allows excluding hosts from Zabbix sync entirely via aZabbixTagassigned to any object in the inheritance chain (Role, Platform, Site, SiteGroup, Manufacturer, or directly on a Device/VM).How it works
ZabbixTagwithtag='do_not_monitor'(or any name) and any valueDeviceRole(e.g. 'Desktop PC'),Platform,Site, or individualDevice/VirtualMachine'exclude_tag': 'do_not_monitor'inPLUGINS_CONFIGThe tag is filtered before Jinja2 rendering in
get_tag_attributes(), so it never reaches Zabbix as a host tag.Dependencies
Stacks on PR #115. Merge after #115.
Testing
7 new tests covering: exclusion disabled (default), tag present/absent, skip sync when excluded, delete on exclude, and no-delete when already decommissioned. All 1076 existing tests pass.
Part of #121.