Skip to content

Mapping files should be read on each work iteration instead of on startup #151

Description

@pederhan

Currently, the application needs to be restarted every time the mapping files change. This can be done via external listeners that trigger restarts on mapping file changes, but that is far from ideal.

We can solve this most easily by moving the relevant lines from read_map_file from __init__() to work():

self.property_template_map = utils.read_map_file(
os.path.join(self.zabbix_config.map_dir, "property_template_map.txt")
)
self.property_hostgroup_map = utils.read_map_file(
os.path.join(self.zabbix_config.map_dir, "property_hostgroup_map.txt")
)
self.siteadmin_hostgroup_map = utils.read_map_file(
os.path.join(self.zabbix_config.map_dir, "siteadmin_hostgroup_map.txt")
)

def work(self) -> None:
start_time = time.time()
logger.info("Zabbix update starting")
self.do_update()
logger.info(
"Zabbix update finished",
duration=time.time() - start_time,
next_update=self.next_update.isoformat(timespec="seconds"),
)

There are other ways to solve this, but this is the easiest. It does have some downsides:

  1. Subclasses could override work(), thereby losing these calls
  2. work() could become overloaded with such bootstrapping code in the long run.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions