unioslo / zabbix-auto-config

MIT License
2 stars 5 forks source link

Add host property tagging #67

Closed pederhan closed 2 weeks ago

pederhan commented 10 months ago

This PR adds the ability to automatically tag hosts with their source properties. The name of the tag and the properties to include are configurable with the following new configuration options:

[zabbix.property_tagging]
enabled = true
tag = "property"
include = []
exclude = []

The options include & exclude accept regular expressions which will be used to filter which properties are used for tagging. If no patterns are included, all properties are used.

The property tags are fully managed by ZAC, which means that if a source host loses a property, the corresponding property tag will also be removed in Zabbix.*

How it works

Given a host with the properties is_adfs_server and is_app_server , and the following configuration:

[zabbix]
tags_prefix = "zac_"

[zabbix.property_tagging]
enabled = true
tag = "property"

The host is given the following tags:

image

Including and excluding tags

If a host has a property called broken_server and we want to exclude it from being used as a tag, we can configure it like this:

exclude = ["broken_server"]

If we want to exclude all properties starting with broken_, we can add a wildcard pattern:

exclude = ["broken_.*"]

Or if we only want to include properties that follow the is_<type>_server pattern, we can use an include pattern:

include = ["is_.*_server"]

We can also combine include and exclude patterns to create more advanced filters:

include = ["is_.*_server"]
exclude = ["is_broken_server", "is_bad_server"]

*Whether or not a DB host can actually lose a property in practice is another question entirely though. I believe SourceMergerProcess.merge_hosts & Host.merge are not fully capable of determining when a host has had data removed; they can only add new data. That should be fixed in a future PR.

pederhan commented 2 weeks ago

Closing. #81 obsoletes a lot of code in this PR. Can revisit in the future.