version: '3.5'
services:
 keycloak:
  image: quay.io/keycloak/keycloak:17.0.0
  environment:
   - KEYCLOAK_ADMIN=admin
   - KEYCLOAK_ADMIN_PASSWORD=admin
  ports:
   - "80:8080"
  command: start-dev

 zabbix-server:
  image: zabbix/zabbix-server-mysql:ubuntu-5.4.0
  ports:
   - "10051:10051"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
   - ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
   - ./zbx_env/var/lib/zabbix/export:/var/lib/zabbix/export:rw
   - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
   - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
   - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
   - ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
   - snmptraps:/var/lib/zabbix/snmptraps:rw
  ulimits:
   nproc: 65535
   nofile:
    soft: 20000
    hard: 40000
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 1G
    reservations:
      cpus: '0.5'
      memory: 512M
  env_file:
   - env_vars/.env_db_mysql
   - env_vars/.env_srv
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
  depends_on:
   - mysql-server
   - keycloak
  networks:
   zbx_net_backend:
     aliases:
      - zabbix-server
      - zabbix-server-mysql
      - zabbix-server-ubuntu-mysql
      - zabbix-server-mysql-ubuntu
   zbx_net_frontend:
#  devices:
#   - "/dev/ttyUSB0:/dev/ttyUSB0"
  stop_grace_period: 30s
  sysctls:
   - net.ipv4.ip_local_port_range=1024 65000
   - net.ipv4.conf.all.accept_redirects=0
   - net.ipv4.conf.all.secure_redirects=0
   - net.ipv4.conf.all.send_redirects=0
  labels:
   com.zabbix.description: "Zabbix server with MySQL database support"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-server"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "ubuntu"

 zabbix-proxy-sqlite3:
  image: zabbix/zabbix-proxy-sqlite3:ubuntu-latest
  profiles:
   - all
  ports:
   - "10061:10051"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
   - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
   - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
   - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
   - ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
   - snmptraps:/var/lib/zabbix/snmptraps:rw
  ulimits:
   nproc: 65535
   nofile:
    soft: 20000
    hard: 40000
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 512M
    reservations:
      cpus: '0.3'
      memory: 256M
  env_file:
   - env_vars/.env_prx
   - env_vars/.env_prx_sqlite3
  depends_on:
   - zabbix-java-gateway
   - zabbix-snmptraps
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-proxy-sqlite3
     - zabbix-proxy-ubuntu-sqlite3
     - zabbix-proxy-sqlite3-ubuntu
   zbx_net_frontend:
  stop_grace_period: 30s
  labels:
   com.zabbix.description: "Zabbix proxy with SQLite3 database support"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-proxy"
   com.zabbix.dbtype: "sqlite3"
   com.zabbix.os: "ubuntu"

 zabbix-proxy-mysql:
  image: zabbix/zabbix-proxy-mysql:ubuntu-5.4.0
  profiles:
   - all
  ports:
   - "10071:10051"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
   - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
   - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
   - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
   - ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
   - snmptraps:/var/lib/zabbix/snmptraps:rw
  ulimits:
   nproc: 65535
   nofile:
    soft: 20000
    hard: 40000
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 512M
    reservations:
      cpus: '0.3'
      memory: 256M
  env_file:
   - env_vars/.env_db_mysql_proxy
   - env_vars/.env_prx
   - env_vars/.env_prx_mysql
  depends_on:
   - mysql-server
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-proxy-mysql
     - zabbix-proxy-ubuntu-mysql
     - zabbix-proxy-mysql-ubuntu
   zbx_net_frontend:
  stop_grace_period: 30s
  labels:
   com.zabbix.description: "Zabbix proxy with MySQL database support"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-proxy"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "ubuntu"

 zabbix-web-apache-mysql:
  image: zabbix/zabbix-web-apache-mysql:ubuntu-5.4.0
  profiles:
   - all
  ports:
   - "8081:8080"
   - "8443:8443"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/etc/ssl/apache2:/etc/ssl/apache2:ro
   - ./zbx_env/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 512M
    reservations:
      cpus: '0.5'
      memory: 256M
  env_file:
   - env_vars/.env_db_mysql
   - env_vars/.env_web
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
  depends_on:
   - mysql-server
   - zabbix-server
  healthcheck:
   test: ["CMD", "curl", "-f", "http://localhost:8080/"]
   interval: 10s
   timeout: 5s
   retries: 3
   start_period: 30s
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-web-apache-mysql
     - zabbix-web-apache-ubuntu-mysql
     - zabbix-web-apache-mysql-ubuntu
   zbx_net_frontend:
  stop_grace_period: 10s
  sysctls:
   - net.core.somaxconn=65535
  labels:
   com.zabbix.description: "Zabbix frontend on Apache web-server with MySQL database support"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-frontend"
   com.zabbix.webserver: "apache2"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "ubuntu"

 zabbix-web-nginx-mysql:
  image: zabbix/zabbix-web-nginx-mysql:ubuntu-5.4.0
  ports:
   - "8080:8080"
   - "443:8443"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
   - ./zbx_env/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
   - ./zbx_env/usr/share/zabbix/conf/certs/:/etc/zabbix/web/certs:ro
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 512M
    reservations:
      cpus: '0.5'
      memory: 256M
  env_file:
   - env_vars/.env_db_mysql
   - env_vars/.env_web
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
  depends_on:
   - mysql-server
   - zabbix-server
  healthcheck:
   test: ["CMD", "curl", "-f", "http://localhost:8080/"]
   interval: 10s
   timeout: 5s
   retries: 3
   start_period: 30s
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-web-nginx-mysql
     - zabbix-web-nginx-ubuntu-mysql
     - zabbix-web-nginx-mysql-ubuntu
   zbx_net_frontend:
  stop_grace_period: 10s
  sysctls:
   - net.core.somaxconn=65535
  labels:
   com.zabbix.description: "Zabbix frontend on Nginx web-server with MySQL database support"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-frontend"
   com.zabbix.webserver: "nginx"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "ubuntu"

 zabbix-agent:
  image: zabbix/zabbix-agent:ubuntu-5.4.0
  profiles:
   - full
   - all
  ports:
   - "10050:10050"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
   - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
   - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
   - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
  deploy:
   resources:
    limits:
      cpus: '0.2'
      memory: 128M
    reservations:
      cpus: '0.1'
      memory: 64M
   mode: global
  env_file:
   - env_vars/.env_agent
  privileged: true
  pid: "host"
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-agent
     - zabbix-agent-passive
     - zabbix-agent-ubuntu
  stop_grace_period: 5s
  labels:
   com.zabbix.description: "Zabbix agent"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "zabbix-agentd"
   com.zabbix.os: "ubuntu"

 zabbix-java-gateway:
  image: zabbix/zabbix-java-gateway:ubuntu-5.4.0
  profiles:
   - full
   - all
  ports:
   - "10052:10052"
  deploy:
   resources:
    limits:
      cpus: '0.5'
      memory: 512M
    reservations:
      cpus: '0.25'
      memory: 256M
  env_file:
   - env_vars/.env_java
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-java-gateway
     - zabbix-java-gateway-ubuntu
  stop_grace_period: 5s
  labels:
   com.zabbix.description: "Zabbix Java Gateway"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "java-gateway"
   com.zabbix.os: "ubuntu"

 zabbix-snmptraps:
  image: zabbix/zabbix-snmptraps:ubuntu-5.4.0
  profiles:
   - full
   - all
  ports:
   - "162:1162/udp"
  volumes:
   - snmptraps:/var/lib/zabbix/snmptraps:rw
  deploy:
   resources:
    limits:
      cpus: '0.5'
      memory: 256M
    reservations:
      cpus: '0.25'
      memory: 128M
  networks:
   zbx_net_frontend:
    aliases:
     - zabbix-snmptraps
   zbx_net_backend:
  stop_grace_period: 5s
  labels:
   com.zabbix.description: "Zabbix snmptraps"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "snmptraps"
   com.zabbix.os: "ubuntu"

 zabbix-web-service:
  image: zabbix/zabbix-web-service:ubuntu-5.4.0
  profiles:
   - full
   - all
  ports:
   - "10053:10053"
  volumes:
   - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
  cap_add:
   - SYS_ADMIN
  deploy:
   resources:
    limits:
      cpus: '0.5'
      memory: 512M
    reservations:
      cpus: '0.25'
      memory: 256M
  env_file:
   - env_vars/.env_web_service
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-web-service
     - zabbix-web-service-ubuntu
  stop_grace_period: 5s
  labels:
   com.zabbix.description: "Zabbix web service"
   com.zabbix.company: "Zabbix LLC"
   com.zabbix.component: "web-service"
   com.zabbix.os: "ubuntu"

 mysql-server:
  image: mysql:oracle
  command:
   - mysqld
   - --character-set-server=utf8
   - --collation-server=utf8_bin
   - --default-authentication-plugin=mysql_native_password
  volumes:
   - ./zbx_env/var/lib/mysql:/var/lib/mysql:rw
  env_file:
   - env_vars/.env_db_mysql
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
  stop_grace_period: 1m
  networks:
   zbx_net_backend:
    aliases:
     - mysql-server
     - zabbix-database
     - mysql-database

 db_data_mysql:
  image: busybox
  volumes:
   - ./zbx_env/var/lib/mysql:/var/lib/mysql:rw

networks:
  zbx_net_frontend:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
  zbx_net_backend:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    internal: true
    ipam:
      driver: default
      config:
      - subnet: 172.16.239.0/24

volumes:
  snmptraps:

secrets:
  MYSQL_USER:
    file: ./env_vars/.MYSQL_USER
  MYSQL_PASSWORD:
    file: ./env_vars/.MYSQL_PASSWORD
  MYSQL_ROOT_PASSWORD:
    file: ./env_vars/.MYSQL_ROOT_PASSWORD

