Skip to content

Feature: Zero-touch Zabbix provisioning via NetBox site inheritance + regex template rules #121

Description

@berlikm

Motivation

In deployments with hundreds or thousands of devices across multiple sites, configuring per-device Zabbix assignments (proxy, templates, tags, hostgroups, interfaces) does not scale. We need zero-touch provisioning: when a device or VM appears in NetBox (via netbox-sync, NAPALM, or manual entry), it should automatically be synced to Zabbix with the correct proxy, templates, tags, hostgroups, and interface — without any per-device configuration in nbxSync.

Problem

nbxSync currently requires a ZabbixServerAssignment (proxy) on every individual device or VM. For 2,000+ devices across 20+ sites, this means 2,000+ manual assignments. Similarly, templates need to be assigned per-platform, but platforms are dynamic — vCenter creates dozens of variants (e.g. "Windows Server 2022 (Build 20348.5400)") that all need the same Zabbix template.

Proposed Solution

A set of features that work together to achieve zero-touch provisioning:

1. Site-level inheritance (PR #115)

Assignments (proxy, templates, tags, hostgroups, interfaces, inventory) made at the Site, SiteGroup, or Region level are inherited by all devices and VMs at that site or below. This means:

  • One ZabbixServerAssignment per site → all devices at that site get the correct Zabbix proxy
  • One ZabbixHostgroupAssignment per site → all devices inherit the site hostgroup
  • SiteGroup parent traversal → assignments on a parent SiteGroup (e.g. "CH") are inherited by all child sites (e.g. "CH-STA-L26")

Example: Assigning a proxy to SiteGroup "CH" covers all Swiss sites. A new site "CH-STA-L99" automatically inherits the proxy when it's created — no configuration needed.

2. Regex-based template rules (PRs #117, #118, #119)

A ZabbixTemplateRule model that matches the device's platform name against a regex pattern and automatically assigns the correct Zabbix template (+ optionally hostgroup and tag). This solves the platform-variant explosion:

  • Pattern Windows matches "Windows Server 2019", "Windows Server 2022 (Build 20348.5400)", etc.
  • Pattern Ubuntu|Debian|Linux matches all Linux variants
  • Each rule can also assign a hostgroup (e.g. "Windows") and a tag (e.g. os_family=Windows) in the same rule

Rules include a 2-second regex timeout to prevent catastrophic backtracking (ReDoS), with patterns validated at save time.

3. Device-context Jinja2 rendering (PRs #110, #111)

When tags and hostgroups are inherited from a Site, Platform, or Role, Jinja2 templates are now rendered against the actual device/VM (not the Site or Role). This enables:

  • environment tag that detects Prod/Dev/QA from the device name pattern
  • critical tag that reads the device's NetBox native tag
  • Hostgroup values like {{ object.name }} that resolve to the device name

4. Tag-based host exclusion (PR #113)

A do_not_monitor tag (configurable via exclude_tag setting) assigned to any object in the inheritance chain (Role, Platform, Site, etc.) excludes the host from sync entirely. Previously-synced hosts are deleted from Zabbix. Useful for excluding device classes that should never be monitored (e.g. 1,400 desktop PCs).

5. Additional fixes (PRs #112, #114, #116)

Architecture

Device/VM appears in NetBox (via netbox-sync, NAPALM, etc.)
    |
nbxSync resolves via get_assigned_zabbixobjects():
    Layer 1 (regex rule): Platform "Windows" -> template + hostgroup + tag
    Layer 2 (role): Role "MSSQL" -> template + hostgroup + tag
    Layer 3 (site): Site "CH-ZRH-ZH4" -> proxy + hostgroup + interface
    Layer 4 (site group): Parent SiteGroup "CH" -> proxy (if not on site)
    |
    _is_excluded() -- checks do_not_monitor tag -> skip if present
    |
HostSync -- POST to Zabbix with:
    Templates (from regex rules + role assignments)
    Tags (rendered with device context, deduplicated)
    Hostgroups (from site + role + regex rules)
    Interface (cloned from ConfigGroup with device's primary IP)
    Proxy (inherited from Site/SiteGroup)
    Inventory (from Platform)

Our Use Case

We operate ~2,000 devices across 23 sites in 6 countries. We use:

  • Site-level proxy assignments (one per site, inherited by all devices)
  • ZabbixTemplateRule for OS-family template matching (Windows, Linux, EXOS, IQ Engine, FortiOS, ESXi)
  • do_not_monitor tag on the "Desktop PC" role to exclude 1,400 PCs
  • Jinja2 environment tag for Prod/Dev/QA detection from device name patterns
  • ConfigGroup at SiteGroup level for SNMP/agent interfaces

PRs

PR Title Review order
#115 Site, SiteGroup, Region as assignment targets with inheritance 1st (foundation)
#116 ConfigGroupAssignment form for Site/SiteGroup/Region 2nd (independent)
#117 ZabbixTemplateRule: regex-based template assignment 2nd (independent)
#118 Fix ZabbixTemplateRule: create wrapper 3rd (after #117)
#119 Extend ZabbixTemplateRule: hostgroup + tag 4th (after #118)
#110 Pass device context to tag render 3rd (after #115)
#111 Render tag values with device context in ObjectViewTable 4th (after #110)
#112 SiteGroup parent traversal 3rd (after #115)
#113 Tag-based host exclusion (exclude_tag) 3rd (after #115)
#114 Neutral indicator for inherited sync status 3rd (after #115)

Recommended review order: #115 first, then #116/#117 independently, then the rest in dependency order.

After #115 is merged, dependent PRs can be rebased on development to show only their own commits.

Testing

All PRs have been tested end-to-end on our dev NetBox + Zabbix 7.0.28:

  • Device sync: proxy, hostgroups, tags, and interface correctly inherited from Site/SiteGroup
  • VM sync: regex template rule matched "Windows" platform, assigned template + hostgroup + tag
  • Jinja2 tags rendered with device context (environment tag detected from VM name)
  • Exclusion: do_not_monitor tag correctly excludes host from sync and deletes existing Zabbix host
  • SiteGroup parent inheritance: device inherits proxy from parent SiteGroup

All 1,076 existing tests pass + 24 new tests across the PRs.

We're happy to adjust the approach based on feedback. The goal is to reduce per-device configuration to zero while staying within nbxSync's existing patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions