From bcf7f191a826d5e278344a1d3891c9765cd3901f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Wed, 25 Oct 2023 22:37:40 +0200 Subject: [PATCH] Chore: Add devenv for Zabbix 7 --- devenv/zabbix70/bootstrap/Dockerfile | 17 + devenv/zabbix70/bootstrap/bootstrap_config.py | 80 ++++ .../zabbix70/bootstrap/zbx_export_hosts.xml | 432 ++++++++++++++++++ devenv/zabbix70/docker-compose.yml | 119 +++++ 4 files changed, 648 insertions(+) create mode 100644 devenv/zabbix70/bootstrap/Dockerfile create mode 100644 devenv/zabbix70/bootstrap/bootstrap_config.py create mode 100644 devenv/zabbix70/bootstrap/zbx_export_hosts.xml create mode 100644 devenv/zabbix70/docker-compose.yml diff --git a/devenv/zabbix70/bootstrap/Dockerfile b/devenv/zabbix70/bootstrap/Dockerfile new file mode 100644 index 000000000..da6457fd1 --- /dev/null +++ b/devenv/zabbix70/bootstrap/Dockerfile @@ -0,0 +1,17 @@ +FROM python:2.7 + +ENV ZBX_API_URL=http://zabbix-web:8080 +ENV ZBX_API_USER="Admin" +ENV ZBX_API_PASSWORD="zabbix" +ENV ZBX_CONFIG="zbx_export_hosts.xml" +ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py" + +RUN pip install pyzabbix + +ADD ./bootstrap_config.py /bootstrap_config.py +ADD ${ZBX_CONFIG} /${ZBX_CONFIG} + +WORKDIR / + +# Run bootstrap_config.py when the container launches +CMD ["python", "/bootstrap_config.py"] diff --git a/devenv/zabbix70/bootstrap/bootstrap_config.py b/devenv/zabbix70/bootstrap/bootstrap_config.py new file mode 100644 index 000000000..650a3f0d3 --- /dev/null +++ b/devenv/zabbix70/bootstrap/bootstrap_config.py @@ -0,0 +1,80 @@ +import os +from time import sleep +from pyzabbix import ZabbixAPI, ZabbixAPIException + +zabbix_url = os.environ['ZBX_API_URL'] +zabbix_user = os.environ['ZBX_API_USER'] +zabbix_password = os.environ['ZBX_API_PASSWORD'] +print(zabbix_url, zabbix_user, zabbix_password) + +zapi = ZabbixAPI(zabbix_url, timeout=5) + +for i in range(10): + print("Trying to connected to Zabbix API %s" % zabbix_url) + try: + zapi.login(zabbix_user, zabbix_password) + print("Connected to Zabbix API Version %s" % zapi.api_version()) + break + except ZabbixAPIException as e: + print e + sleep(5) + except: + print("Waiting") + sleep(5) + + +config_path = os.environ['ZBX_CONFIG'] +import_rules = { + 'discoveryRules': { + 'createMissing': True, + 'updateExisting': True + }, + 'graphs': { + 'createMissing': True, + 'updateExisting': True + }, + 'host_groups': { + 'createMissing': True + }, + 'hosts': { + 'createMissing': True, + 'updateExisting': True + }, + 'images': { + 'createMissing': True, + 'updateExisting': True + }, + 'items': { + 'createMissing': True, + 'updateExisting': True + }, + 'maps': { + 'createMissing': True, + 'updateExisting': True + }, + 'templateLinkage': { + 'createMissing': True, + }, + 'templates': { + 'createMissing': True, + 'updateExisting': True + }, + 'triggers': { + 'createMissing': True, + 'updateExisting': True + }, +} + +print("Importing Zabbix config from %s" % config_path) +with open(config_path, 'r') as f: + config = f.read() + + try: + # https://github.com/lukecyca/pyzabbix/issues/62 + import_result = zapi.confimport("xml", config, import_rules) + print(import_result) + except ZabbixAPIException as e: + print e + +for h in zapi.host.get(output="extend"): + print(h['name']) diff --git a/devenv/zabbix70/bootstrap/zbx_export_hosts.xml b/devenv/zabbix70/bootstrap/zbx_export_hosts.xml new file mode 100644 index 000000000..8b1ddb776 --- /dev/null +++ b/devenv/zabbix70/bootstrap/zbx_export_hosts.xml @@ -0,0 +1,432 @@ + + + 6.2 + 2022-04-28T13:04:18Z + + + 2e427c268ac1468b9add94b65e2d6c14 + Backend + + + d97ba66b283544339628b71975a6e68d + Frontend + + + dc579cd7a1a34222933f24f52a68bcd8 + Linux servers + + + 6f6799aa69e844b4b3918f779f2abf08 + Zabbix servers + + + 7df96b18c230490a9a0a9e2307226338 + Templates + + + + + backend01 + backend01 + + + + + + Backend + + + Linux servers + + + + + NO + zas_backend_01 + if1 + + + + + backend + + + service + backend + + + DISABLED + + + backend02 + backend02 + + + + + + Backend + + + Linux servers + + + + + NO + zas_backend_02 + if1 + + + + + backend + + + service + backend + + + DISABLED + + + frontend01 + frontend01 + + + + + + Frontend + + + Linux servers + + + + + NO + zas_frontend_01 + if1 + + + + + frontend + + + service + frontend + + + DISABLED + + + frontend02 + frontend02 + + + + + + Frontend + + + Linux servers + + + + + NO + zas_frontend_02 + if1 + + + + + frontend + + + service + frontend + + + DISABLED + + + Zabbix server + Zabbix server + + + + + + + Zabbix servers + + + + + NO + zabbix-agent + if1 + + + DISABLED + + + + + + + + 7aac0ec0c0e04b7a8bb6472d1faa7a09 + CPU load + FIXED + + + 009900 + + Template ZAS Agent + system.cpu.load[percpu,avg1] + + + + 2 + 990000 + + Template ZAS Agent + system.cpu.load[percpu,avg15] + + + + + + f25064d88b964a678fac7ea6095b238a + CPU utilization + NO + STACKED + FIXED + FIXED + + + 4 + FILLED_REGION + 999900 + + Template ZAS Agent + system.cpu.util[,iowait] + + + + 5 + FILLED_REGION + 990000 + + Template ZAS Agent + system.cpu.util[,system] + + + + 6 + FILLED_REGION + 000099 + + Template ZAS Agent + system.cpu.util[,user] + + + + + + diff --git a/devenv/zabbix70/docker-compose.yml b/devenv/zabbix70/docker-compose.yml new file mode 100644 index 000000000..eb3956017 --- /dev/null +++ b/devenv/zabbix70/docker-compose.yml @@ -0,0 +1,119 @@ +version: '3' + +services: + # Grafana + grafana: + image: grafana/grafana:10.1.2 + ports: + - '3001:3000' + volumes: + - ../..:/grafana-zabbix + - ../dashboards:/devenv/dashboards + - ../grafana.ini:/etc/grafana/grafana.ini:ro + - '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml' + - '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml' + + # Zabbix + zabbix-server: + image: zabbix/zabbix-server-pgsql:alpine-trunk + ports: + - '10051:10051' + depends_on: + - database + environment: + DB_SERVER_HOST: database + DB_SERVER_PORT: 5432 + POSTGRES_USER: zabbix + POSTGRES_PASSWORD: zabbix + POSTGRES_DB: zabbix + ZBX_TIMEOUT: 10 + ZBX_STARTPOLLERS: 10 + ZBX_STARTPOLLERSUNREACHABLE: 5 + ZBX_DEBUGLEVEL: 3 + + zabbix-web: + image: zabbix/zabbix-web-apache-pgsql:alpine-trunk + ports: + - '8188:8080' + depends_on: + - database + - zabbix-server + environment: + ZBX_SERVER_HOST: zabbix-server + ZBX_SERVER_PORT: 10051 + DB_SERVER_HOST: database + DB_SERVER_PORT: 5432 + POSTGRES_USER: zabbix + POSTGRES_PASSWORD: zabbix + POSTGRES_DB: zabbix + + database: + image: postgres:16 + ports: + - '15432:5432' + command: postgres -c 'max_connections=1000' + environment: + POSTGRES_USER: zabbix + POSTGRES_PASSWORD: zabbix + + zabbix-agent: + image: zabbix/zabbix-agent:alpine-trunk + environment: + ZBX_SERVER_HOST: zabbix-server + ZBX_SERVER_PORT: 10051 + + ######################################################### + # Bootstrap config + ######################################################### + + bootstrap: + build: ./bootstrap + environment: + ZBX_API_URL: http://zabbix-web:8080 + ZBX_API_USER: Admin + ZBX_API_PASSWORD: zabbix + depends_on: + - database + - zabbix-server + - zabbix-web + + ######################################################### + # Fake agents + ######################################################### + + # backend + redis_backend: + image: redis:alpine + + zas_backend_01: + build: ../zas-agent + volumes: + - ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg + environment: + REDIS_HOST: redis_backend + # restart: always + + zas_backend_02: + build: ../zas-agent + volumes: + - ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg + environment: + REDIS_HOST: redis_backend + + # frontend + redis_frontend: + image: redis:alpine + + zas_frontend_01: + build: ../zas-agent + volumes: + - ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg + environment: + REDIS_HOST: redis_frontend + + zas_frontend_02: + build: ../zas-agent + volumes: + - ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg + environment: + REDIS_HOST: redis_frontend