Skip to content

[Bug] Two bugs in syncmaintenance: missing zabbixserver attribute + invalid "day" parameter for non-MONTHLY timeperiods (Zabbix 7.x) #107

Description

@itirel-sdeau50

Environment

  • nbxsync: 1.0.4
  • NetBox: 5.2.13
  • Zabbix: 7.4

Bug 1 — SyncMaintenceJob crashes immediately: missing self.zabbixserver

Traceback

AttributeError: 'SyncMaintenceJob' object has no attribute 'zabbixserver'
File "nbxsync/jobs/syncmaintenance.py", line 12, in run
if not self.zabbixserver.sync_enabled:

Root cause

SyncMaintenceJob.__init__ sets self.instance but never initializes self.zabbixserver, which is used immediately in run().

Fix

def __init__(self, **kwargs):
    self.instance = kwargs.get('instance')
    self.zabbixserver = self.instance.zabbixserver  # missing line

Bug 2 — get_timeperiods() sends day parameter for all timeperiod types, rejected by Zabbix 7.x API

Traceback

zabbix_utils.exceptions.APIRequestError: Invalid params.
Invalid parameter "/1/timeperiods/1": unexpected parameter "day".

Root cause

In maintenancesync.py, the final block in get_timeperiods() unconditionally adds day or dayofweek to every timeperiod regardless of type:

if not timeperiod.dayofweek:
    timeperiod_result['day'] = timeperiod.day
else:
    ...

The day parameter is only valid for MONTHLY timeperiods in the Zabbix API. For ONE_TIME periods (used by [AUTOMATIC] maintenances created via status mapping), Zabbix 7.x rejects it.

Fix

if timeperiod.timeperiod_type == ZabbixTimePeriodTypeChoices.MONTHLY:
    if not timeperiod.dayofweek:
        timeperiod_result['day'] = timeperiod.day
    else:
        timeperiod_result['dayofweek'] = 0
        for x in timeperiod.dayofweek:
            timeperiod_result['dayofweek'] |= x

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