Zabbix-auto-config is an utility that aims to automatically configure hosts, host groups, host inventories and templates in the monitoring software Zabbix.
Note: This is only tested with Zabbix 5.0 LTS.
This is a crash course in how to quickly get this application up and running in a local test environment:
Setup a Zabbix test instance with podman and podman-compose.
TAG=alpine-5.0-latest ZABBIX_PASSWORD=secret podman-compose up -d
It is currently assumed that you have the following hostgroups in Zabbix. You should logon to Zabbix and create them:
- All-auto-disabled-hosts
- All-hosts
For automatic linking in templates you could create the templates:
- Template-barry
- Template-pizza
PGPASSWORD=secret psql -h localhost -U postgres -p 5432 -U zabbix << EOF
CREATE DATABASE zac;
\c zac
CREATE TABLE hosts (
data jsonb
);
CREATE TABLE hosts_source (
data jsonb
);
EOF
python3 -m venv venv
. venv/bin/activate
pip install -e .
cp config.sample.toml config.toml
sed -i 's/^dryrun = true$/dryrun = false/g' config.toml
mkdir -p path/to/source_collector_dir/ path/to/host_modifier_dir/ path/to/map_dir/
cat > path/to/source_collector_dir/mysource.py << EOF
import zabbix_auto_config.models
HOSTS = [
{
"hostname": "foo.example.com",
},
{
"hostname": "bar.example.com",
},
]
def collect(*args, **kwargs):
hosts = []
for host in HOSTS:
host["enabled"] = True
host["siteadmins"] = ["bob@example.com"]
host["properties"] = ["pizza"]
source = kwargs.get("source")
if source:
host["properties"].append(source)
hosts.append(zabbix_auto_config.models.Host(**host))
return hosts
if __name__ == "__main__":
for host in collect():
print(host.json())
EOF
cat > path/to/host_modifier_dir/mod.py << EOF
def modify(host):
if host.hostname == "bar.example.com":
host.properties.add("barry")
return host
EOF
cat > path/to/map_dir/property_template_map.txt << EOF
pizza:Template-pizza
barry:Template-barry
EOF
cat > path/to/map_dir/property_hostgroup_map.txt << EOF
other:Hostgroup-other-hosts
EOF
cat > path/to/map_dir/siteadmin_hostgroup_map.txt << EOF
bob@example.com:Hostgroup-bob-hosts
EOF
Run the application:
zac
You could run this as a systemd service:
[Unit]
Description=Zabbix auto config
After=network.target
[Service]
User=zabbix
Group=zabbix
WorkingDirectory=/home/zabbix/zabbix-auto-config
Environment=PATH=/home/zabbix/zabbix-auto-config/venv/bin
ExecStart=/home/zabbix/zabbix-auto-config/venv/bin/zac
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Zac manages only inventory properties configured as managed_inventory
in config.toml
. An inventory property will not be removed/blanked from Zabbix even if the inventory property is removed from managed_inventory
list or from the host in the source e.g:
- Add "location=x" to a host in a source and wait for sync
- Remove the "location" property from the host in the source
- "location=x" will remain in Zabbix