Compare commits

...

2 Commits

4 changed files with 397 additions and 0 deletions

68
zabbix-tests/host-cleanup.py Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
import requests
import json
import time
# === CONFIGURATION ===
ZABBIX_URL = "http://10.0.0.101:8887/api_jsonrpc.php"
ZABBIX_TOKEN = "c785634354e760a6843055ba4581bc7b6cd6eb2ec75f7c2a79f251c1719933f7"
GROUP_ID = "19"
BATCH_SIZE = 100
HOST_PATTERN = "dummy-host-"
HEADERS = {
"Content-Type": "application/json-rpc",
"Authorization": f"Bearer {ZABBIX_TOKEN}"
}
def zbx_request(method, params):
payload = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": int(time.time())
}
r = requests.post(ZABBIX_URL, headers=HEADERS, data=json.dumps(payload))
r.raise_for_status()
resp = r.json()
if "error" in resp:
raise Exception(f"API error: {resp['error']}")
return resp
def cleanup_hosts():
# Get all hosts in the group
resp = zbx_request("host.get", {
"groupids": [GROUP_ID],
"output": ["hostid", "host"]
})
# Filter hosts that contain the dummy pattern
hosts = [h for h in resp.get("result", []) if HOST_PATTERN in h["host"]]
if not hosts:
print("No dummy hosts found")
return
print(f"Deleting {len(hosts)} hosts")
# Delete in batches
host_ids = [h["hostid"] for h in hosts]
total_deleted = 0
for i in range(0, len(host_ids), BATCH_SIZE):
batch = host_ids[i:i + BATCH_SIZE]
try:
resp = zbx_request("host.delete", batch)
deleted = len(resp.get("result", {}).get("hostids", []))
total_deleted += deleted
print(f"Deleted batch {i//BATCH_SIZE + 1}: {deleted} hosts")
except Exception as e:
print(f"Error in batch {i//BATCH_SIZE + 1}: {e}")
if i + BATCH_SIZE < len(host_ids):
time.sleep(0.5)
print(f"Total deleted: {total_deleted}")
if __name__ == "__main__":
cleanup_hosts()

77
zabbix-tests/host-creator.py Executable file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/env python3
import requests
import json
import time
# === CONFIGURATION ===
ZABBIX_URL = "http://10.0.0.101:8887/api_jsonrpc.php"
ZABBIX_TOKEN = "c785634354e760a6843055ba4581bc7b6cd6eb2ec75f7c2a79f251c1719933f7"
PROXY_GROUP_ID = "1" # your proxy group ID
GROUP_ID = "19" # host group for these hosts
NUM_HOSTS = 1000 # number of hosts to create
BATCH_SIZE = 100 # how many to create per call
HEADERS = {
"Content-Type": "application/json-rpc",
"Authorization": f"Bearer {ZABBIX_TOKEN}"
}
def zbx_request(method, params):
"""Send Zabbix API request using Bearer token authentication."""
payload = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": int(time.time())
}
r = requests.post(ZABBIX_URL, headers=HEADERS, data=json.dumps(payload))
r.raise_for_status()
resp = r.json()
if "error" in resp:
raise Exception(f"Zabbix API error: {resp['error']}")
return resp
def create_hosts():
hosts = []
for i in range(1, NUM_HOSTS + 1):
host_name = f"dummy-host-{i:04d}"
host = {
"host": host_name,
"interfaces": [{
"type": 1, # Zabbix agent
"main": 1,
"useip": 1,
"ip": "127.0.0.1",
"dns": "",
"port": "10050"
}],
"groups": [{"groupid": GROUP_ID}],
"templates": [{"templateid": "10048"}], # assign template ID 10048
"monitored_by": 2, # 2 = proxy group
"proxy_groupid": PROXY_GROUP_ID, # your proxy group ID
"items": [{
"name": "Dummy metric",
"key_": "dummy.value",
"type": 2, # trapper
"value_type": 0, # numeric float
"delay": "60s"
}]
}
hosts.append(host)
for i in range(0, len(hosts), BATCH_SIZE):
batch = hosts[i:i + BATCH_SIZE]
print(f"Creating hosts {i+1}{i+len(batch)}...")
try:
resp = zbx_request("host.create", batch)
created = len(resp.get("result", {}).get("hostids", []))
print(f"✅ Created {created} hosts.")
except Exception as e:
print(f"❌ Error in batch {i+1}{i+len(batch)}: {e}")
time.sleep(1)
if __name__ == "__main__":
try:
create_hosts()
except Exception as e:
print(f"Fatal error: {e}")

View File

@@ -0,0 +1,28 @@
# Database Configuration
MYSQL_DATABASE=zabbix
MYSQL_USER=zabbix
MYSQL_PASSWORD=strong-password
MYSQL_ROOT_PASSWORD=very-strong-password
# Image Versions (uncomment to override defaults)
ZABBIX_VERSION=latest
# MYSQL_VERSION=8.4.0-oraclelinux8 # Keep oraclelinux variant for architecture compatibility
# Port Configuration
ZABBIX_SERVER_PORT=10051
ZABBIX_WEB_PORT=8887
# Server Settings
PHP_TIMEZONE=Europe/Warsaw
ZBX_STARTSNMPTRAPPER=1
ZBX_SNMPTRAPPERFILE=/tmp/traps.log
ZBX_CACHESIZE=128M
ZBX_VALUECACHESIZE=64M
ZBX_TRENDCACHESIZE=32M
# Common Proxy Settings (applied to all proxies)
PROXY_CACHE_SIZE=128M
PROXY_HISTORY_CACHE_SIZE=32M
PROXY_HISTORY_INDEX_CACHE_SIZE=16M
PROXY_BUFFER_MODE=hybrid
PROXY_MEMORY_BUFFER_SIZE=64M

View File

@@ -0,0 +1,224 @@
### This will create a Zabbix server with six active proxies and a MySQL database.
### You need to configure proxies in Zabbix frontend after deployment.
### Adjust .env file for customization.
services:
mysql-server:
image: mysql:${MYSQL_VERSION:-8.4.0-oraclelinux8}
container_name: zabbix-mysql-server
command:
- 'mysqld'
- '--character-set-server=utf8mb4'
- '--collation-server=utf8mb4_bin'
- '--log-bin-trust-function-creators=1'
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes:
- ./zabbix/mysql:/var/lib/mysql
restart: unless-stopped
networks:
- zabbix-net
zabbix-server:
image: zabbix/zabbix-server-mysql:${ZABBIX_VERSION:-latest}
container_name: zabbix-server
depends_on:
- mysql-server
ports:
- "${ZABBIX_SERVER_PORT}:10051"
environment:
- DB_SERVER_HOST=mysql-server
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- ZBX_STARTSNMPTRAPPER=${ZBX_STARTSNMPTRAPPER}
- ZBX_SNMPTRAPPERFILE=${ZBX_SNMPTRAPPERFILE}
- ZBX_CACHESIZE=${ZBX_CACHESIZE}
- ZBX_VALUECACHESIZE=${ZBX_VALUECACHESIZE}
- ZBX_TRENDCACHESIZE=${ZBX_TRENDCACHESIZE}
volumes:
- ./zabbix/alertscripts:/usr/lib/zabbix/alertscripts
- ./zabbix/externalscripts:/usr/lib/zabbix/externalscripts
restart: unless-stopped
networks:
- zabbix-net
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:${ZABBIX_VERSION:-latest}
container_name: zabbix-web
depends_on:
- mysql-server
- zabbix-server
ports:
- "${ZABBIX_WEB_PORT}:8080"
environment:
- DB_SERVER_HOST=mysql-server
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- ZBX_SERVER_HOST=zabbix-server
- PHP_TZ=${PHP_TIMEZONE}
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-01:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-01
depends_on:
- zabbix-server
ports:
- "10101:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-01
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-01:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-02:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-02
depends_on:
- zabbix-server
ports:
- "10102:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-02
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-02:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-03:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-03
depends_on:
- zabbix-server
ports:
- "10103:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-03
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-03:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-04:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-04
depends_on:
- zabbix-server
ports:
- "10104:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-04
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-04:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-05:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-05
depends_on:
- zabbix-server
ports:
- "10105:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-05
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-05:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
zabbix-proxy-active-06:
image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
container_name: zabbix-proxy-active-06
depends_on:
- zabbix-server
ports:
- "10106:10051"
environment:
- ZBX_HOSTNAME=zabbix-proxy-active-06
- ZBX_SERVER_HOST=zabbix-server
- ZBX_PROXYMODE=0
- ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
- ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
- ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
- ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
- ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
volumes:
- ./zabbix/proxy-06:/var/lib/zabbix/db_data:rw
restart: unless-stopped
networks:
- zabbix-net
# zabbix-proxy-passive-03:
# image: zabbix/zabbix-proxy-sqlite3:${ZABBIX_VERSION:-latest}
# container_name: zabbix-proxy-passive-03
# depends_on:
# - zabbix-server
# ports:
# - "10103:10051"
# environment:
# - ZBX_HOSTNAME=zabbix-proxy-passive-03
# - ZBX_SERVER_HOST=zabbix-server
# - ZBX_PROXYMODE=1
# - ZBX_CACHESIZE=${PROXY_CACHE_SIZE}
# - ZBX_HISTORYCACHESIZE=${PROXY_HISTORY_CACHE_SIZE}
# - ZBX_HISTORYINDEXCACHESIZE=${PROXY_HISTORY_INDEX_CACHE_SIZE}
# - ZBX_PROXYBUFFERMODE=${PROXY_BUFFER_MODE}
# - ZBX_PROXYMEMORYBUFFERSIZE=${PROXY_MEMORY_BUFFER_SIZE}
# volumes:
# - ./zabbix/proxy-03:/var/lib/zabbix/db_data:rw
# restart: unless-stopped
# networks:
# - zabbix-net
networks:
zabbix-net:
driver: bridge