Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete disabled hosts #8

Open
paalbra opened this issue Jun 9, 2020 · 0 comments
Open

Delete disabled hosts #8

paalbra opened this issue Jun 9, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@paalbra
Copy link
Contributor

paalbra commented Jun 9, 2020

Hosts are currently just disabled when removed and not deleted. This will lead to piling of disabled hosts.

for hostname in hostnames_to_remove:
if self.stop_event.is_set():
logging.debug("Told to stop. Breaking")
break
zabbix_host = zabbix_hosts[hostname]
self.disable_host(zabbix_host)

def disable_host(self, zabbix_host):
if not self.dryrun:
try:
disabled_hostgroup_id = self.api.hostgroup.get(filter={"name": "All-auto-disabled-hosts"})[0]["groupid"]
self.api.host.update(hostid=zabbix_host["hostid"], status=1, templates=[], groups=[{"groupid": disabled_hostgroup_id}])
logging.info("Disabling host: '%s' (%s)", zabbix_host["host"], zabbix_host["hostid"])
except pyzabbix.ZabbixAPIException as e:
logging.error("Error when disabling host '%s' (%s): %s", zabbix_host["host"], zabbix_host["hostid"], e.args)
else:
logging.info("DRYRUN: Disabling host: '%s' (%s)", zabbix_host["host"], zabbix_host["hostid"])

Possible enhancement could be adding the hosts to some kind of "deathrow" group that gets deleted at a later point.

E.g. this is week 2020-W24. If a two week buffer is enough a disabled host could be added to host group DeathRow-2020-W26 and be deleted when we arrive in 2020-W26. If a host gets enabled before this week they should be removed from the "deathrow" host group.

@paalbra paalbra added the enhancement New feature or request label Jun 9, 2020
@paalbra paalbra added the good first issue Good for newcomers label Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant