Devenv: Add zabbix 5.2

This commit is contained in:
Alexander Zobnin
2023-08-01 12:28:21 +02:00
parent d484934b3a
commit 103938511a
5 changed files with 707 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
FROM python:3
ENV ZBX_API_URL=http://zabbix-web
ENV ZBX_API_USER="Admin"
ENV ZBX_API_PASSWORD="zabbix"
ENV ZBX_CONFIG="zbx_export_hosts_5.xml"
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py"
RUN pip install pyzabbix
WORKDIR /
ADD ./${ZBX_CONFIG} /${ZBX_CONFIG}
ADD ./bootstrap_config.py /bootstrap_config.py
# RUN cp ./${ZBX_CONFIG} /${ZBX_CONFIG}
# Run bootstrap_config.py when the container launches
CMD ["python", "/bootstrap_config.py"]

View File

@@ -0,0 +1,93 @@
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(10)
except:
print("Waiting")
sleep(10)
zapi.timeout = 600
config_path = os.environ['ZBX_CONFIG']
import_rules = {
'applications': {
'createMissing': True,
},
'discoveryRules': {
'createMissing': True,
'updateExisting': True
},
'graphs': {
'createMissing': True,
'updateExisting': True
},
'groups': {
'createMissing': True
},
'hosts': {
'createMissing': True,
'updateExisting': True
},
'images': {
'createMissing': True,
'updateExisting': True
},
'items': {
'createMissing': True,
'updateExisting': True
},
'maps': {
'createMissing': True,
'updateExisting': True
},
# 'screens': {
# 'createMissing': True,
# 'updateExisting': True
# },
'templateLinkage': {
'createMissing': True,
},
'templates': {
'createMissing': True,
'updateExisting': True
},
# 'templateScreens': {
# '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'])

View File

@@ -0,0 +1,63 @@
<host>
<host>backend01</host>
<name>backend01</name>
<description/>
<proxy/>
<status>0</status>
<ipmi_authtype>-1</ipmi_authtype>
<ipmi_privilege>2</ipmi_privilege>
<ipmi_username/>
<ipmi_password/>
<tls_connect>1</tls_connect>
<tls_accept>1</tls_accept>
<tls_issuer/>
<tls_subject/>
<tls_psk_identity/>
<tls_psk/>
<templates>
<template>
<name>Template ZAS Agent</name>
</template>
</templates>
<groups>
<group>
<name>Backend</name>
</group>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<interface>
<default>1</default>
<type>1</type>
<useip>0</useip>
<ip>127.0.0.1</ip>
<dns>zas_backend_01</dns>
<port>10050</port>
<bulk>1</bulk>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<items/>
<discovery_rules/>
<httptests/>
<macros/>
<inventory>
<inventory_mode>-1</inventory_mode>
</inventory>
<tags>
<tag>
<tag>env</tag>
<value>staging</value>
</tag>
<tag>
<tag>group</tag>
<value>backend</value>
</tag>
<tag>
<tag>region</tag>
<value>EU</value>
</tag>
</tags>
</host>

View File

@@ -0,0 +1,407 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2021-09-10T12:42:13Z</date>
<groups>
<group>
<name>Backend</name>
</group>
<group>
<name>Database</name>
</group>
<group>
<name>Frontend</name>
</group>
<group>
<name>Linux servers</name>
</group>
<group>
<name>Zabbix servers</name>
</group>
</groups>
<hosts>
<host>
<host>backend01</host>
<name>backend01</name>
<templates>
<template>
<name>Template ZAS Agent</name>
</template>
</templates>
<groups>
<group>
<name>Backend</name>
</group>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<interface>
<useip>NO</useip>
<dns>zas_backend_01</dns>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<inventory_mode>DISABLED</inventory_mode>
</host>
<host>
<host>backend02</host>
<name>backend02</name>
<templates>
<template>
<name>Template ZAS Agent</name>
</template>
</templates>
<groups>
<group>
<name>Backend</name>
</group>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<interface>
<useip>NO</useip>
<dns>zas_backend_02</dns>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<inventory_mode>DISABLED</inventory_mode>
</host>
<host>
<host>frontend01</host>
<name>frontend01</name>
<templates>
<template>
<name>Template ZAS Agent</name>
</template>
</templates>
<groups>
<group>
<name>Frontend</name>
</group>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<interface>
<useip>NO</useip>
<dns>zas_frontend_01</dns>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<inventory_mode>DISABLED</inventory_mode>
</host>
<host>
<host>frontend02</host>
<name>frontend02</name>
<templates>
<template>
<name>Template ZAS Agent</name>
</template>
</templates>
<groups>
<group>
<name>Frontend</name>
</group>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<interface>
<useip>NO</useip>
<dns>zas_frontend_02</dns>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<inventory_mode>DISABLED</inventory_mode>
</host>
<host>
<host>Zabbix server</host>
<name>Zabbix server</name>
<templates>
<template>
<name>Linux by Zabbix agent</name>
</template>
<template>
<name>Zabbix Server</name>
</template>
</templates>
<groups>
<group>
<name>Zabbix servers</name>
</group>
</groups>
<interfaces>
<interface>
<interface_ref>if1</interface_ref>
</interface>
</interfaces>
<inventory_mode>DISABLED</inventory_mode>
</host>
</hosts>
<templates>
<template>
<template>Template ZAS Agent</template>
<name>Template ZAS Agent</name>
<templates>
<template>
<name>Template App Zabbix Agent</name>
</template>
</templates>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Filesystems</name>
</application>
<application>
<name>General</name>
</application>
<application>
<name>Memory</name>
</application>
<application>
<name>Network interfaces</name>
</application>
<application>
<name>OS</name>
</application>
<application>
<name>Performance</name>
</application>
<application>
<name>Processes</name>
</application>
<application>
<name>Security</name>
</application>
</applications>
<items>
<item>
<name>Incoming network traffic on eth0</name>
<key>net.if.in[eth0]</key>
<history>1d</history>
<units>bps</units>
<applications>
<application>
<name>Network interfaces</name>
</application>
</applications>
<request_method>POST</request_method>
</item>
<item>
<name>Outgoing network traffic on eth0</name>
<key>net.if.out[eth0]</key>
<history>1d</history>
<units>bps</units>
<applications>
<application>
<name>Network interfaces</name>
</application>
</applications>
<request_method>POST</request_method>
</item>
<item>
<name>Processor load (1 min average per core)</name>
<key>system.cpu.load[percpu,avg1]</key>
<history>1d</history>
<value_type>FLOAT</value_type>
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Performance</name>
</application>
</applications>
<request_method>POST</request_method>
<triggers>
<trigger>
<expression>{last(0)}&gt;2</expression>
<name>Processor load is too high on {HOST.NAME}</name>
<priority>WARNING</priority>
</trigger>
</triggers>
</item>
<item>
<name>Processor load (15 min average per core)</name>
<key>system.cpu.load[percpu,avg15]</key>
<history>1d</history>
<value_type>FLOAT</value_type>
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Performance</name>
</application>
</applications>
<request_method>POST</request_method>
</item>
<item>
<name>CPU $2 time</name>
<key>system.cpu.util[,iowait]</key>
<history>1d</history>
<value_type>FLOAT</value_type>
<units>%</units>
<description>Amount of time the CPU has been waiting for I/O to complete.</description>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Performance</name>
</application>
</applications>
<request_method>POST</request_method>
<triggers>
<trigger>
<expression>{avg(5m)}&gt;20</expression>
<name>Disk I/O is overloaded on {HOST.NAME}</name>
<priority>WARNING</priority>
<description>OS spends significant time waiting for I/O (input/output) operations. It could be indicator of performance issues with storage system.</description>
</trigger>
</triggers>
</item>
<item>
<name>CPU $2 time</name>
<key>system.cpu.util[,system]</key>
<history>1d</history>
<value_type>FLOAT</value_type>
<units>%</units>
<description>The time the CPU has spent running the kernel and its processes.</description>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Performance</name>
</application>
</applications>
<request_method>POST</request_method>
</item>
<item>
<name>CPU $2 time</name>
<key>system.cpu.util[,user]</key>
<history>1d</history>
<value_type>FLOAT</value_type>
<units>%</units>
<description>The time the CPU has spent running users' processes that are not niced.</description>
<applications>
<application>
<name>CPU</name>
</application>
<application>
<name>Performance</name>
</application>
</applications>
<request_method>POST</request_method>
</item>
</items>
</template>
<template>
<template>Template App Zabbix Agent</template>
<name>Template App Zabbix Agent</name>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Zabbix agent</name>
</application>
</applications>
<items>
<item>
<name>Host name of zabbix_agentd running</name>
<key>agent.hostname</key>
<delay>1h</delay>
<history>1w</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<applications>
<application>
<name>Zabbix agent</name>
</application>
</applications>
<request_method>POST</request_method>
<triggers>
<trigger>
<expression>{diff(0)}&gt;0</expression>
<name>Host name of zabbix_agentd was changed on {HOST.NAME}</name>
<priority>INFO</priority>
</trigger>
</triggers>
</item>
<item>
<name>Agent ping</name>
<key>agent.ping</key>
<history>1w</history>
<description>The agent always returns 1 for this item. It could be used in combination with nodata() for availability check.</description>
<applications>
<application>
<name>Zabbix agent</name>
</application>
</applications>
<valuemap>
<name>Zabbix agent ping status</name>
</valuemap>
<request_method>POST</request_method>
<triggers>
<trigger>
<expression>{nodata(5m)}=1</expression>
<name>Zabbix agent on {HOST.NAME} is unreachable for 5 minutes</name>
<priority>AVERAGE</priority>
</trigger>
</triggers>
</item>
<item>
<name>Version of zabbix_agent(d) running</name>
<key>agent.version</key>
<delay>1h</delay>
<history>1w</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<applications>
<application>
<name>Zabbix agent</name>
</application>
</applications>
<request_method>POST</request_method>
<triggers>
<trigger>
<expression>{diff(0)}&gt;0</expression>
<name>Version of zabbix_agent(d) was changed on {HOST.NAME}</name>
<priority>INFO</priority>
</trigger>
</triggers>
</item>
</items>
</template>
</templates>
<value_maps>
<value_map>
<name>Zabbix agent ping status</name>
<mappings>
<mapping>
<value>1</value>
<newvalue>Up</newvalue>
</mapping>
</mappings>
</value_map>
</value_maps>
</zabbix_export>

View File

@@ -0,0 +1,126 @@
version: "3"
services:
# Zabbix
zabbix-server:
image: zabbix/zabbix-server-pgsql:alpine-5.2.1
ports:
- "10051:10051"
depends_on:
- database
environment:
DB_SERVER_HOST: database
DB_SERVER_PORT: 5432
POSTGRES_USER: zabbix
POSTGRES_PASSWORD: zabbix
POSTGRES_DB: zabbix
zabbix-web:
image: zabbix/zabbix-web-apache-pgsql:alpine-5.2.1
ports:
- "8188:8080"
- "8189:8443"
# - "8188:80"
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
ZBX_SESSION_NAME: zbx_sessionid_new
volumes:
- ./ssl:/etc/ssl/apache2:ro
database:
image: postgres
ports:
- "15432:5432"
environment:
POSTGRES_USER: zabbix
POSTGRES_PASSWORD: zabbix
zabbix-agent:
image: zabbix/zabbix-agent:alpine-5.2.1
environment:
ZBX_SERVER_HOST: zabbix-server
ZBX_SERVER_PORT: 10051
zabbix-proxy:
image: zabbix/zabbix-proxy-sqlite3:alpine-5.2.1
environment:
ZBX_PROXYMODE: 0
ZBX_HOSTNAME: zabbix-proxy
ZBX_SERVER_HOST: zabbix-server
ZBX_SERVER_PORT: 10051
zabbix-agent-proxy:
image: zabbix/zabbix-agent:alpine-5.2.1
environment:
ZBX_SERVER_HOST: zabbix-proxy
ZBX_SERVER_PORT: 10051
#########################################################
# Bootstrap config
#########################################################
bootstrap:
build:
context: ./bootstrap
dockerfile: Dockerfile
args:
ZBX_HOSTS_NUMBER: 10
environment:
ZBX_API_URL: http://zabbix-web:8080
# ZBX_API_URL: http://zabbix-web:80
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