From 7526346d702e95cf144b16041351d0a22bbab906 Mon Sep 17 00:00:00 2001 From: Adam Gelwarg Date: Tue, 5 Aug 2025 12:01:40 -0400 Subject: [PATCH 1/3] Initial framework for building proxy-pgsql images --- .env | 2 + Dockerfiles/proxy-mysql/alpine/Dockerfile | 3 +- Dockerfiles/proxy-pgsql/README.md | 350 ++++++++++ Dockerfiles/proxy-pgsql/alpine/.dockerignore | 1 + Dockerfiles/proxy-pgsql/alpine/Dockerfile | 113 +++ Dockerfiles/proxy-pgsql/alpine/README.md | 1 + Dockerfiles/proxy-pgsql/alpine/build.sh | 1 + .../proxy-pgsql/alpine/docker-entrypoint.sh | 606 ++++++++++++++++ Dockerfiles/proxy-pgsql/centos/.dockerignore | 1 + Dockerfiles/proxy-pgsql/centos/Dockerfile | 139 ++++ Dockerfiles/proxy-pgsql/centos/README.md | 1 + Dockerfiles/proxy-pgsql/centos/build.sh | 1 + .../proxy-pgsql/centos/docker-entrypoint.sh | 606 ++++++++++++++++ Dockerfiles/proxy-pgsql/ol/.dockerignore | 1 + Dockerfiles/proxy-pgsql/ol/Dockerfile | 127 ++++ Dockerfiles/proxy-pgsql/ol/README.md | 1 + Dockerfiles/proxy-pgsql/ol/build.sh | 1 + .../conf/etc/yum.repos.d/oracle-epel-ol9.repo | 6 + .../proxy-pgsql/ol/docker-entrypoint.sh | 606 ++++++++++++++++ Dockerfiles/proxy-pgsql/rhel/.dockerignore | 1 + Dockerfiles/proxy-pgsql/rhel/Dockerfile | 168 +++++ Dockerfiles/proxy-pgsql/rhel/README.html | 195 ++++++ Dockerfiles/proxy-pgsql/rhel/build.sh | 1 + .../proxy-pgsql/rhel/docker-entrypoint.sh | 606 ++++++++++++++++ .../proxy-pgsql/rhel/licenses/AGPL-v3.0.txt | 661 ++++++++++++++++++ Dockerfiles/proxy-pgsql/ubuntu/.dockerignore | 1 + Dockerfiles/proxy-pgsql/ubuntu/Dockerfile | 137 ++++ Dockerfiles/proxy-pgsql/ubuntu/README.md | 1 + Dockerfiles/proxy-pgsql/ubuntu/build.sh | 1 + .../proxy-pgsql/ubuntu/docker-entrypoint.sh | 606 ++++++++++++++++ build.json | 1 + compose_zabbix_components.yaml | 65 ++ env_vars/.env_db_pgsql_proxy | 11 + env_vars/.env_prx_pgsql | 8 + 34 files changed, 5028 insertions(+), 2 deletions(-) create mode 100644 Dockerfiles/proxy-pgsql/README.md create mode 100644 Dockerfiles/proxy-pgsql/alpine/.dockerignore create mode 100644 Dockerfiles/proxy-pgsql/alpine/Dockerfile create mode 120000 Dockerfiles/proxy-pgsql/alpine/README.md create mode 120000 Dockerfiles/proxy-pgsql/alpine/build.sh create mode 100755 Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh create mode 100644 Dockerfiles/proxy-pgsql/centos/.dockerignore create mode 100644 Dockerfiles/proxy-pgsql/centos/Dockerfile create mode 120000 Dockerfiles/proxy-pgsql/centos/README.md create mode 120000 Dockerfiles/proxy-pgsql/centos/build.sh create mode 100755 Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh create mode 100644 Dockerfiles/proxy-pgsql/ol/.dockerignore create mode 100644 Dockerfiles/proxy-pgsql/ol/Dockerfile create mode 120000 Dockerfiles/proxy-pgsql/ol/README.md create mode 120000 Dockerfiles/proxy-pgsql/ol/build.sh create mode 100644 Dockerfiles/proxy-pgsql/ol/conf/etc/yum.repos.d/oracle-epel-ol9.repo create mode 100755 Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh create mode 100644 Dockerfiles/proxy-pgsql/rhel/.dockerignore create mode 100644 Dockerfiles/proxy-pgsql/rhel/Dockerfile create mode 100644 Dockerfiles/proxy-pgsql/rhel/README.html create mode 120000 Dockerfiles/proxy-pgsql/rhel/build.sh create mode 100755 Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh create mode 100644 Dockerfiles/proxy-pgsql/rhel/licenses/AGPL-v3.0.txt create mode 100644 Dockerfiles/proxy-pgsql/ubuntu/.dockerignore create mode 100644 Dockerfiles/proxy-pgsql/ubuntu/Dockerfile create mode 120000 Dockerfiles/proxy-pgsql/ubuntu/README.md create mode 120000 Dockerfiles/proxy-pgsql/ubuntu/build.sh create mode 100755 Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh create mode 100644 env_vars/.env_db_pgsql_proxy create mode 100644 env_vars/.env_prx_pgsql diff --git a/.env b/.env index 375afd71d4..5b6fd2bd6d 100644 --- a/.env +++ b/.env @@ -10,6 +10,7 @@ ZABBIX_LOCAL_IMAGE_TAG_POSTFIX=-local ZABBIX_SERVER_MYSQL_IMAGE=zabbix/zabbix-server-mysql ZABBIX_SERVER_PGSQL_IMAGE=zabbix/zabbix-server-pgsql ZABBIX_PROXY_MYSQL_IMAGE=zabbix/zabbix-proxy-mysql +ZABBIX_PROXY_PGSQL_IMAGE=zabbix/zabbix-proxy-pgsql ZABBIX_PROXY_SQLITE3_IMAGE=zabbix/zabbix-proxy-sqlite3 ZABBIX_WEB_NGINX_MYSQL_IMAGE=zabbix/zabbix-web-nginx-mysql ZABBIX_WEB_APACHE_MYSQL_IMAGE=zabbix/zabbix-web-apache-mysql @@ -45,6 +46,7 @@ WEBDRIVER_FIREFOX_IMAGE_TAG=126.0 # Expose ports per service ZABBIX_SERVER_PORT=10051 ZABBIX_PROXY_MYSQL_PORT=10071 +ZABBIX_PROXY_PGSQL_PORT=10081 ZABBIX_PROXY_SQLITE3_PORT=10061 ZABBIX_WEB_NGINX_HTTP_PORT=80 ZABBIX_WEB_NGINX_HTTPS_PORT=443 diff --git a/Dockerfiles/proxy-mysql/alpine/Dockerfile b/Dockerfiles/proxy-mysql/alpine/Dockerfile index 834ebaa57c..adebb75f39 100644 --- a/Dockerfiles/proxy-mysql/alpine/Dockerfile +++ b/Dockerfiles/proxy-mysql/alpine/Dockerfile @@ -80,8 +80,6 @@ RUN set -eux && \ chgrp zabbix /usr/bin/nmap && \ setcap cap_net_raw+eip /usr/bin/nmap && \ mkdir -p ${ZABBIX_CONF_DIR} && \ - chmod u+s /usr/sbin/fping && \ - mkdir -p ${ZABBIX_CONF_DIR}/ && \ mkdir -p ${ZABBIX_USER_HOME_DIR} && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ @@ -98,6 +96,7 @@ RUN set -eux && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod u+s ${ZBX_FPINGLOCATION} && \ /usr/sbin/zabbix_proxy -V EXPOSE 10051/TCP diff --git a/Dockerfiles/proxy-pgsql/README.md b/Dockerfiles/proxy-pgsql/README.md new file mode 100644 index 0000000000..87b9ba56c2 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/README.md @@ -0,0 +1,350 @@ +![logo](https://assets.zabbix.com/img/logo/zabbix_logo_500x131.png) + +# What is Zabbix? + +Zabbix is an enterprise-class open source distributed monitoring solution. + +Zabbix is software that monitors numerous parameters of a network and the health and integrity of servers. Zabbix uses a flexible notification mechanism that allows users to configure e-mail based alerts for virtually any event. This allows a fast reaction to server problems. Zabbix offers excellent reporting and data visualisation features based on the stored data. This makes Zabbix ideal for capacity planning. + +For more information and related downloads for Zabbix components, please visit https://hub.docker.com/u/zabbix/ and https://zabbix.com + +# What is Zabbix proxy? + +Zabbix proxy is a process that may collect monitoring data from one or more monitored devices and send the information to the Zabbix server, essentially working on behalf of the server. All collected data is buffered locally and then transferred to the Zabbix server the proxy belongs to. + +# Zabbix proxy images + +These are the only official Zabbix proxy Docker images. They are based on Alpine Linux v3.22, Ubuntu 24.04 (noble), CentOS Stream 10 and Oracle Linux 10 images. The available versions of Zabbix proxy are: + + Zabbix proxy 6.0 (tags: alpine-6.0-latest, ubuntu-6.0-latest, ol-6.0-latest) + Zabbix proxy 6.0.* (tags: alpine-6.0.*, ubuntu-6.0.*, ol-6.0.*) + Zabbix proxy 7.0 (tags: alpine-7.0-latest, ubuntu-7.0-latest, ol-7.0-latest) + Zabbix proxy 7.0.* (tags: alpine-7.0.*, ubuntu-7.0.*, ol-7.0.*) + Zabbix proxy 7.2 (tags: alpine-7.2-latest, ubuntu-7.2-latest, ol-7.2-latest) + Zabbix proxy 7.2.* (tags: alpine-7.2.*, ubuntu-7.2.*, ol-7.2.*) + Zabbix proxy 7.4 (tags: alpine-7.4-latest, ubuntu-7.4-latest, ol-7.4-latest, alpine-latest, ubuntu-latest, ol-latest, latest) + Zabbix proxy 7.4.* (tags: alpine-7.4.*, ubuntu-7.4.*, ol-7.4.*) + Zabbix proxy 8.0 (tags: alpine-trunk, ubuntu-trunk, ol-trunk) + +Images are updated when new releases are published. The image with ``latest`` tag is based on Alpine Linux. + +The image uses PostgreSQL database to store collected data before sending it to Zabbix server. It uses the next procedure to start: +################################################## +- Checking database availability +- Checking of having `POSTGRES_DB` database. Creating `POSTGRES_DB` database name if it does not exist +- Checking of having `dbversion` table. Creating Zabbix proxy database schema if no `dbversion` table +################################################## + +# How to use this image + +## Start `zabbix-proxy-pgsql` + +Start a Zabbix proxy container as follows: + + docker run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -e POSTGRES_USER="some-user" -e POSTGRES_PASSWORD="some-password" -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag + +Where `some-zabbix-proxy-pgsql` is the name you want to assign to your container, `some-postgres-server` is IP or DNS name of PostgreSQL server, `some-user` is user to connect to Zabbix database on PostgreSQL server, `some-password` is the password to connect to PostgreSQL server, `some-hostname` is the hostname, it is Hostname parameter in Zabbix proxy configuration file, `some-zabbix-server` is IP or DNS name of Zabbix server and `tag` is the tag specifying the version you want. See the list above for relevant tags, or look at the [full list of tags](https://hub.docker.com/r/zabbix/zabbix-proxy-pgsql/tags/). + +> [!NOTE] +> Zabbix server has possibility to execute `fping` utility to perform ICMP checks. When containers are running in rootless mode or with specific restrictions environment, you may face errors related to fping: +> `fping: Operation not permitted` +> or +> lost all packets to all resources +> in this case add `--cap-add=net_raw` to `docker run` or `podman run` commands. +> Additionally fping executing in non-root environments can require sysctl modification: +> `net.ipv4.ping_group_range=0 1995` +> where 1995 is `zabbix` GID. + +## Connects from Zabbix server (Passive proxy) + +This image exposes the standard Zabbix proxy port (10051) and can operate as Passive proxy in case `ZBX_PROXYMODE` = `1`. Start Zabbix server container like this in order to link it to the Zabbix proxy container: + +```console +$ docker run --name some-zabbix-server --link some-zabbix-proxy-pgsql:zabbix-proxy-pgsql --init -d zabbix/zabbix-server:latest +``` + +## Connect to Zabbix server (Active proxy) + +This image can operate as Active proxy (`default` mode). Start your application container like this in order to link Zabbix proxy to Zabbix server containters: + +```console +$ docker run --name some-zabbix-proxy-pgsql --link some-zabbix-server:zabbix-server --init -d zabbix/zabbix-proxy-pgsql:latest +``` + +## Container shell access and viewing Zabbix proxy logs + +The `docker exec` command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your `zabbix-proxy-pgsql` container: + +```console +$ docker exec -ti some-zabbix-proxy-pgsql /bin/bash +``` + +The Zabbix proxy log is available through Docker's container log: + +```console +$ docker logs some-zabbix-proxy-pgsql +``` + +## Environment Variables + +When you start the `zabbix-proxy-pgsql` image, you can adjust the configuration of the Zabbix proxy by passing one or more environment variables on the `docker run` command line. + +### `ZBX_PROXYMODE` + +The variable allows to switch Zabbix proxy mode. Bu default, value is `0` - active proxy. Allowed values are `0` - active proxy and `1` - passive proxy. + +### `ZBX_HOSTNAME` + +This variable is unique, case sensitive hostname. By default, value is `zabbix-proxy-pgsql` of the container. It is ``Hostname`` parameter in ``zabbix_proxy.conf``. + +### `ZBX_SERVER_HOST` + +This variable is IP or DNS name of Zabbix server or Zabbix proxy. By default, value is `zabbix-server`. It is ``Server`` parameter in ``zabbix_proxy.conf``. It is allowed to specify Zabbix server or Zabbix proxy port number using ``ZBX_SERVER_PORT`` variable. It make sense in case of non-default port for active checks. + +### `ZBX_SERVER_PORT` + +This variable is port Zabbix server listening on. By default, value is `10051`. + +**Note:** This parameter is no longer used in version 6.0 and above. Instead, add a colon ``:`` followed by the port number to the end of ``ZBX_SERVER_HOST``. + +### `DB_SERVER_HOST` + +This variable is IP or DNS name of PostgreSQL server. By default, value is 'postgres-server' + +### `DB_SERVER_PORT` + +This variable is port of PostgreSQL server. By default, value is '5432'. + +### `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_USER_FILE`, `POSTGRES_PASSWORD_FILE` + +These variables are used by Zabbix server to connect to Zabbix database. With the `_FILE` variables you can instead provide the path to a file which contains the user / the password instead. Without Docker Swarm or Kubernetes you also have to map the files. Those are exclusive so you can just provide one type - either `POSTGRES_USER` or `POSTGRES_USER_FILE`! + +```console +docker run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -v ./.POSTGRES_USER:/run/secrets/POSTGRES_USER -e POSTGRES_USER_FILE=/run/secrets/POSTGRES_USER -v ./.POSTGRES_PASSWORD:/run/secrets/POSTGRES_PASSWORD -e POSTGRES_PASSWORD_FILE=/var/run/secrets/POSTGRES_PASSWORD -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag +``` + +With Docker Swarm or Kubernetes this works with secrets. That way it is replicated in your cluster! + +```console +printf "zabbix" | docker secret create POSTGRES_USER - +printf "zabbix" | docker secret create POSTGRES_PASSWORD - +docker run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -e POSTGRES_USER_FILE=/run/secrets/POSTGRES_USER -e POSTGRES_PASSWORD_FILE=/run/secrets/POSTGRES_PASSWORD -e ZBX_SERVER_HOST="some-zabbix-server" -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag +``` + +By default, values for `POSTGRES_USER` and `POSTGRES_PASSWORD` are `zabbix`, `zabbix`. + +### `POSTGRES_DB` + +The variable is Zabbix database name. By default, value is `zabbix_proxy`. + +### `POSTGRES_USE_IMPLICIT_SEARCH_PATH` + +In some setups, for example including [PgBouncer](https://www.pgbouncer.org), setting the `search_path` via connection parameters fails. If this variable is set to `"true"`, the image skips setting the `search_path` and trusts that the `search_path` of the Zabbix user is setup correctly in PostgreSQL database. + +### `ZBX_LOADMODULE` + +The variable is list of comma separated loadable Zabbix modules. It works with volume ``/var/lib/zabbix/modules``. The syntax of the variable is ``dummy1.so,dummy2.so``. + +### ``ZBX_DEBUGLEVEL`` + +The variable is used to specify debug level. By default, value is ``3``. It is ``DebugLevel`` parameter in ``zabbix_server.conf``. Allowed values are listed below: +- ``0`` - basic information about starting and stopping of Zabbix processes; +- ``1`` - critical information +- ``2`` - error information +- ``3`` - warnings +- ``4`` - for debugging (produces lots of information) +- ``5`` - extended debugging (produces even more information) + +### `ZBX_TIMEOUT` + +The variable is used to specify timeout for processing checks. By default, value is ``4``. + +### `ZBX_JAVAGATEWAY_ENABLE` + +The variable enable communication with Zabbix Java Gateway to collect Java related checks. By default, value is `false`. + +### Other variables + +Additionally the image allows to specify many other environment variables listed below: + +``` +ZBX_ALLOWUNSUPPORTEDDBVERSIONS=0 # Available since 6.0.0 +ZBX_DBTLSCONNECT= # Available since 5.0.0 +ZBX_DBTLSCAFILE= # Available since 5.0.0 +ZBX_DBTLSCERTFILE= # Available since 5.0.0 +ZBX_DBTLSKEYFILE= # Available since 5.0.0 +ZBX_DBTLSCIPHER= # Available since 5.0.0 +ZBX_DBTLSCIPHER13= # Available since 5.0.0 +ZBX_VAULTDBPATH= # Available since 5.2.0 +ZBX_VAULTPREFIX= # Available since 7.0.0 +ZBX_VAULTURL=https://127.0.0.1:8200 # Available since 5.2.0 +VAULT_TOKEN= # Available since 5.2.0 +ZBX_ENABLEREMOTECOMMANDS=0 # Available since 3.4.0 +ZBX_LOGREMOTECOMMANDS=0 # Available since 3.4.0 +ZBX_HOSTNAMEITEM=system.hostname +ZBX_SOURCEIP= +ZBX_PROXYLOCALBUFFER=0 +ZBX_PROXYOFFLINEBUFFER=1 +ZBX_PROXYHEARTBEATFREQUENCY=60 # Deprecated since 6.4.0 +ZBX_CONFIGFREQUENCY=3600 # Deprecated since 6.4.0 +ZBX_PROXYCONFIGFREQUENCY=10 # Available since 6.4.0 +ZBX_DATASENDERFREQUENCY=1 +ZBX_STARTPOLLERS=5 +ZBX_STARTPREPROCESSORS=3 # Available since 4.2.0 +ZBX_STARTIPMIPOLLERS=0 +ZBX_STARTPOLLERSUNREACHABLE=1 +ZBX_STARTTRAPPERS=5 +ZBX_STARTPINGERS=1 +ZBX_STARTDISCOVERERS=1 +ZBX_STARTHISTORYPOLLERS=1 # Available since 5.4.0 till 6.0.0 +ZBX_STARTHTTPPOLLERS=1 +ZBX_STARTODBCPOLLERS=1 # Available since 6.0.0 +ZBX_JAVAGATEWAY=zabbix-java-gateway +ZBX_JAVAGATEWAYPORT=10052 +ZBX_STARTJAVAPOLLERS=0 +ZBX_STATSALLOWEDIP= # Available since 4.0.5 +ZBX_STARTVMWARECOLLECTORS=0 +ZBX_VMWAREFREQUENCY=60 +ZBX_VMWAREPERFFREQUENCY=60 +ZBX_VMWARECACHESIZE=8M +ZBX_VMWARETIMEOUT=10 +ZBX_ENABLE_SNMP_TRAPS=false +ZBX_LISTENIP= +ZBX_LISTENPORT=10051 +ZBX_LISTENBACKLOG= +ZBX_HOUSEKEEPINGFREQUENCY=1 +ZBX_CACHESIZE=8M +ZBX_STARTDBSYNCERS=4 +ZBX_HISTORYCACHESIZE=16M +ZBX_HISTORYINDEXCACHESIZE=4M +ZBX_TRAPPERTIMEOUT=300 +ZBX_UNREACHABLEPERIOD=45 +ZBX_UNAVAILABLEDELAY=60 +ZBX_UNREACHABLEDELAY=15 +ZBX_LOGSLOWQUERIES=3000 +ZBX_TLSCONNECT=unencrypted +ZBX_TLSACCEPT=unencrypted +ZBX_TLSCAFILE= +ZBX_TLSCA= +ZBX_TLSCRLFILE= +ZBX_TLSCRL= +ZBX_TLSSERVERCERTISSUER= +ZBX_TLSSERVERCERTSUBJECT= +ZBX_TLSCERTFILE= +ZBX_TLSCERT= +ZBX_TLSKEYFILE= +ZBX_TLSKEY= +ZBX_TLSPSKIDENTITY= +ZBX_TLSPSKFILE= +ZBX_TLSPSK= +ZBX_TLSCIPHERALL= # Available since 4.4.7 +ZBX_TLSCIPHERALL13= # Available since 4.4.7 +ZBX_TLSCIPHERCERT= # Available since 4.4.7 +ZBX_TLSCIPHERCERT13= # Available since 4.4.7 +ZBX_TLSCIPHERPSK= # Available since 4.4.7 +ZBX_TLSCIPHERPSK13= # Available since 4.4.7 +ZBX_WEBDRIVERURL= # Available since 7.0.0 +ZBX_STARTBROWSERPOLLERS=1 # Available since 7.0.0 +ZBX_STARTSNMPPOLLERS=1 # Available since 7.0.0 + +``` + +Default values of these variables are specified after equal sign. + +The allowed variables are identical of parameters in official ``zabbix_proxy.conf``. For example, ``ZBX_LOGSLOWQUERIES`` = ``LogSlowQueries``. + +Please use official documentation for [``zabbix_proxy.conf``](https://www.zabbix.com/documentation/current/manual/appendix/config/zabbix_proxy) to get more information about the variables. + +## Allowed volumes for the Zabbix proxy container + +### ``/usr/lib/zabbix/externalscripts`` + +The volume is used by External checks (type of items). It is `ExternalScripts` parameter in ``zabbix_proxy.conf``. + +### ``/var/lib/zabbix/modules`` + +The volume allows load additional modules and extend Zabbix proxy using ``LoadModule`` feature. + +### ``/var/lib/zabbix/enc`` + +The volume is used to store TLS related files. These file names are specified using ``ZBX_TLSCAFILE``, ``ZBX_TLSCRLFILE``, ``ZBX_TLSCERTFILE``, ``ZBX_TLSKEYFILE`` and ``ZBX_TLSPSKFILE`` variables. Additionally it is possible to use environment variables ``ZBX_TLSCA``, ``ZBX_TLSCRL``, ``ZBX_TLSCERT``, ``ZBX_TLSKEY`` and ``ZBX_TLSPSK`` with plaintext values. + +### ``/var/lib/zabbix/ssh_keys`` + +The volume is used as location of public and private keys for SSH checks and actions. It is `SSHKeyLocation` parameter in ``zabbix_proxy.conf``. + +### ``/var/lib/zabbix/ssl/certs`` + +The volume is used as location of of SSL client certificate files for client authentication. It is `SSLCertLocation` parameter in ``zabbix_proxy.conf``. + +### ``/var/lib/zabbix/ssl/keys`` + +The volume is used as location of SSL private key files for client authentication. It is `SSLKeyLocation` parameter in ``zabbix_proxy.conf``. + +### ``/var/lib/zabbix/ssl/ssl_ca`` + +The volume is used as location of certificate authority (CA) files for SSL server certificate verification. It is `SSLCALocation` parameter in ``zabbix_proxy.conf``. + +### ``/var/lib/zabbix/snmptraps`` + +The volume is used as location of ``snmptraps.log`` file. It could be shared by ``zabbix-snmptraps`` container and inherited using `volumes_from` Docker option while creating new instance of Zabbix proxy. +SNMP traps processing feature could be enabled using shared volume and switched ``ZBX_ENABLE_SNMP_TRAPS`` environment variable to `true`. + +### ``/var/lib/zabbix/mibs`` + +The volume allows to add new MIB files. It does not support subdirectories, all MIBs must be placed to ``/var/lib/zabbix/mibs``. + +# The image variants + +The `zabbix-proxy-pgsql` images come in many flavors, each designed for a specific use case. + +## `zabbix-proxy-pgsql:alpine-` + +This image is based on the popular [Alpine Linux project](http://alpinelinux.org), available in [the `alpine` official image](https://hub.docker.com/_/alpine). Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general. + +This variant is highly recommended when final image size being as small as possible is desired. The main caveat to note is that it does use [musl libc](http://www.musl-libc.org) instead of [glibc and friends](http://www.etalabs.net/compare_libcs.html), so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. See [this Hacker News comment thread](https://news.ycombinator.com/item?id=10782897) for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images. + +To minimize image size, it's uncommon for additional related tools (such as `git` or `bash`) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the [`alpine` image description](https://hub.docker.com/_/alpine/) for examples of how to install packages if you are unfamiliar). + +## `zabbix-proxy-pgsql:ubuntu-` + +This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of. + +## `zabbix-proxy-pgsql:ol-` + +Oracle Linux is an open-source operating system available under the GNU General Public License (GPLv2). Suitable for general purpose or Oracle workloads, it benefits from rigorous testing of more than 128,000 hours per day with real-world workloads and includes unique innovations such as Ksplice for zero-downtime kernel patching, DTrace for real-time diagnostics, the powerful Btrfs file system, and more. + +# Supported Docker versions + +This image is officially supported on Docker version 1.12.0. + +Support for older versions (down to 1.6) is provided on a best-effort basis. + +Please see [the Docker installation documentation](https://docs.docker.com/installation/) for details on how to upgrade your Docker daemon. + +# User Feedback + +## Documentation + +Documentation for this image is stored in the [`proxy-pgsql/` directory](https://github.com/zabbix/zabbix-docker/tree/7.0/Dockerfiles/proxy-pgsql) of the [`zabbix/zabbix-docker` GitHub repo](https://github.com/zabbix/zabbix-docker/). Be sure to familiarize yourself with the [repository's `README.md` file](https://github.com/zabbix/zabbix-docker/blob/7.0/README.md) before attempting a pull request. + +## Issues + +If you have any problems with or questions about this image, please contact us through a [GitHub issue](https://github.com/zabbix/zabbix-docker/issues). + +### Known issues + +## Contributing + +You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can. + +Before you start to code, we recommend discussing your plans through a [GitHub issue](https://github.com/zabbix/zabbix-docker/issues), especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing. + +## License + +Starting from Zabbix version 7.0, all subsequent Zabbix versions will be released under the GNU Affero General Public License version 3 (AGPLv3). +You can modify the relevant version and propagate such modified version under the terms of the AGPLv3 as published by the Free Software Foundation. +For additional details, including answers to common questions about the AGPLv3, see the generic FAQ from the [Free Software Foundation](http://www.fsf.org/licenses/gpl-faq.html). + +Zabbix is Open Source Software, however, if you use Zabbix in a commercial context we kindly ask you to support the development of Zabbix by purchasing some level of technical support. +All previous Zabbix software versions up to 6.4 are released under the GNU General Public License version 2 (GPLv2). The formal terms of the GPLv2 and AGPLv3 can be found at http://www.fsf.org/licenses/. diff --git a/Dockerfiles/proxy-pgsql/alpine/.dockerignore b/Dockerfiles/proxy-pgsql/alpine/.dockerignore new file mode 100644 index 0000000000..88a84e55aa --- /dev/null +++ b/Dockerfiles/proxy-pgsql/alpine/.dockerignore @@ -0,0 +1 @@ +build.sh diff --git a/Dockerfiles/proxy-pgsql/alpine/Dockerfile b/Dockerfiles/proxy-pgsql/alpine/Dockerfile new file mode 100644 index 0000000000..c01ea48d83 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/alpine/Dockerfile @@ -0,0 +1,113 @@ +# syntax=docker/dockerfile:1 +ARG OS_BASE_IMAGE=alpine:3.22 +ARG MAJOR_VERSION=7.0 +ARG ZBX_VERSION=${MAJOR_VERSION}.17 +ARG BUILD_BASE_IMAGE=zabbix-build-pgsql:alpine-${ZBX_VERSION} + +FROM ${BUILD_BASE_IMAGE} AS builder + +FROM ${OS_BASE_IMAGE} + +ARG MAJOR_VERSION +ARG ZBX_VERSION +ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git + +ENV TERM=xterm \ + ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \ + MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \ + NMAP_PRIVILEGED="" \ + ZABBIX_USER_HOME_DIR="/var/lib/zabbix" \ + ZABBIX_CONF_DIR="/etc/zabbix" \ + ZBX_FPINGLOCATION="/usr/sbin/fping" + +LABEL org.opencontainers.image.authors="Alexey Pustovalov " \ + org.opencontainers.image.description="Zabbix proxy with PostgreSQL database support" \ + org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" \ + org.opencontainers.image.licenses="AGPL v3.0" \ + org.opencontainers.image.source="${ZBX_SOURCES}" \ + org.opencontainers.image.title="Zabbix proxy (PostgreSQL)" \ + org.opencontainers.image.url="https://zabbix.com/" \ + org.opencontainers.image.vendor="Zabbix SIA" \ + org.opencontainers.image.version="${ZBX_VERSION}" + +STOPSIGNAL SIGTERM + +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy", "/usr/sbin/zabbix_proxy"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/general/bin/*", "/usr/bin/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/", "${ZABBIX_CONF_DIR}/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/database/postgresql/", "/usr/share/doc/zabbix-proxy-postgresql/"] + +RUN set -eux && \ + INSTALL_PKGS="bash \ + tzdata \ + traceroute \ + nmap \ + krb5 \ + iputils \ + openssl \ + libcap \ + libcurl \ + libevent \ + libldap \ + libssh \ + libxml2 \ + net-snmp-agent-libs \ + openipmi-libs \ + pcre2 \ + postgresql17-client \ + unixodbc \ + gzip \ + fping \ + zlib" && \ + apk add \ + --no-cache \ + --clean-protected \ + ${INSTALL_PKGS} && \ + addgroup \ + --system \ + --gid 1995 \ + zabbix && \ + adduser \ + --system \ + --gecos "Zabbix monitoring system" \ + --disabled-password \ + --uid 1997 \ + --ingroup zabbix \ + --shell /sbin/nologin \ + --home ${ZABBIX_USER_HOME_DIR} \ + zabbix && \ + chgrp zabbix /usr/bin/nmap && \ + setcap cap_net_raw+eip /usr/bin/nmap && \ + mkdir -p ${ZABBIX_CONF_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/mibs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/snmptraps && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssh_keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/certs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/ssl_ca && \ + mkdir -p /usr/lib/zabbix/externalscripts && \ + mkdir -p /usr/share/doc/zabbix-proxy-postgresql && \ + chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod u+s ${ZBX_FPINGLOCATION} && \ + /usr/sbin/zabbix_proxy -V + +EXPOSE 10051/TCP + +WORKDIR ${ZABBIX_USER_HOME_DIR} + +VOLUME ["${ZABBIX_USER_HOME_DIR}/snmptraps"] + +COPY ["docker-entrypoint.sh", "/usr/bin/"] + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +USER 1997 + +CMD ["/usr/sbin/zabbix_proxy", "--foreground", "-c", "/etc/zabbix/zabbix_proxy.conf"] diff --git a/Dockerfiles/proxy-pgsql/alpine/README.md b/Dockerfiles/proxy-pgsql/alpine/README.md new file mode 120000 index 0000000000..32d46ee883 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/alpine/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/alpine/build.sh b/Dockerfiles/proxy-pgsql/alpine/build.sh new file mode 120000 index 0000000000..46b2031346 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/alpine/build.sh @@ -0,0 +1 @@ +../../../build.sh \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh new file mode 100755 index 0000000000..d5aa604c3b --- /dev/null +++ b/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh @@ -0,0 +1,606 @@ +#!/bin/bash + +set -o pipefail + +set +e + +# Script trace mode +if [ "${DEBUG_MODE,,}" == "true" ]; then + set -o xtrace +fi + +# Default Zabbix server host +: ${ZBX_SERVER_HOST:="zabbix-server"} + +# Default directories +# Internal directory for TLS related files, used when TLS*File specified as plain text values +ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" + +: ${DB_CHARACTER_SET:="utf8mb4"} +: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} + +# usage: file_env VAR [DEFAULT] +# as example: file_env 'MYSQL_PASSWORD' 'zabbix' +# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) +# unsets the VAR_FILE afterwards and just leaving VAR +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local defaultValue="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo "**** Both variables $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$defaultValue" + + if [ "${!var:-}" ]; then + val="${!var}" + echo "** Using ${var} variable from ENV" + elif [ "${!fileVar:-}" ]; then + if [ ! -f "${!fileVar}" ]; then + echo "**** Secret file \"${!fileVar}\" is not found" + exit 1 + fi + val="$(< "${!fileVar}")" + echo "** Using ${var} variable from secret file" + fi + export "$var"="$val" + unset "$fileVar" +} + +escape_spec_char() { + local var_value=$1 + + var_value="${var_value//\\/\\\\}" + var_value="${var_value//[$'\n']/}" + var_value="${var_value//\//\\/}" + var_value="${var_value//./\\.}" + var_value="${var_value//\*/\\*}" + var_value="${var_value//^/\\^}" + var_value="${var_value//\$/\\\$}" + var_value="${var_value//\&/\\\&}" + var_value="${var_value//\[/\\[}" + var_value="${var_value//\]/\\]}" + + echo "$var_value" +} + +update_config_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + local is_multiple=$4 + + local masklist=("DBPassword TLSPSKIdentity") + + if [ ! -f "$config_path" ]; then + echo "**** Configuration file '$config_path' does not exist" + return + fi + + if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then + echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..." + else + echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." + fi + + # Remove configuration parameter definition in case of unset or empty parameter value + if [ -z "$var_value" ]; then + sed -i -e "/^$var_name=/d" "$config_path" + echo "removed" + return + fi + + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi + echo "undefined" + return + fi + + # Use full path to a file for TLS related configuration parameters + if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then + var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value + fi + + # Escaping characters in parameter value and name + var_value=$(escape_spec_char "$var_value") + var_name=$(escape_spec_char "$var_name") + + if [ "$(grep -E "^$var_name=$var_value$" $config_path)" ]; then + echo "exists" + elif [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then + sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path" + echo "updated" + elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then + sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path" + echo "added first occurrence" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path" + echo "added" + fi + +} + +update_config_multiple_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + + var_value="${var_value%\"}" + var_value="${var_value#\"}" + + local IFS=, + local OPT_LIST=($var_value) + + for value in "${OPT_LIST[@]}"; do + update_config_var $config_path $var_name $value true + done +} + +file_process_from_env() { + local config_path=$1 + local var_name=$2 + local file_name=$3 + local var_value=$4 + + if [ ! -z "$var_value" ]; then + echo -n "$var_value" > "${ZABBIX_INTERNAL_ENC_DIR}/$var_name" + file_name="${ZABBIX_INTERNAL_ENC_DIR}/${var_name}" + fi + update_config_var $config_path "$var_name" "$file_name" +} + +# Check prerequisites for PostgreSQL database +check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + + file_env POSTGRES_USER + file_env POSTGRES_PASSWORD + + DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} + DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} + + DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} + DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"} + + : ${DB_SERVER_SCHEMA:="public"} + + DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} + + : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi +} + +check_db_connect_postgresql() { + echo "********************" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi + echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" + echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" + if [ "${DEBUG_MODE,,}" == "true" ]; then + echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}" + echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}" + fi + echo "********************" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + WAIT_TIMEOUT=5 + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + while true : + do + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + + echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." + sleep $WAIT_TIMEOUT + done + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +psql_query() { + query=$1 + db=$2 + + local result="" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ + --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + + echo $result +} + +exec_sql_file() { + sql_script=$1 + + local command="cat" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + if [ "${sql_script: -3}" == ".gz" ]; then + command="zcat" + fi + + $command $sql_script | psql --quiet \ + $psql_connect_args \ + --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +create_db_database_postgresql() { + DB_EXISTS=$(psql_query "SELECT 1 AS result FROM pg_database WHERE datname='${DB_SERVER_DBNAME}'" "${DB_SERVER_DBNAME}") + + if [ -z ${DB_EXISTS} ]; then + echo "** Database '${DB_SERVER_DBNAME}' does not exist. Creating..." + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ + --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + else + echo "** Database '${DB_SERVER_DBNAME}' already exists. Please be careful with database owner!" + fi + + psql_query "CREATE SCHEMA IF NOT EXISTS ${DB_SERVER_SCHEMA}" "${DB_SERVER_DBNAME}" 1>/dev/null +} + +create_db_schema_postgresql() { + DBVERSION_TABLE_EXISTS=$(psql_query "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = + c.relnamespace WHERE n.nspname = '$DB_SERVER_SCHEMA' AND c.relname = 'dbversion'" "${DB_SERVER_DBNAME}") + + if [ -n "${DBVERSION_TABLE_EXISTS}" ]; then + echo "** Table '${DB_SERVER_DBNAME}.dbversion' already exists." + ZBX_DB_VERSION=$(psql_query "SELECT mandatory FROM ${DB_SERVER_SCHEMA}.dbversion" "${DB_SERVER_DBNAME}") + fi + + if [ -z "${ZBX_DB_VERSION}" ]; then + echo "** Creating '${DB_SERVER_DBNAME}' schema in PostgreSQL" + + exec_sql_file "/usr/share/doc/zabbix-proxy-postgresql/create.sql.gz" + fi +} + +update_zbx_config() { + echo "** Preparing Zabbix proxy configuration file" + + ZBX_CONFIG=${ZABBIX_CONF_DIR}/zabbix_proxy.conf + + update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}" + update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}" + if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then + update_config_var $ZBX_CONFIG "Hostname" "" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + else + update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-postgresql"}" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + fi + + update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}" + update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}" + update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}" + + update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}" + update_config_var $ZBX_CONFIG "LogType" "console" + update_config_var $ZBX_CONFIG "LogFile" + update_config_var $ZBX_CONFIG "LogFileSize" + update_config_var $ZBX_CONFIG "PidFile" + + update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}" + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + update_config_var $ZBX_CONFIG "DBTLSConnect" "${ZBX_DBTLSCONNECT}" + update_config_var $ZBX_CONFIG "DBTLSCAFile" "${ZBX_DBTLSCAFILE}" + update_config_var $ZBX_CONFIG "DBTLSCertFile" "${ZBX_DBTLSCERTFILE}" + update_config_var $ZBX_CONFIG "DBTLSKeyFile" "${ZBX_DBTLSKEYFILE}" + update_config_var $ZBX_CONFIG "DBTLSCipher" "${ZBX_DBTLSCIPHER}" + update_config_var $ZBX_CONFIG "DBTLSCipher13" "${ZBX_DBTLSCIPHER13}" + fi + + update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}" + update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}" + + if [ ! -n "${DB_SERVER_SOCKET}" ]; then + update_config_var $ZBX_CONFIG "DBHost" "${DB_SERVER_HOST}" + update_config_var $ZBX_CONFIG "DBPort" "${DB_SERVER_PORT}" + else + update_config_var $ZBX_CONFIG "DBHost" + update_config_var $ZBX_CONFIG "DBPort" + fi + update_config_var $ZBX_CONFIG "DBSocket" "${DB_SERVER_SOCKET}" + update_config_var $ZBX_CONFIG "DBName" "${DB_SERVER_DBNAME}" + update_config_var $ZBX_CONFIG "DBSchema" "${DB_SERVER_SCHEMA}" + + if [ -n "${ZBX_VAULTDBPATH}" ] && [ -n "${ZBX_VAULTURL}" ]; then + update_config_var $ZBX_CONFIG "Vault" "${ZBX_VAULT}" + update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" "${ZBX_VAULTTLSCERTFILE}" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" "${ZBX_VAULTTLSKEYFILE}" + update_config_var $ZBX_CONFIG "VaultPrefix" "${ZBX_VAULTPREFIX}" + update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}" + update_config_var $ZBX_CONFIG "DBUser" + update_config_var $ZBX_CONFIG "DBPassword" + else + update_config_var $ZBX_CONFIG "Vault" + update_config_var $ZBX_CONFIG "VaultDBPath" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" + update_config_var $ZBX_CONFIG "VaultPrefix" + update_config_var $ZBX_CONFIG "VaultURL" + update_config_var $ZBX_CONFIG "DBUser" "${DB_SERVER_ZBX_USER}" + update_config_var $ZBX_CONFIG "DBPassword" "${DB_SERVER_ZBX_PASS}" + fi + + update_config_var $ZBX_CONFIG "AllowUnsupportedDBVersions" "${ZBX_ALLOWUNSUPPORTEDDBVERSIONS}" + update_config_var $ZBX_CONFIG "MaxConcurrentChecksPerPoller" "${ZBX_MAXCONCURRENTCHECKSPERPOLLER}" + + update_config_var $ZBX_CONFIG "ProxyBufferMode" "${ZBX_PROXYBUFFERMODE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferAge" "${ZBX_PROXYMEMORYBUFFERAGE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferSize" "${ZBX_PROXYMEMORYBUFFERSIZE}" + + update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}" + update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}" + update_config_var $ZBX_CONFIG "ProxyConfigFrequency" "${ZBX_PROXYCONFIGFREQUENCY}" + update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}" + + update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}" + update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}" + + update_config_var $ZBX_CONFIG "StartAgentPollers" "${ZBX_STARTAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}" + update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_STARTIPMIPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}" + update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}" + update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}" + update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}" + update_config_var $ZBX_CONFIG "StartHTTPAgentPollers" "${ZBX_STARTHTTPAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}" + update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}" + update_config_var $ZBX_CONFIG "StartSNMPPollers" "${ZBX_STARTSNMPPOLLERS}" + + : ${ZBX_JAVAGATEWAY_ENABLE:="false"} + if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}" + update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}" + update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}" + else + update_config_var $ZBX_CONFIG "JavaGateway" + update_config_var $ZBX_CONFIG "JavaGatewayPort" + update_config_var $ZBX_CONFIG "StartJavaPollers" + fi + + update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}" + update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}" + update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}" + + : ${ZBX_ENABLE_SNMP_TRAPS:="false"} + if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1" + else + update_config_var $ZBX_CONFIG "SNMPTrapperFile" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" + fi + + update_config_var $ZBX_CONFIG "SocketDir" "/tmp/" + update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}" + + update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}" + + update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}" + update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}" + update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}" + + update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}" + update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}" + update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}" + update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}" + update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}" + + update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts" + + update_config_var $ZBX_CONFIG "FpingLocation" "${ZBX_FPINGLOCATION}" + update_config_var $ZBX_CONFIG "Fping6Location" '""' + + update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys" + update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}" + + update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/" + update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/" + update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" + update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/" + update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}" + + update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}" + update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}" + file_process_from_env $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}" "${ZBX_TLSCA}" + file_process_from_env $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}" "${ZBX_TLSCRL}" + + update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}" + update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}" + + file_process_from_env $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}" "${ZBX_TLSCERT}" + update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}" + update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}" + update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}" + update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}" + update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}" + update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}" + file_process_from_env $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}" "${ZBX_TLSKEY}" + + update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}" + file_process_from_env $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}" "${ZBX_TLSPSK}" + + if [ "$(id -u)" != '0' ]; then + update_config_var $ZBX_CONFIG "User" "$(whoami)" + else + update_config_var $ZBX_CONFIG "AllowRoot" "1" + fi + + update_config_var $ZBX_CONFIG "WebDriverURL" "${ZBX_WEBDRIVERURL}" + update_config_var $ZBX_CONFIG "StartBrowserPollers" "${ZBX_STARTBROWSERPOLLERS}" + + command -v openssl >/dev/null 2>&1 && openssl rehash -v "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" 1>/dev/null +} + +clear_zbx_env() { + [[ "${ZBX_CLEAR_ENV}" == "false" ]] && return + + for env_var in $(env | grep -E "^(ZBX|DB|POSTGRES)_"); do + unset "${env_var%%=*}" + done +} + +prepare_db() { + echo "** Preparing database" + + check_variables_postgresql + check_db_connect_postgresql + create_db_database_postgresql + create_db_schema_postgresql +} + +prepare_proxy() { + echo "** Preparing Zabbix proxy" + + prepare_db + update_zbx_config + clear_zbx_env +} + +################################################# + +if [ "${1#-}" != "$1" ]; then + set -- /usr/sbin/zabbix_proxy "$@" +fi + +if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then + prepare_proxy +fi + +if [ "$1" == "init_db_only" ]; then + prepare_db +else + + # Additional configuration every startup + if [ -d "${ZABBIX_USER_HOME_DIR}/dbscripts/startup" ]; then + for sql_script in "${ZABBIX_USER_HOME_DIR}/dbscripts/startup/*.sql"; do + [ -e "$sql_script" ] || continue + echo "** Processing additional '$sql_script' SQL script" + + exec_sql_file "$sql_script" + done + fi + + exec "$@" +fi + +################################################# diff --git a/Dockerfiles/proxy-pgsql/centos/.dockerignore b/Dockerfiles/proxy-pgsql/centos/.dockerignore new file mode 100644 index 0000000000..88a84e55aa --- /dev/null +++ b/Dockerfiles/proxy-pgsql/centos/.dockerignore @@ -0,0 +1 @@ +build.sh diff --git a/Dockerfiles/proxy-pgsql/centos/Dockerfile b/Dockerfiles/proxy-pgsql/centos/Dockerfile new file mode 100644 index 0000000000..8be5ad6a02 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/centos/Dockerfile @@ -0,0 +1,139 @@ +# syntax=docker/dockerfile:1 +ARG OS_BASE_IMAGE=quay.io/centos/centos:stream9-minimal +ARG MAJOR_VERSION=7.0 +ARG ZBX_VERSION=${MAJOR_VERSION}.17 +ARG BUILD_BASE_IMAGE=zabbix-build-pgsql:centos-${ZBX_VERSION} + +FROM ${BUILD_BASE_IMAGE} AS builder + +FROM ${OS_BASE_IMAGE} + +ARG MAJOR_VERSION +ARG ZBX_VERSION +ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git + +ENV TERM=xterm \ + ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \ + MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \ + NMAP_PRIVILEGED="" \ + ZABBIX_USER_HOME_DIR="/var/lib/zabbix" \ + ZABBIX_CONF_DIR="/etc/zabbix" \ + ZBX_FPINGLOCATION="/usr/sbin/fping" + +LABEL org.opencontainers.image.authors="Alexey Pustovalov " \ + org.opencontainers.image.description="Zabbix proxy with PostgreSQL database support" \ + org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" \ + org.opencontainers.image.licenses="AGPL v3.0" \ + org.opencontainers.image.source="${ZBX_SOURCES}" \ + org.opencontainers.image.title="Zabbix proxy (PostgreSQL)" \ + org.opencontainers.image.url="https://zabbix.com/" \ + org.opencontainers.image.vendor="Zabbix SIA" \ + org.opencontainers.image.version="${ZBX_VERSION}" + +STOPSIGNAL SIGTERM + +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy", "/usr/sbin/zabbix_proxy"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/general/bin/*", "/usr/bin/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/", "${ZABBIX_CONF_DIR}/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/database/postgresql/", "/usr/share/doc/zabbix-proxy-postgresql/"] + +RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ + --mount=type=tmpfs,target=/var/cache/yum/ \ + set -eux && \ + INSTALL_PKGS="bash \ + libevent \ + traceroute \ + nmap \ + krb5-workstation \ + gzip \ + libssh \ + file-libs \ + fping \ + iputils \ + libxml2 \ + net-snmp-libs \ + OpenIPMI-libs \ + openldap \ + openssl \ + openssl-libs \ + pcre2 \ + postgresql \ + postgresql-private-libs \ + shadow-utils \ + zlib \ + unixODBC" && \ + microdnf -y install \ + --disablerepo "*" \ + --enablerepo "extras-common" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + --best \ + --nodocs epel-release && \ + microdnf -y module enable \ + --disablerepo "*" \ + --enablerepo "appstream" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + postgresql:16 && \ + microdnf -y install \ + --disablerepo "*" \ + --enablerepo "baseos" \ + --enablerepo "appstream" \ + --enablerepo="epel" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + --best \ + --nodocs ${INSTALL_PKGS} && \ + microdnf -y reinstall \ + --enablerepo "baseos" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + --best \ + --setopt=tsflags=nodocs \ + tzdata && \ + groupadd \ + --system \ + --gid 1995 \ + zabbix && \ + useradd \ + --system \ + --comment "Zabbix monitoring system" \ + -g zabbix \ + --uid 1997 \ + --shell /sbin/nologin \ + --home-dir ${ZABBIX_USER_HOME_DIR} \ + zabbix && \ + chgrp zabbix /usr/bin/nmap && \ + setcap cap_net_raw+eip /usr/bin/nmap && \ + mkdir -p ${ZABBIX_CONF_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/mibs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/snmptraps && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssh_keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/certs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/ssl_ca && \ + mkdir -p /usr/lib/zabbix/externalscripts && \ + mkdir -p /usr/share/doc/zabbix-proxy-postgresql && \ + chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + /usr/sbin/zabbix_proxy -V + +EXPOSE 10051/TCP + +WORKDIR ${ZABBIX_USER_HOME_DIR} + +VOLUME ["${ZABBIX_USER_HOME_DIR}/snmptraps"] + +COPY ["docker-entrypoint.sh", "/usr/bin/"] + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +USER 1997 + +CMD ["/usr/sbin/zabbix_proxy", "--foreground", "-c", "/etc/zabbix/zabbix_proxy.conf"] diff --git a/Dockerfiles/proxy-pgsql/centos/README.md b/Dockerfiles/proxy-pgsql/centos/README.md new file mode 120000 index 0000000000..32d46ee883 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/centos/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/centos/build.sh b/Dockerfiles/proxy-pgsql/centos/build.sh new file mode 120000 index 0000000000..46b2031346 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/centos/build.sh @@ -0,0 +1 @@ +../../../build.sh \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh new file mode 100755 index 0000000000..d5aa604c3b --- /dev/null +++ b/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh @@ -0,0 +1,606 @@ +#!/bin/bash + +set -o pipefail + +set +e + +# Script trace mode +if [ "${DEBUG_MODE,,}" == "true" ]; then + set -o xtrace +fi + +# Default Zabbix server host +: ${ZBX_SERVER_HOST:="zabbix-server"} + +# Default directories +# Internal directory for TLS related files, used when TLS*File specified as plain text values +ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" + +: ${DB_CHARACTER_SET:="utf8mb4"} +: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} + +# usage: file_env VAR [DEFAULT] +# as example: file_env 'MYSQL_PASSWORD' 'zabbix' +# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) +# unsets the VAR_FILE afterwards and just leaving VAR +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local defaultValue="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo "**** Both variables $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$defaultValue" + + if [ "${!var:-}" ]; then + val="${!var}" + echo "** Using ${var} variable from ENV" + elif [ "${!fileVar:-}" ]; then + if [ ! -f "${!fileVar}" ]; then + echo "**** Secret file \"${!fileVar}\" is not found" + exit 1 + fi + val="$(< "${!fileVar}")" + echo "** Using ${var} variable from secret file" + fi + export "$var"="$val" + unset "$fileVar" +} + +escape_spec_char() { + local var_value=$1 + + var_value="${var_value//\\/\\\\}" + var_value="${var_value//[$'\n']/}" + var_value="${var_value//\//\\/}" + var_value="${var_value//./\\.}" + var_value="${var_value//\*/\\*}" + var_value="${var_value//^/\\^}" + var_value="${var_value//\$/\\\$}" + var_value="${var_value//\&/\\\&}" + var_value="${var_value//\[/\\[}" + var_value="${var_value//\]/\\]}" + + echo "$var_value" +} + +update_config_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + local is_multiple=$4 + + local masklist=("DBPassword TLSPSKIdentity") + + if [ ! -f "$config_path" ]; then + echo "**** Configuration file '$config_path' does not exist" + return + fi + + if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then + echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..." + else + echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." + fi + + # Remove configuration parameter definition in case of unset or empty parameter value + if [ -z "$var_value" ]; then + sed -i -e "/^$var_name=/d" "$config_path" + echo "removed" + return + fi + + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi + echo "undefined" + return + fi + + # Use full path to a file for TLS related configuration parameters + if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then + var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value + fi + + # Escaping characters in parameter value and name + var_value=$(escape_spec_char "$var_value") + var_name=$(escape_spec_char "$var_name") + + if [ "$(grep -E "^$var_name=$var_value$" $config_path)" ]; then + echo "exists" + elif [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then + sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path" + echo "updated" + elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then + sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path" + echo "added first occurrence" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path" + echo "added" + fi + +} + +update_config_multiple_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + + var_value="${var_value%\"}" + var_value="${var_value#\"}" + + local IFS=, + local OPT_LIST=($var_value) + + for value in "${OPT_LIST[@]}"; do + update_config_var $config_path $var_name $value true + done +} + +file_process_from_env() { + local config_path=$1 + local var_name=$2 + local file_name=$3 + local var_value=$4 + + if [ ! -z "$var_value" ]; then + echo -n "$var_value" > "${ZABBIX_INTERNAL_ENC_DIR}/$var_name" + file_name="${ZABBIX_INTERNAL_ENC_DIR}/${var_name}" + fi + update_config_var $config_path "$var_name" "$file_name" +} + +# Check prerequisites for PostgreSQL database +check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + + file_env POSTGRES_USER + file_env POSTGRES_PASSWORD + + DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} + DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} + + DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} + DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"} + + : ${DB_SERVER_SCHEMA:="public"} + + DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} + + : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi +} + +check_db_connect_postgresql() { + echo "********************" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi + echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" + echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" + if [ "${DEBUG_MODE,,}" == "true" ]; then + echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}" + echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}" + fi + echo "********************" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + WAIT_TIMEOUT=5 + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + while true : + do + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + + echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." + sleep $WAIT_TIMEOUT + done + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +psql_query() { + query=$1 + db=$2 + + local result="" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ + --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + + echo $result +} + +exec_sql_file() { + sql_script=$1 + + local command="cat" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + if [ "${sql_script: -3}" == ".gz" ]; then + command="zcat" + fi + + $command $sql_script | psql --quiet \ + $psql_connect_args \ + --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +create_db_database_postgresql() { + DB_EXISTS=$(psql_query "SELECT 1 AS result FROM pg_database WHERE datname='${DB_SERVER_DBNAME}'" "${DB_SERVER_DBNAME}") + + if [ -z ${DB_EXISTS} ]; then + echo "** Database '${DB_SERVER_DBNAME}' does not exist. Creating..." + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ + --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + else + echo "** Database '${DB_SERVER_DBNAME}' already exists. Please be careful with database owner!" + fi + + psql_query "CREATE SCHEMA IF NOT EXISTS ${DB_SERVER_SCHEMA}" "${DB_SERVER_DBNAME}" 1>/dev/null +} + +create_db_schema_postgresql() { + DBVERSION_TABLE_EXISTS=$(psql_query "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = + c.relnamespace WHERE n.nspname = '$DB_SERVER_SCHEMA' AND c.relname = 'dbversion'" "${DB_SERVER_DBNAME}") + + if [ -n "${DBVERSION_TABLE_EXISTS}" ]; then + echo "** Table '${DB_SERVER_DBNAME}.dbversion' already exists." + ZBX_DB_VERSION=$(psql_query "SELECT mandatory FROM ${DB_SERVER_SCHEMA}.dbversion" "${DB_SERVER_DBNAME}") + fi + + if [ -z "${ZBX_DB_VERSION}" ]; then + echo "** Creating '${DB_SERVER_DBNAME}' schema in PostgreSQL" + + exec_sql_file "/usr/share/doc/zabbix-proxy-postgresql/create.sql.gz" + fi +} + +update_zbx_config() { + echo "** Preparing Zabbix proxy configuration file" + + ZBX_CONFIG=${ZABBIX_CONF_DIR}/zabbix_proxy.conf + + update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}" + update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}" + if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then + update_config_var $ZBX_CONFIG "Hostname" "" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + else + update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-postgresql"}" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + fi + + update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}" + update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}" + update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}" + + update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}" + update_config_var $ZBX_CONFIG "LogType" "console" + update_config_var $ZBX_CONFIG "LogFile" + update_config_var $ZBX_CONFIG "LogFileSize" + update_config_var $ZBX_CONFIG "PidFile" + + update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}" + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + update_config_var $ZBX_CONFIG "DBTLSConnect" "${ZBX_DBTLSCONNECT}" + update_config_var $ZBX_CONFIG "DBTLSCAFile" "${ZBX_DBTLSCAFILE}" + update_config_var $ZBX_CONFIG "DBTLSCertFile" "${ZBX_DBTLSCERTFILE}" + update_config_var $ZBX_CONFIG "DBTLSKeyFile" "${ZBX_DBTLSKEYFILE}" + update_config_var $ZBX_CONFIG "DBTLSCipher" "${ZBX_DBTLSCIPHER}" + update_config_var $ZBX_CONFIG "DBTLSCipher13" "${ZBX_DBTLSCIPHER13}" + fi + + update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}" + update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}" + + if [ ! -n "${DB_SERVER_SOCKET}" ]; then + update_config_var $ZBX_CONFIG "DBHost" "${DB_SERVER_HOST}" + update_config_var $ZBX_CONFIG "DBPort" "${DB_SERVER_PORT}" + else + update_config_var $ZBX_CONFIG "DBHost" + update_config_var $ZBX_CONFIG "DBPort" + fi + update_config_var $ZBX_CONFIG "DBSocket" "${DB_SERVER_SOCKET}" + update_config_var $ZBX_CONFIG "DBName" "${DB_SERVER_DBNAME}" + update_config_var $ZBX_CONFIG "DBSchema" "${DB_SERVER_SCHEMA}" + + if [ -n "${ZBX_VAULTDBPATH}" ] && [ -n "${ZBX_VAULTURL}" ]; then + update_config_var $ZBX_CONFIG "Vault" "${ZBX_VAULT}" + update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" "${ZBX_VAULTTLSCERTFILE}" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" "${ZBX_VAULTTLSKEYFILE}" + update_config_var $ZBX_CONFIG "VaultPrefix" "${ZBX_VAULTPREFIX}" + update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}" + update_config_var $ZBX_CONFIG "DBUser" + update_config_var $ZBX_CONFIG "DBPassword" + else + update_config_var $ZBX_CONFIG "Vault" + update_config_var $ZBX_CONFIG "VaultDBPath" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" + update_config_var $ZBX_CONFIG "VaultPrefix" + update_config_var $ZBX_CONFIG "VaultURL" + update_config_var $ZBX_CONFIG "DBUser" "${DB_SERVER_ZBX_USER}" + update_config_var $ZBX_CONFIG "DBPassword" "${DB_SERVER_ZBX_PASS}" + fi + + update_config_var $ZBX_CONFIG "AllowUnsupportedDBVersions" "${ZBX_ALLOWUNSUPPORTEDDBVERSIONS}" + update_config_var $ZBX_CONFIG "MaxConcurrentChecksPerPoller" "${ZBX_MAXCONCURRENTCHECKSPERPOLLER}" + + update_config_var $ZBX_CONFIG "ProxyBufferMode" "${ZBX_PROXYBUFFERMODE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferAge" "${ZBX_PROXYMEMORYBUFFERAGE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferSize" "${ZBX_PROXYMEMORYBUFFERSIZE}" + + update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}" + update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}" + update_config_var $ZBX_CONFIG "ProxyConfigFrequency" "${ZBX_PROXYCONFIGFREQUENCY}" + update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}" + + update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}" + update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}" + + update_config_var $ZBX_CONFIG "StartAgentPollers" "${ZBX_STARTAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}" + update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_STARTIPMIPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}" + update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}" + update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}" + update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}" + update_config_var $ZBX_CONFIG "StartHTTPAgentPollers" "${ZBX_STARTHTTPAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}" + update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}" + update_config_var $ZBX_CONFIG "StartSNMPPollers" "${ZBX_STARTSNMPPOLLERS}" + + : ${ZBX_JAVAGATEWAY_ENABLE:="false"} + if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}" + update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}" + update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}" + else + update_config_var $ZBX_CONFIG "JavaGateway" + update_config_var $ZBX_CONFIG "JavaGatewayPort" + update_config_var $ZBX_CONFIG "StartJavaPollers" + fi + + update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}" + update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}" + update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}" + + : ${ZBX_ENABLE_SNMP_TRAPS:="false"} + if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1" + else + update_config_var $ZBX_CONFIG "SNMPTrapperFile" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" + fi + + update_config_var $ZBX_CONFIG "SocketDir" "/tmp/" + update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}" + + update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}" + + update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}" + update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}" + update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}" + + update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}" + update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}" + update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}" + update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}" + update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}" + + update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts" + + update_config_var $ZBX_CONFIG "FpingLocation" "${ZBX_FPINGLOCATION}" + update_config_var $ZBX_CONFIG "Fping6Location" '""' + + update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys" + update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}" + + update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/" + update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/" + update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" + update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/" + update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}" + + update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}" + update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}" + file_process_from_env $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}" "${ZBX_TLSCA}" + file_process_from_env $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}" "${ZBX_TLSCRL}" + + update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}" + update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}" + + file_process_from_env $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}" "${ZBX_TLSCERT}" + update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}" + update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}" + update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}" + update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}" + update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}" + update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}" + file_process_from_env $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}" "${ZBX_TLSKEY}" + + update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}" + file_process_from_env $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}" "${ZBX_TLSPSK}" + + if [ "$(id -u)" != '0' ]; then + update_config_var $ZBX_CONFIG "User" "$(whoami)" + else + update_config_var $ZBX_CONFIG "AllowRoot" "1" + fi + + update_config_var $ZBX_CONFIG "WebDriverURL" "${ZBX_WEBDRIVERURL}" + update_config_var $ZBX_CONFIG "StartBrowserPollers" "${ZBX_STARTBROWSERPOLLERS}" + + command -v openssl >/dev/null 2>&1 && openssl rehash -v "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" 1>/dev/null +} + +clear_zbx_env() { + [[ "${ZBX_CLEAR_ENV}" == "false" ]] && return + + for env_var in $(env | grep -E "^(ZBX|DB|POSTGRES)_"); do + unset "${env_var%%=*}" + done +} + +prepare_db() { + echo "** Preparing database" + + check_variables_postgresql + check_db_connect_postgresql + create_db_database_postgresql + create_db_schema_postgresql +} + +prepare_proxy() { + echo "** Preparing Zabbix proxy" + + prepare_db + update_zbx_config + clear_zbx_env +} + +################################################# + +if [ "${1#-}" != "$1" ]; then + set -- /usr/sbin/zabbix_proxy "$@" +fi + +if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then + prepare_proxy +fi + +if [ "$1" == "init_db_only" ]; then + prepare_db +else + + # Additional configuration every startup + if [ -d "${ZABBIX_USER_HOME_DIR}/dbscripts/startup" ]; then + for sql_script in "${ZABBIX_USER_HOME_DIR}/dbscripts/startup/*.sql"; do + [ -e "$sql_script" ] || continue + echo "** Processing additional '$sql_script' SQL script" + + exec_sql_file "$sql_script" + done + fi + + exec "$@" +fi + +################################################# diff --git a/Dockerfiles/proxy-pgsql/ol/.dockerignore b/Dockerfiles/proxy-pgsql/ol/.dockerignore new file mode 100644 index 0000000000..88a84e55aa --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/.dockerignore @@ -0,0 +1 @@ +build.sh diff --git a/Dockerfiles/proxy-pgsql/ol/Dockerfile b/Dockerfiles/proxy-pgsql/ol/Dockerfile new file mode 100644 index 0000000000..c695f7588e --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/Dockerfile @@ -0,0 +1,127 @@ +# syntax=docker/dockerfile:1 +ARG OS_BASE_IMAGE=oraclelinux:9-slim +ARG MAJOR_VERSION=7.0 +ARG ZBX_VERSION=${MAJOR_VERSION}.17 +ARG BUILD_BASE_IMAGE=zabbix-build-pgsql:ol-${ZBX_VERSION} + +FROM ${BUILD_BASE_IMAGE} AS builder + +FROM ${OS_BASE_IMAGE} + +ARG MAJOR_VERSION +ARG ZBX_VERSION +ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git + +ENV TERM=xterm \ + ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \ + MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \ + NMAP_PRIVILEGED="" \ + ZABBIX_USER_HOME_DIR="/var/lib/zabbix" \ + ZABBIX_CONF_DIR="/etc/zabbix" \ + ZBX_FPINGLOCATION="/usr/sbin/fping" + +LABEL org.opencontainers.image.authors="Alexey Pustovalov " \ + org.opencontainers.image.description="Zabbix proxy with PostgreSQL database support" \ + org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" \ + org.opencontainers.image.licenses="AGPL v3.0" \ + org.opencontainers.image.source="${ZBX_SOURCES}" \ + org.opencontainers.image.title="Zabbix proxy (PostgreSQL)" \ + org.opencontainers.image.url="https://zabbix.com/" \ + org.opencontainers.image.vendor="Zabbix SIA" \ + org.opencontainers.image.version="${ZBX_VERSION}" + +STOPSIGNAL SIGTERM + +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy", "/usr/sbin/zabbix_proxy"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/general/bin/*", "/usr/bin/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/", "${ZABBIX_CONF_DIR}/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/database/postgresql/", "/usr/share/doc/zabbix-proxy-postgresql/"] +COPY ["conf/etc/yum.repos.d/oracle-epel-ol9.repo", "/etc/yum.repos.d/oracle-epel-ol9.repo"] + +RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ + --mount=type=tmpfs,target=/var/cache/yum/ \ + set -eux && \ + INSTALL_PKGS="bash \ + libevent \ + traceroute \ + nmap \ + krb5-workstation \ + libssh \ + file-libs \ + fping \ + iputils \ + libxml2 \ + net-snmp-libs \ + OpenIPMI-libs \ + openldap \ + openssl \ + openssl-libs \ + pcre2 \ + postgresql \ + postgresql-private-libs \ + zlib \ + gzip \ + unixODBC" && \ + microdnf -y module enable \ + --disablerepo "*" \ + --enablerepo "ol9_baseos_latest" \ + --enablerepo "ol9_appstream" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + postgresql:16 && \ + microdnf -y install \ + --disablerepo="*" \ + --enablerepo="ol9_baseos_latest" \ + --enablerepo="ol9_appstream" \ + --enablerepo="ol9_developer_EPEL" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + --best \ + --nodocs \ + ${INSTALL_PKGS} && \ + groupadd \ + --system \ + --gid 1995 \ + zabbix && \ + useradd \ + --system \ + --comment "Zabbix monitoring system" \ + -g zabbix \ + --uid 1997 \ + --shell /sbin/nologin \ + --home-dir ${ZABBIX_USER_HOME_DIR} \ + zabbix && \ + chgrp zabbix /usr/bin/nmap && \ + setcap cap_net_raw+eip /usr/bin/nmap && \ + mkdir -p ${ZABBIX_CONF_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/mibs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/snmptraps && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssh_keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/certs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/ssl_ca && \ + mkdir -p /usr/lib/zabbix/externalscripts && \ + mkdir -p /usr/share/doc/zabbix-proxy-postgresql && \ + chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + /usr/sbin/zabbix_proxy -V + +EXPOSE 10051/TCP + +WORKDIR ${ZABBIX_USER_HOME_DIR} + +VOLUME ["${ZABBIX_USER_HOME_DIR}/snmptraps"] + +COPY ["docker-entrypoint.sh", "/usr/bin/"] + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +USER 1997 + +CMD ["/usr/sbin/zabbix_proxy", "--foreground", "-c", "/etc/zabbix/zabbix_proxy.conf"] diff --git a/Dockerfiles/proxy-pgsql/ol/README.md b/Dockerfiles/proxy-pgsql/ol/README.md new file mode 120000 index 0000000000..32d46ee883 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/ol/build.sh b/Dockerfiles/proxy-pgsql/ol/build.sh new file mode 120000 index 0000000000..46b2031346 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/build.sh @@ -0,0 +1 @@ +../../../build.sh \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/ol/conf/etc/yum.repos.d/oracle-epel-ol9.repo b/Dockerfiles/proxy-pgsql/ol/conf/etc/yum.repos.d/oracle-epel-ol9.repo new file mode 100644 index 0000000000..7fa64dc118 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/conf/etc/yum.repos.d/oracle-epel-ol9.repo @@ -0,0 +1,6 @@ +[ol9_developer_EPEL] +name=Oracle Linux $releasever EPEL Packages for Development ($basearch) +baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL9/developer/EPEL/$basearch/ +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle +gpgcheck=1 +enabled=0 diff --git a/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh new file mode 100755 index 0000000000..d5aa604c3b --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh @@ -0,0 +1,606 @@ +#!/bin/bash + +set -o pipefail + +set +e + +# Script trace mode +if [ "${DEBUG_MODE,,}" == "true" ]; then + set -o xtrace +fi + +# Default Zabbix server host +: ${ZBX_SERVER_HOST:="zabbix-server"} + +# Default directories +# Internal directory for TLS related files, used when TLS*File specified as plain text values +ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" + +: ${DB_CHARACTER_SET:="utf8mb4"} +: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} + +# usage: file_env VAR [DEFAULT] +# as example: file_env 'MYSQL_PASSWORD' 'zabbix' +# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) +# unsets the VAR_FILE afterwards and just leaving VAR +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local defaultValue="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo "**** Both variables $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$defaultValue" + + if [ "${!var:-}" ]; then + val="${!var}" + echo "** Using ${var} variable from ENV" + elif [ "${!fileVar:-}" ]; then + if [ ! -f "${!fileVar}" ]; then + echo "**** Secret file \"${!fileVar}\" is not found" + exit 1 + fi + val="$(< "${!fileVar}")" + echo "** Using ${var} variable from secret file" + fi + export "$var"="$val" + unset "$fileVar" +} + +escape_spec_char() { + local var_value=$1 + + var_value="${var_value//\\/\\\\}" + var_value="${var_value//[$'\n']/}" + var_value="${var_value//\//\\/}" + var_value="${var_value//./\\.}" + var_value="${var_value//\*/\\*}" + var_value="${var_value//^/\\^}" + var_value="${var_value//\$/\\\$}" + var_value="${var_value//\&/\\\&}" + var_value="${var_value//\[/\\[}" + var_value="${var_value//\]/\\]}" + + echo "$var_value" +} + +update_config_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + local is_multiple=$4 + + local masklist=("DBPassword TLSPSKIdentity") + + if [ ! -f "$config_path" ]; then + echo "**** Configuration file '$config_path' does not exist" + return + fi + + if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then + echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..." + else + echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." + fi + + # Remove configuration parameter definition in case of unset or empty parameter value + if [ -z "$var_value" ]; then + sed -i -e "/^$var_name=/d" "$config_path" + echo "removed" + return + fi + + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi + echo "undefined" + return + fi + + # Use full path to a file for TLS related configuration parameters + if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then + var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value + fi + + # Escaping characters in parameter value and name + var_value=$(escape_spec_char "$var_value") + var_name=$(escape_spec_char "$var_name") + + if [ "$(grep -E "^$var_name=$var_value$" $config_path)" ]; then + echo "exists" + elif [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then + sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path" + echo "updated" + elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then + sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path" + echo "added first occurrence" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path" + echo "added" + fi + +} + +update_config_multiple_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + + var_value="${var_value%\"}" + var_value="${var_value#\"}" + + local IFS=, + local OPT_LIST=($var_value) + + for value in "${OPT_LIST[@]}"; do + update_config_var $config_path $var_name $value true + done +} + +file_process_from_env() { + local config_path=$1 + local var_name=$2 + local file_name=$3 + local var_value=$4 + + if [ ! -z "$var_value" ]; then + echo -n "$var_value" > "${ZABBIX_INTERNAL_ENC_DIR}/$var_name" + file_name="${ZABBIX_INTERNAL_ENC_DIR}/${var_name}" + fi + update_config_var $config_path "$var_name" "$file_name" +} + +# Check prerequisites for PostgreSQL database +check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + + file_env POSTGRES_USER + file_env POSTGRES_PASSWORD + + DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} + DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} + + DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} + DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"} + + : ${DB_SERVER_SCHEMA:="public"} + + DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} + + : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi +} + +check_db_connect_postgresql() { + echo "********************" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi + echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" + echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" + if [ "${DEBUG_MODE,,}" == "true" ]; then + echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}" + echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}" + fi + echo "********************" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + WAIT_TIMEOUT=5 + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + while true : + do + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + + echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." + sleep $WAIT_TIMEOUT + done + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +psql_query() { + query=$1 + db=$2 + + local result="" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ + --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + + echo $result +} + +exec_sql_file() { + sql_script=$1 + + local command="cat" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + if [ "${sql_script: -3}" == ".gz" ]; then + command="zcat" + fi + + $command $sql_script | psql --quiet \ + $psql_connect_args \ + --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +create_db_database_postgresql() { + DB_EXISTS=$(psql_query "SELECT 1 AS result FROM pg_database WHERE datname='${DB_SERVER_DBNAME}'" "${DB_SERVER_DBNAME}") + + if [ -z ${DB_EXISTS} ]; then + echo "** Database '${DB_SERVER_DBNAME}' does not exist. Creating..." + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ + --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + else + echo "** Database '${DB_SERVER_DBNAME}' already exists. Please be careful with database owner!" + fi + + psql_query "CREATE SCHEMA IF NOT EXISTS ${DB_SERVER_SCHEMA}" "${DB_SERVER_DBNAME}" 1>/dev/null +} + +create_db_schema_postgresql() { + DBVERSION_TABLE_EXISTS=$(psql_query "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = + c.relnamespace WHERE n.nspname = '$DB_SERVER_SCHEMA' AND c.relname = 'dbversion'" "${DB_SERVER_DBNAME}") + + if [ -n "${DBVERSION_TABLE_EXISTS}" ]; then + echo "** Table '${DB_SERVER_DBNAME}.dbversion' already exists." + ZBX_DB_VERSION=$(psql_query "SELECT mandatory FROM ${DB_SERVER_SCHEMA}.dbversion" "${DB_SERVER_DBNAME}") + fi + + if [ -z "${ZBX_DB_VERSION}" ]; then + echo "** Creating '${DB_SERVER_DBNAME}' schema in PostgreSQL" + + exec_sql_file "/usr/share/doc/zabbix-proxy-postgresql/create.sql.gz" + fi +} + +update_zbx_config() { + echo "** Preparing Zabbix proxy configuration file" + + ZBX_CONFIG=${ZABBIX_CONF_DIR}/zabbix_proxy.conf + + update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}" + update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}" + if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then + update_config_var $ZBX_CONFIG "Hostname" "" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + else + update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-postgresql"}" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + fi + + update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}" + update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}" + update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}" + + update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}" + update_config_var $ZBX_CONFIG "LogType" "console" + update_config_var $ZBX_CONFIG "LogFile" + update_config_var $ZBX_CONFIG "LogFileSize" + update_config_var $ZBX_CONFIG "PidFile" + + update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}" + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + update_config_var $ZBX_CONFIG "DBTLSConnect" "${ZBX_DBTLSCONNECT}" + update_config_var $ZBX_CONFIG "DBTLSCAFile" "${ZBX_DBTLSCAFILE}" + update_config_var $ZBX_CONFIG "DBTLSCertFile" "${ZBX_DBTLSCERTFILE}" + update_config_var $ZBX_CONFIG "DBTLSKeyFile" "${ZBX_DBTLSKEYFILE}" + update_config_var $ZBX_CONFIG "DBTLSCipher" "${ZBX_DBTLSCIPHER}" + update_config_var $ZBX_CONFIG "DBTLSCipher13" "${ZBX_DBTLSCIPHER13}" + fi + + update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}" + update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}" + + if [ ! -n "${DB_SERVER_SOCKET}" ]; then + update_config_var $ZBX_CONFIG "DBHost" "${DB_SERVER_HOST}" + update_config_var $ZBX_CONFIG "DBPort" "${DB_SERVER_PORT}" + else + update_config_var $ZBX_CONFIG "DBHost" + update_config_var $ZBX_CONFIG "DBPort" + fi + update_config_var $ZBX_CONFIG "DBSocket" "${DB_SERVER_SOCKET}" + update_config_var $ZBX_CONFIG "DBName" "${DB_SERVER_DBNAME}" + update_config_var $ZBX_CONFIG "DBSchema" "${DB_SERVER_SCHEMA}" + + if [ -n "${ZBX_VAULTDBPATH}" ] && [ -n "${ZBX_VAULTURL}" ]; then + update_config_var $ZBX_CONFIG "Vault" "${ZBX_VAULT}" + update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" "${ZBX_VAULTTLSCERTFILE}" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" "${ZBX_VAULTTLSKEYFILE}" + update_config_var $ZBX_CONFIG "VaultPrefix" "${ZBX_VAULTPREFIX}" + update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}" + update_config_var $ZBX_CONFIG "DBUser" + update_config_var $ZBX_CONFIG "DBPassword" + else + update_config_var $ZBX_CONFIG "Vault" + update_config_var $ZBX_CONFIG "VaultDBPath" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" + update_config_var $ZBX_CONFIG "VaultPrefix" + update_config_var $ZBX_CONFIG "VaultURL" + update_config_var $ZBX_CONFIG "DBUser" "${DB_SERVER_ZBX_USER}" + update_config_var $ZBX_CONFIG "DBPassword" "${DB_SERVER_ZBX_PASS}" + fi + + update_config_var $ZBX_CONFIG "AllowUnsupportedDBVersions" "${ZBX_ALLOWUNSUPPORTEDDBVERSIONS}" + update_config_var $ZBX_CONFIG "MaxConcurrentChecksPerPoller" "${ZBX_MAXCONCURRENTCHECKSPERPOLLER}" + + update_config_var $ZBX_CONFIG "ProxyBufferMode" "${ZBX_PROXYBUFFERMODE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferAge" "${ZBX_PROXYMEMORYBUFFERAGE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferSize" "${ZBX_PROXYMEMORYBUFFERSIZE}" + + update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}" + update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}" + update_config_var $ZBX_CONFIG "ProxyConfigFrequency" "${ZBX_PROXYCONFIGFREQUENCY}" + update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}" + + update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}" + update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}" + + update_config_var $ZBX_CONFIG "StartAgentPollers" "${ZBX_STARTAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}" + update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_STARTIPMIPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}" + update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}" + update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}" + update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}" + update_config_var $ZBX_CONFIG "StartHTTPAgentPollers" "${ZBX_STARTHTTPAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}" + update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}" + update_config_var $ZBX_CONFIG "StartSNMPPollers" "${ZBX_STARTSNMPPOLLERS}" + + : ${ZBX_JAVAGATEWAY_ENABLE:="false"} + if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}" + update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}" + update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}" + else + update_config_var $ZBX_CONFIG "JavaGateway" + update_config_var $ZBX_CONFIG "JavaGatewayPort" + update_config_var $ZBX_CONFIG "StartJavaPollers" + fi + + update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}" + update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}" + update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}" + + : ${ZBX_ENABLE_SNMP_TRAPS:="false"} + if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1" + else + update_config_var $ZBX_CONFIG "SNMPTrapperFile" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" + fi + + update_config_var $ZBX_CONFIG "SocketDir" "/tmp/" + update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}" + + update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}" + + update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}" + update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}" + update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}" + + update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}" + update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}" + update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}" + update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}" + update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}" + + update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts" + + update_config_var $ZBX_CONFIG "FpingLocation" "${ZBX_FPINGLOCATION}" + update_config_var $ZBX_CONFIG "Fping6Location" '""' + + update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys" + update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}" + + update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/" + update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/" + update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" + update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/" + update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}" + + update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}" + update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}" + file_process_from_env $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}" "${ZBX_TLSCA}" + file_process_from_env $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}" "${ZBX_TLSCRL}" + + update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}" + update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}" + + file_process_from_env $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}" "${ZBX_TLSCERT}" + update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}" + update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}" + update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}" + update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}" + update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}" + update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}" + file_process_from_env $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}" "${ZBX_TLSKEY}" + + update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}" + file_process_from_env $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}" "${ZBX_TLSPSK}" + + if [ "$(id -u)" != '0' ]; then + update_config_var $ZBX_CONFIG "User" "$(whoami)" + else + update_config_var $ZBX_CONFIG "AllowRoot" "1" + fi + + update_config_var $ZBX_CONFIG "WebDriverURL" "${ZBX_WEBDRIVERURL}" + update_config_var $ZBX_CONFIG "StartBrowserPollers" "${ZBX_STARTBROWSERPOLLERS}" + + command -v openssl >/dev/null 2>&1 && openssl rehash -v "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" 1>/dev/null +} + +clear_zbx_env() { + [[ "${ZBX_CLEAR_ENV}" == "false" ]] && return + + for env_var in $(env | grep -E "^(ZBX|DB|POSTGRES)_"); do + unset "${env_var%%=*}" + done +} + +prepare_db() { + echo "** Preparing database" + + check_variables_postgresql + check_db_connect_postgresql + create_db_database_postgresql + create_db_schema_postgresql +} + +prepare_proxy() { + echo "** Preparing Zabbix proxy" + + prepare_db + update_zbx_config + clear_zbx_env +} + +################################################# + +if [ "${1#-}" != "$1" ]; then + set -- /usr/sbin/zabbix_proxy "$@" +fi + +if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then + prepare_proxy +fi + +if [ "$1" == "init_db_only" ]; then + prepare_db +else + + # Additional configuration every startup + if [ -d "${ZABBIX_USER_HOME_DIR}/dbscripts/startup" ]; then + for sql_script in "${ZABBIX_USER_HOME_DIR}/dbscripts/startup/*.sql"; do + [ -e "$sql_script" ] || continue + echo "** Processing additional '$sql_script' SQL script" + + exec_sql_file "$sql_script" + done + fi + + exec "$@" +fi + +################################################# diff --git a/Dockerfiles/proxy-pgsql/rhel/.dockerignore b/Dockerfiles/proxy-pgsql/rhel/.dockerignore new file mode 100644 index 0000000000..88a84e55aa --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/.dockerignore @@ -0,0 +1 @@ +build.sh diff --git a/Dockerfiles/proxy-pgsql/rhel/Dockerfile b/Dockerfiles/proxy-pgsql/rhel/Dockerfile new file mode 100644 index 0000000000..73a5690ac3 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/Dockerfile @@ -0,0 +1,168 @@ +# syntax=docker/dockerfile:1 +ARG OS_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi-minimal:9.6 +ARG MAJOR_VERSION=7.0 +ARG RELEASE=17 +ARG ZBX_VERSION=${MAJOR_VERSION}.17 +ARG BUILD_BASE_IMAGE=zabbix-build-pgsql:rhel-${ZBX_VERSION} + +FROM ${BUILD_BASE_IMAGE} AS builder + +FROM ${OS_BASE_IMAGE} + +ARG MAJOR_VERSION +ARG RELEASE +ARG ZBX_VERSION +ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git + +ENV TERM=xterm \ + ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \ + MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \ + NMAP_PRIVILEGED="" \ + ZABBIX_USER_HOME_DIR="/var/lib/zabbix" \ + ZABBIX_CONF_DIR="/etc/zabbix" \ + ZBX_FPINGLOCATION="/usr/sbin/fping" + +LABEL description="Zabbix proxy with PostgreSQL database support" \ + maintainer="alexey.pustovalov@zabbix.com" \ + name="zabbix/zabbix-proxy-pgsql-70" \ + release="${RELEASE}" \ + run="docker run --name zabbix-proxy --link postgresql:pgsql-server -p 10051:10051 -d registry.connect.redhat.com/zabbix/zabbix-proxy-pgsql-70:${ZBX_VERSION}" \ + summary="Zabbix proxy (PostgreSQL)" \ + url="https://www.zabbix.com/" \ + vendor="Zabbix SIA" \ + version="${MAJOR_VERSION}" \ + io.k8s.description="Zabbix proxy with PostgreSQL database support" \ + io.k8s.display-name="Zabbix proxy (PostgreSQL)" \ + io.openshift.expose-services="10051:10051" \ + io.openshift.tags="zabbix,zabbix-proxy,pgsql" \ + org.label-schema.build-date="${BUILD_DATE}" \ + org.label-schema.description="Zabbix proxy with PostgreSQL database support" \ + org.label-schema.docker.cmd="docker run --name zabbix-proxy --link postgresql:pgsql-server -p 10051:10051 -d registry.connect.redhat.com/zabbix/zabbix-proxy-pgsql-70:${ZBX_VERSION}" \ + org.label-schema.license="AGPL v3.0" \ + org.label-schema.name="zabbix-proxy-pgsql-rhel" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.url="https://zabbix.com/" \ + org.label-schema.usage="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" \ + org.label-schema.vcs-ref="${VCS_REF}" \ + org.label-schema.vcs-url="${ZBX_SOURCES}" \ + org.label-schema.vendor="Zabbix SIA" \ + org.label-schema.version="${ZBX_VERSION}" + +STOPSIGNAL SIGTERM + +COPY ["licenses", "/licenses"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy", "/usr/sbin/zabbix_proxy"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/general/bin/*", "/usr/bin/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/", "${ZABBIX_CONF_DIR}/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/database/postgresql/", "/usr/share/doc/zabbix-proxy-postgresql/"] + +RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ + --mount=type=tmpfs,target=/var/cache/yum/ \ +# --mount=type=bind,target=/run/secrets/,src=secrets/ \ + set -eux && \ + INSTALL_PKGS="bash \ + traceroute \ + nmap \ + krb5-workstation \ + shadow-utils \ + fping \ + iputils \ + libcurl-minimal \ + libevent \ + openldap \ + openssl \ + libssh \ + libxml2 \ + net-snmp-agent-libs \ + OpenIPMI-libs \ + pcre2 \ + postgresql \ + postgresql-private-libs \ + gzip \ + unixODBC \ + zlib" && \ + curl --tlsv1.2 -sSf -L https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -o /tmp/epel-release-latest-9.noarch.rpm && \ + rpm -ivh /tmp/epel-release-latest-9.noarch.rpm && \ + rm -rf /tmp/epel-release-latest-9.noarch.rpm && \ + ARCH_SUFFIX="$(arch)"; \ + microdnf -y module enable \ + --disablerepo "*" \ + --enablerepo "rhel-9-for-$ARCH_SUFFIX-appstream-rpms" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + postgresql:16 && \ + microdnf -y install \ + --disablerepo "*" \ + --enablerepo "ubi-9-baseos-rpms" \ + --enablerepo "ubi-9-appstream-rpms" \ + --enablerepo "rhel-9-for-$ARCH_SUFFIX-baseos-rpms" \ + --enablerepo "rhel-9-for-$ARCH_SUFFIX-appstream-rpms" \ + --enablerepo "codeready-builder-for-rhel-9-$ARCH_SUFFIX-rpms" \ + --enablerepo "epel" \ + --setopt=install_weak_deps=0 \ + --setopt=keepcache=0 \ + --best \ + --setopt=tsflags=nodocs \ + ${INSTALL_PKGS} && \ + microdnf -y update \ + --disableplugin=subscription-manager \ + --disablerepo "*" \ + --enablerepo "ubi-9-baseos-rpms" \ + --setopt=install_weak_deps=0 \ + --best \ + --setopt=tsflags=nodocs \ + tzdata && \ + microdnf -y reinstall \ + --disableplugin=subscription-manager \ + --disablerepo "*" \ + --enablerepo "ubi-9-baseos-rpms" \ + --setopt=install_weak_deps=0 \ + --best \ + --setopt=tsflags=nodocs \ + tzdata && \ + groupadd \ + --system \ + --gid 1995 \ + zabbix && \ + useradd \ + --system \ + --comment "Zabbix monitoring system" \ + -g zabbix \ + --uid 1997 \ + --shell /sbin/nologin \ + --home-dir ${ZABBIX_USER_HOME_DIR} \ + zabbix && \ + chgrp zabbix /usr/bin/nmap && \ + setcap cap_net_raw+eip /usr/bin/nmap && \ + mkdir -p ${ZABBIX_CONF_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/mibs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/snmptraps && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssh_keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/certs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/ssl_ca && \ + mkdir -p /usr/lib/zabbix/externalscripts && \ + mkdir -p /usr/share/doc/zabbix-proxy-postgresql && \ + chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + /usr/sbin/zabbix_proxy -V + +EXPOSE 10051/TCP + +WORKDIR ${ZABBIX_USER_HOME_DIR} + +VOLUME ["${ZABBIX_USER_HOME_DIR}/snmptraps"] + +COPY ["docker-entrypoint.sh", "/usr/bin/"] + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +USER 1997 + +CMD ["/usr/sbin/zabbix_proxy", "--foreground", "-c", "/etc/zabbix/zabbix_proxy.conf"] diff --git a/Dockerfiles/proxy-pgsql/rhel/README.html b/Dockerfiles/proxy-pgsql/rhel/README.html new file mode 100644 index 0000000000..e73f7726af --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/README.html @@ -0,0 +1,195 @@ +

logo

+

What is Zabbix?

+

Zabbix is an enterprise-class open source distributed monitoring solution.

+

Zabbix is software that monitors numerous parameters of a network and the health and integrity of servers. Zabbix uses a flexible notification mechanism that allows users to configure e-mail based alerts for virtually any event. This allows a fast reaction to server problems. Zabbix offers excellent reporting and data visualisation features based on the stored data. This makes Zabbix ideal for capacity planning.

+

For more information and related downloads for Zabbix components, please visit https://hub.docker.com/u/zabbix/ and https://zabbix.com

+

What is Zabbix proxy?

+

Zabbix proxy is a process that may collect monitoring data from one or more monitored devices and send the information to the Zabbix server, essentially working on behalf of the server. All collected data is buffered locally and then transferred to the Zabbix server the proxy belongs to.

+

Zabbix proxy images

+

These are the only official Zabbix proxy Podman images. Images are updated when new releases are published. The image with latest tag is based on Alpine Linux.

+

The image uses PostgreSQL database to store collected data before sending it to Zabbix server. It uses the next procedure to start:

+
    +
  • Checking database availability
  • +
  • Checking of having POSTGRES_DB database. Creating POSTGRES_DB database name if it does not exist
  • +
  • Checking of having dbversion table. Creating Zabbix proxy database schema if no dbversion table
  • +
+

How to use this image

+

Start zabbix-proxy-pgsql

+

Start a Zabbix proxy container as follows:

+
podman run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -e POSTGRES_USER="some-user" -e POSTGRES_PASSWORD="some-password" -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag
+

Where some-zabbix-proxy-pgsql is the name you want to assign to your container, some-postgres-server is IP or DNS name of PostgreSQL server, some-user is user to connect to Zabbix database on PostgreSQL server, some-password is the password to connect to PostgreSQL server, some-hostname is the hostname, it is Hostname parameter in Zabbix proxy configuration file, some-zabbix-server is IP or DNS name of Zabbix server and tag is the tag specifying the version you want.

+
+

[!NOTE] +Zabbix server has possibility to execute fping utility to perform ICMP checks. When containers are running in rootless mode or with specific restrictions environment, you may face errors related to fping: +fping: Operation not permitted +or +lost all packets to all resources +in this case add --cap-add=net_raw to docker run or podman run commands. +Additionally fping executing in non-root environments can require sysctl modification: +net.ipv4.ping_group_range=0 1995 +where 1995 is zabbix GID.

+
+

Connects from Zabbix server (Passive proxy)

+

This image exposes the standard Zabbix proxy port (10051) and can operate as Passive proxy in case ZBX_PROXYMODE = 1. Start Zabbix server container like this in order to link it to the Zabbix proxy container:

+
$ podman run --name some-zabbix-server --link some-zabbix-proxy-pgsql:zabbix-proxy-pgsql --init -d zabbix/zabbix-server:latest
+
+

Connect to Zabbix server (Active proxy)

+

This image can operate as Active proxy (default mode). Start your application container like this in order to link Zabbix proxy to Zabbix server containters:

+
$ podman run --name some-zabbix-proxy-pgsql --link some-zabbix-server:zabbix-server --init -d zabbix/zabbix-proxy-pgsql:latest
+
+

Container shell access and viewing Zabbix proxy logs

+

The podman exec command allows you to run commands inside a Podman container. The following command line will give you a bash shell inside your zabbix-proxy-pgsql container:

+
$ podman exec -ti some-zabbix-proxy-pgsql /bin/bash
+
+

The Zabbix proxy log is available through Podman's container log:

+
$ podman logs some-zabbix-proxy-pgsql
+
+

Environment Variables

+

When you start the zabbix-proxy-pgsql image, you can adjust the configuration of the Zabbix proxy by passing one or more environment variables on the podman run command line.

+

ZBX_PROXYMODE

+

The variable allows to switch Zabbix proxy mode. Bu default, value is 0 - active proxy. Allowed values are 0 - active proxy and 1 - passive proxy.

+

ZBX_HOSTNAME

+

This variable is unique, case sensitive hostname. By default, value is zabbix-proxy-pgsql of the container. It is Hostname parameter in zabbix_proxy.conf.

+

ZBX_SERVER_HOST

+

This variable is IP or DNS name of Zabbix server or Zabbix proxy. By default, value is zabbix-server. It is Server parameter in zabbix_proxy.conf. It is allowed to specify Zabbix server or Zabbix proxy port number using ZBX_SERVER_PORT variable. It make sense in case of non-default port for active checks.

+

ZBX_SERVER_PORT

+

This variable is port Zabbix server listening on. By default, value is 10051.

+

Note: This parameter is no longer used in version 6.0 and above. Instead, add a colon : followed by the port number to the end of ZBX_SERVER_HOST.

+

DB_SERVER_HOST

+

This variable is IP or DNS name of PostgreSQL server. By default, value is 'postgres-server'

+

DB_SERVER_PORT

+

This variable is port of PostgreSQL server. By default, value is '5432'.

+

POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_USER_FILE, POSTGRES_PASSWORD_FILE

+

These variables are used by Zabbix proxy to connect to Zabbix database. With the _FILE variables you can instead provide the path to a file which contains the user / the password instead. Without Docker Swarm or Kubernetes you also have to map the files. Those are exclusive so you can just provide one type - either POSTGRES_USER or POSTGRES_USER_FILE!

+
podman run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -v ./.POSTGRES_USER:/run/secrets/POSTGRES_USER -e POSTGRES_USER_FILE=/run/secrets/POSTGRES_USER -v ./.POSTGRES_PASSWORD:/run/secrets/POSTGRES_PASSWORD -e POSTGRES_PASSWORD_FILE=/var/run/secrets/POSTGRES_PASSWORD -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag
+
+

With Docker Swarm or Kubernetes this works with secrets. That way it is replicated in your cluster!

+
printf "zabbix" | podman secret create POSTGRES_USER -
+printf "zabbix" | podman secret create POSTGRES_PASSWORD -
+podman run --name some-zabbix-proxy-pgsql -e DB_SERVER_HOST="some-postgres-server" -e POSTGRES_USER_FILE=/run/secrets/POSTGRES_USER -e POSTGRES_PASSWORD_FILE=/run/secrets/POSTGRES_PASSWORD -e ZBX_SERVER_HOST="some-zabbix-server" -e ZBX_HOSTNAME=some-hostname -e ZBX_SERVER_HOST=some-zabbix-server --init -d zabbix/zabbix-proxy-pgsql:tag
+
+

By default, values for POSTGRES_USER and POSTGRES_PASSWORD are zabbix, zabbix.

+

POSTGRES_DB

+

The variable is Zabbix database name. By default, value is zabbix_proxy.

+

ZBX_LOADMODULE

+

The variable is list of comma separated loadable Zabbix modules. It works with volume /var/lib/zabbix/modules. The syntax of the variable is dummy1.so,dummy2.so.

+

ZBX_DEBUGLEVEL

+

The variable is used to specify debug level. By default, value is 3. It is DebugLevel parameter in zabbix_server.conf. Allowed values are listed below:

+
    +
  • 0 - basic information about starting and stopping of Zabbix processes;
  • +
  • 1 - critical information
  • +
  • 2 - error information
  • +
  • 3 - warnings
  • +
  • 4 - for debugging (produces lots of information)
  • +
  • 5 - extended debugging (produces even more information)
  • +
+

ZBX_TIMEOUT

+

The variable is used to specify timeout for processing checks. By default, value is 4.

+

ZBX_JAVAGATEWAY_ENABLE

+

The variable enable communication with Zabbix Java Gateway to collect Java related checks. By default, value is false.

+

Other variables

+

Additionally the image allows to specify many other environment variables listed below:

+
ZBX_ALLOWUNSUPPORTEDDBVERSIONS=0 # Available since 6.0.0
+ZBX_DBTLSCONNECT= # Available since 5.0.0
+ZBX_DBTLSCAFILE= # Available since 5.0.0
+ZBX_DBTLSCERTFILE= # Available since 5.0.0
+ZBX_DBTLSKEYFILE= # Available since 5.0.0
+ZBX_DBTLSCIPHER= # Available since 5.0.0
+ZBX_DBTLSCIPHER13= # Available since 5.0.0
+ZBX_VAULTDBPATH= # Available since 5.2.0
+ZBX_VAULTPREFIX= # Available since 7.0.0
+ZBX_VAULTURL=https://127.0.0.1:8200 # Available since 5.2.0
+VAULT_TOKEN= # Available since 5.2.0
+ZBX_ENABLEREMOTECOMMANDS=0 # Available since 3.4.0
+ZBX_LOGREMOTECOMMANDS=0 # Available since 3.4.0
+ZBX_HOSTNAMEITEM=system.hostname
+ZBX_SOURCEIP=
+ZBX_PROXYLOCALBUFFER=0
+ZBX_PROXYOFFLINEBUFFER=1
+ZBX_PROXYHEARTBEATFREQUENCY=60 # Deprecated since 6.4.0
+ZBX_CONFIGFREQUENCY=3600 # Deprecated since 6.4.0
+ZBX_PROXYCONFIGFREQUENCY=10 # Available since 6.4.0
+ZBX_DATASENDERFREQUENCY=1
+ZBX_STARTPOLLERS=5
+ZBX_STARTPREPROCESSORS=3 # Available since 4.2.0
+ZBX_STARTIPMIPOLLERS=0
+ZBX_STARTPOLLERSUNREACHABLE=1
+ZBX_STARTTRAPPERS=5
+ZBX_STARTPINGERS=1
+ZBX_STARTDISCOVERERS=1
+ZBX_STARTHISTORYPOLLERS=1 # Available since 5.4.0 till 6.0.0
+ZBX_STARTHTTPPOLLERS=1
+ZBX_STARTODBCPOLLERS=1 # Available since 6.0.0
+ZBX_JAVAGATEWAY=zabbix-java-gateway
+ZBX_JAVAGATEWAYPORT=10052
+ZBX_STARTJAVAPOLLERS=0
+ZBX_STATSALLOWEDIP= # Available since 4.0.5
+ZBX_STARTVMWARECOLLECTORS=0
+ZBX_VMWAREFREQUENCY=60
+ZBX_VMWAREPERFFREQUENCY=60
+ZBX_VMWARECACHESIZE=8M
+ZBX_VMWARETIMEOUT=10
+ZBX_ENABLE_SNMP_TRAPS=false
+ZBX_LISTENIP=
+ZBX_LISTENPORT=10051
+ZBX_LISTENBACKLOG=
+ZBX_HOUSEKEEPINGFREQUENCY=1
+ZBX_CACHESIZE=8M
+ZBX_STARTDBSYNCERS=4
+ZBX_HISTORYCACHESIZE=16M
+ZBX_HISTORYINDEXCACHESIZE=4M
+ZBX_TRAPPERTIMEOUT=300
+ZBX_UNREACHABLEPERIOD=45
+ZBX_UNAVAILABLEDELAY=60
+ZBX_UNREACHABLEDELAY=15
+ZBX_LOGSLOWQUERIES=3000
+ZBX_TLSCONNECT=unencrypted
+ZBX_TLSACCEPT=unencrypted
+ZBX_TLSCAFILE=
+ZBX_TLSCRLFILE=
+ZBX_TLSSERVERCERTISSUER=
+ZBX_TLSSERVERCERTSUBJECT=
+ZBX_TLSCERTFILE=
+ZBX_TLSKEYFILE=
+ZBX_TLSPSKIDENTITY=
+ZBX_TLSPSKFILE=
+ZBX_TLSCIPHERALL= # Available since 4.4.7
+ZBX_TLSCIPHERALL13= # Available since 4.4.7
+ZBX_TLSCIPHERCERT= # Available since 4.4.7
+ZBX_TLSCIPHERCERT13= # Available since 4.4.7
+ZBX_TLSCIPHERPSK= # Available since 4.4.7
+ZBX_TLSCIPHERPSK13= # Available since 4.4.7
+ZBX_WEBDRIVERURL= # Available since 7.0.0
+ZBX_STARTBROWSERPOLLERS= # Available since 7.0.0
+

Default values of these variables are specified after equal sign.

+

The allowed variables are identical of parameters in official zabbix_proxy.conf. For example, ZBX_LOGSLOWQUERIES = LogSlowQueries.

+

Please use official documentation for zabbix_proxy.conf to get more information about the variables.

+

Allowed volumes for the Zabbix proxy container

+

/usr/lib/zabbix/externalscripts

+

The volume is used by External checks (type of items). It is ExternalScripts parameter in zabbix_proxy.conf.

+

/var/lib/zabbix/modules

+

The volume allows load additional modules and extend Zabbix proxy using LoadModule feature.

+

/var/lib/zabbix/enc

+

The volume is used to store TLS related files. These file names are specified using ZBX_TLSCAFILE, ZBX_TLSCRLFILE, ZBX_TLSKEY_FILE and ZBX_TLSPSKFILE variables.

+

/var/lib/zabbix/ssh_keys

+

The volume is used as location of public and private keys for SSH checks and actions. It is SSHKeyLocation parameter in zabbix_proxy.conf.

+

/var/lib/zabbix/ssl/certs

+

The volume is used as location of of SSL client certificate files for client authentication. It is SSLCertLocation parameter in zabbix_proxy.conf.

+

/var/lib/zabbix/ssl/keys

+

The volume is used as location of SSL private key files for client authentication. It is SSLKeyLocation parameter in zabbix_proxy.conf.

+

/var/lib/zabbix/ssl/ssl_ca

+

The volume is used as location of certificate authority (CA) files for SSL server certificate verification. It is SSLCALocation parameter in zabbix_proxy.conf.

+

/var/lib/zabbix/snmptraps

+

The volume is used as location of snmptraps.log file. It could be shared by zabbix-snmptraps container and inherited using volumes_from Podman option while creating new instance of Zabbix proxy. +SNMP traps processing feature could be enabled using shared volume and switched ZBX_ENABLE_SNMP_TRAPS environment variable to true.

+

/var/lib/zabbix/mibs

+

The volume allows to add new MIB files. It does not support subdirectories, all MIBs must be placed to /var/lib/zabbix/mibs.

+

User Feedback

+

Documentation

+

Documentation for this image is stored in the proxy-pgsql/ directory of the zabbix/zabbix-docker GitHub repo. Be sure to familiarize yourself with the repository's README.md file before attempting a pull request.

+

Issues

+

If you have any problems with or questions about this image, please contact us through a GitHub issue.

+

Known issues

+

Contributing

+

You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

+

Before you start to code, we recommend discussing your plans through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.

diff --git a/Dockerfiles/proxy-pgsql/rhel/build.sh b/Dockerfiles/proxy-pgsql/rhel/build.sh new file mode 120000 index 0000000000..46b2031346 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/build.sh @@ -0,0 +1 @@ +../../../build.sh \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh new file mode 100755 index 0000000000..d5aa604c3b --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh @@ -0,0 +1,606 @@ +#!/bin/bash + +set -o pipefail + +set +e + +# Script trace mode +if [ "${DEBUG_MODE,,}" == "true" ]; then + set -o xtrace +fi + +# Default Zabbix server host +: ${ZBX_SERVER_HOST:="zabbix-server"} + +# Default directories +# Internal directory for TLS related files, used when TLS*File specified as plain text values +ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" + +: ${DB_CHARACTER_SET:="utf8mb4"} +: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} + +# usage: file_env VAR [DEFAULT] +# as example: file_env 'MYSQL_PASSWORD' 'zabbix' +# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) +# unsets the VAR_FILE afterwards and just leaving VAR +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local defaultValue="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo "**** Both variables $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$defaultValue" + + if [ "${!var:-}" ]; then + val="${!var}" + echo "** Using ${var} variable from ENV" + elif [ "${!fileVar:-}" ]; then + if [ ! -f "${!fileVar}" ]; then + echo "**** Secret file \"${!fileVar}\" is not found" + exit 1 + fi + val="$(< "${!fileVar}")" + echo "** Using ${var} variable from secret file" + fi + export "$var"="$val" + unset "$fileVar" +} + +escape_spec_char() { + local var_value=$1 + + var_value="${var_value//\\/\\\\}" + var_value="${var_value//[$'\n']/}" + var_value="${var_value//\//\\/}" + var_value="${var_value//./\\.}" + var_value="${var_value//\*/\\*}" + var_value="${var_value//^/\\^}" + var_value="${var_value//\$/\\\$}" + var_value="${var_value//\&/\\\&}" + var_value="${var_value//\[/\\[}" + var_value="${var_value//\]/\\]}" + + echo "$var_value" +} + +update_config_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + local is_multiple=$4 + + local masklist=("DBPassword TLSPSKIdentity") + + if [ ! -f "$config_path" ]; then + echo "**** Configuration file '$config_path' does not exist" + return + fi + + if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then + echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..." + else + echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." + fi + + # Remove configuration parameter definition in case of unset or empty parameter value + if [ -z "$var_value" ]; then + sed -i -e "/^$var_name=/d" "$config_path" + echo "removed" + return + fi + + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi + echo "undefined" + return + fi + + # Use full path to a file for TLS related configuration parameters + if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then + var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value + fi + + # Escaping characters in parameter value and name + var_value=$(escape_spec_char "$var_value") + var_name=$(escape_spec_char "$var_name") + + if [ "$(grep -E "^$var_name=$var_value$" $config_path)" ]; then + echo "exists" + elif [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then + sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path" + echo "updated" + elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then + sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path" + echo "added first occurrence" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path" + echo "added" + fi + +} + +update_config_multiple_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + + var_value="${var_value%\"}" + var_value="${var_value#\"}" + + local IFS=, + local OPT_LIST=($var_value) + + for value in "${OPT_LIST[@]}"; do + update_config_var $config_path $var_name $value true + done +} + +file_process_from_env() { + local config_path=$1 + local var_name=$2 + local file_name=$3 + local var_value=$4 + + if [ ! -z "$var_value" ]; then + echo -n "$var_value" > "${ZABBIX_INTERNAL_ENC_DIR}/$var_name" + file_name="${ZABBIX_INTERNAL_ENC_DIR}/${var_name}" + fi + update_config_var $config_path "$var_name" "$file_name" +} + +# Check prerequisites for PostgreSQL database +check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + + file_env POSTGRES_USER + file_env POSTGRES_PASSWORD + + DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} + DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} + + DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} + DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"} + + : ${DB_SERVER_SCHEMA:="public"} + + DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} + + : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi +} + +check_db_connect_postgresql() { + echo "********************" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi + echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" + echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" + if [ "${DEBUG_MODE,,}" == "true" ]; then + echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}" + echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}" + fi + echo "********************" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + WAIT_TIMEOUT=5 + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + while true : + do + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + + echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." + sleep $WAIT_TIMEOUT + done + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +psql_query() { + query=$1 + db=$2 + + local result="" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ + --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + + echo $result +} + +exec_sql_file() { + sql_script=$1 + + local command="cat" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + if [ "${sql_script: -3}" == ".gz" ]; then + command="zcat" + fi + + $command $sql_script | psql --quiet \ + $psql_connect_args \ + --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +create_db_database_postgresql() { + DB_EXISTS=$(psql_query "SELECT 1 AS result FROM pg_database WHERE datname='${DB_SERVER_DBNAME}'" "${DB_SERVER_DBNAME}") + + if [ -z ${DB_EXISTS} ]; then + echo "** Database '${DB_SERVER_DBNAME}' does not exist. Creating..." + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ + --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + else + echo "** Database '${DB_SERVER_DBNAME}' already exists. Please be careful with database owner!" + fi + + psql_query "CREATE SCHEMA IF NOT EXISTS ${DB_SERVER_SCHEMA}" "${DB_SERVER_DBNAME}" 1>/dev/null +} + +create_db_schema_postgresql() { + DBVERSION_TABLE_EXISTS=$(psql_query "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = + c.relnamespace WHERE n.nspname = '$DB_SERVER_SCHEMA' AND c.relname = 'dbversion'" "${DB_SERVER_DBNAME}") + + if [ -n "${DBVERSION_TABLE_EXISTS}" ]; then + echo "** Table '${DB_SERVER_DBNAME}.dbversion' already exists." + ZBX_DB_VERSION=$(psql_query "SELECT mandatory FROM ${DB_SERVER_SCHEMA}.dbversion" "${DB_SERVER_DBNAME}") + fi + + if [ -z "${ZBX_DB_VERSION}" ]; then + echo "** Creating '${DB_SERVER_DBNAME}' schema in PostgreSQL" + + exec_sql_file "/usr/share/doc/zabbix-proxy-postgresql/create.sql.gz" + fi +} + +update_zbx_config() { + echo "** Preparing Zabbix proxy configuration file" + + ZBX_CONFIG=${ZABBIX_CONF_DIR}/zabbix_proxy.conf + + update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}" + update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}" + if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then + update_config_var $ZBX_CONFIG "Hostname" "" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + else + update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-postgresql"}" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + fi + + update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}" + update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}" + update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}" + + update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}" + update_config_var $ZBX_CONFIG "LogType" "console" + update_config_var $ZBX_CONFIG "LogFile" + update_config_var $ZBX_CONFIG "LogFileSize" + update_config_var $ZBX_CONFIG "PidFile" + + update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}" + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + update_config_var $ZBX_CONFIG "DBTLSConnect" "${ZBX_DBTLSCONNECT}" + update_config_var $ZBX_CONFIG "DBTLSCAFile" "${ZBX_DBTLSCAFILE}" + update_config_var $ZBX_CONFIG "DBTLSCertFile" "${ZBX_DBTLSCERTFILE}" + update_config_var $ZBX_CONFIG "DBTLSKeyFile" "${ZBX_DBTLSKEYFILE}" + update_config_var $ZBX_CONFIG "DBTLSCipher" "${ZBX_DBTLSCIPHER}" + update_config_var $ZBX_CONFIG "DBTLSCipher13" "${ZBX_DBTLSCIPHER13}" + fi + + update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}" + update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}" + + if [ ! -n "${DB_SERVER_SOCKET}" ]; then + update_config_var $ZBX_CONFIG "DBHost" "${DB_SERVER_HOST}" + update_config_var $ZBX_CONFIG "DBPort" "${DB_SERVER_PORT}" + else + update_config_var $ZBX_CONFIG "DBHost" + update_config_var $ZBX_CONFIG "DBPort" + fi + update_config_var $ZBX_CONFIG "DBSocket" "${DB_SERVER_SOCKET}" + update_config_var $ZBX_CONFIG "DBName" "${DB_SERVER_DBNAME}" + update_config_var $ZBX_CONFIG "DBSchema" "${DB_SERVER_SCHEMA}" + + if [ -n "${ZBX_VAULTDBPATH}" ] && [ -n "${ZBX_VAULTURL}" ]; then + update_config_var $ZBX_CONFIG "Vault" "${ZBX_VAULT}" + update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" "${ZBX_VAULTTLSCERTFILE}" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" "${ZBX_VAULTTLSKEYFILE}" + update_config_var $ZBX_CONFIG "VaultPrefix" "${ZBX_VAULTPREFIX}" + update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}" + update_config_var $ZBX_CONFIG "DBUser" + update_config_var $ZBX_CONFIG "DBPassword" + else + update_config_var $ZBX_CONFIG "Vault" + update_config_var $ZBX_CONFIG "VaultDBPath" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" + update_config_var $ZBX_CONFIG "VaultPrefix" + update_config_var $ZBX_CONFIG "VaultURL" + update_config_var $ZBX_CONFIG "DBUser" "${DB_SERVER_ZBX_USER}" + update_config_var $ZBX_CONFIG "DBPassword" "${DB_SERVER_ZBX_PASS}" + fi + + update_config_var $ZBX_CONFIG "AllowUnsupportedDBVersions" "${ZBX_ALLOWUNSUPPORTEDDBVERSIONS}" + update_config_var $ZBX_CONFIG "MaxConcurrentChecksPerPoller" "${ZBX_MAXCONCURRENTCHECKSPERPOLLER}" + + update_config_var $ZBX_CONFIG "ProxyBufferMode" "${ZBX_PROXYBUFFERMODE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferAge" "${ZBX_PROXYMEMORYBUFFERAGE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferSize" "${ZBX_PROXYMEMORYBUFFERSIZE}" + + update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}" + update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}" + update_config_var $ZBX_CONFIG "ProxyConfigFrequency" "${ZBX_PROXYCONFIGFREQUENCY}" + update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}" + + update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}" + update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}" + + update_config_var $ZBX_CONFIG "StartAgentPollers" "${ZBX_STARTAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}" + update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_STARTIPMIPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}" + update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}" + update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}" + update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}" + update_config_var $ZBX_CONFIG "StartHTTPAgentPollers" "${ZBX_STARTHTTPAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}" + update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}" + update_config_var $ZBX_CONFIG "StartSNMPPollers" "${ZBX_STARTSNMPPOLLERS}" + + : ${ZBX_JAVAGATEWAY_ENABLE:="false"} + if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}" + update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}" + update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}" + else + update_config_var $ZBX_CONFIG "JavaGateway" + update_config_var $ZBX_CONFIG "JavaGatewayPort" + update_config_var $ZBX_CONFIG "StartJavaPollers" + fi + + update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}" + update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}" + update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}" + + : ${ZBX_ENABLE_SNMP_TRAPS:="false"} + if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1" + else + update_config_var $ZBX_CONFIG "SNMPTrapperFile" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" + fi + + update_config_var $ZBX_CONFIG "SocketDir" "/tmp/" + update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}" + + update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}" + + update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}" + update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}" + update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}" + + update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}" + update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}" + update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}" + update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}" + update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}" + + update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts" + + update_config_var $ZBX_CONFIG "FpingLocation" "${ZBX_FPINGLOCATION}" + update_config_var $ZBX_CONFIG "Fping6Location" '""' + + update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys" + update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}" + + update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/" + update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/" + update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" + update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/" + update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}" + + update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}" + update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}" + file_process_from_env $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}" "${ZBX_TLSCA}" + file_process_from_env $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}" "${ZBX_TLSCRL}" + + update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}" + update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}" + + file_process_from_env $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}" "${ZBX_TLSCERT}" + update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}" + update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}" + update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}" + update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}" + update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}" + update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}" + file_process_from_env $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}" "${ZBX_TLSKEY}" + + update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}" + file_process_from_env $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}" "${ZBX_TLSPSK}" + + if [ "$(id -u)" != '0' ]; then + update_config_var $ZBX_CONFIG "User" "$(whoami)" + else + update_config_var $ZBX_CONFIG "AllowRoot" "1" + fi + + update_config_var $ZBX_CONFIG "WebDriverURL" "${ZBX_WEBDRIVERURL}" + update_config_var $ZBX_CONFIG "StartBrowserPollers" "${ZBX_STARTBROWSERPOLLERS}" + + command -v openssl >/dev/null 2>&1 && openssl rehash -v "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" 1>/dev/null +} + +clear_zbx_env() { + [[ "${ZBX_CLEAR_ENV}" == "false" ]] && return + + for env_var in $(env | grep -E "^(ZBX|DB|POSTGRES)_"); do + unset "${env_var%%=*}" + done +} + +prepare_db() { + echo "** Preparing database" + + check_variables_postgresql + check_db_connect_postgresql + create_db_database_postgresql + create_db_schema_postgresql +} + +prepare_proxy() { + echo "** Preparing Zabbix proxy" + + prepare_db + update_zbx_config + clear_zbx_env +} + +################################################# + +if [ "${1#-}" != "$1" ]; then + set -- /usr/sbin/zabbix_proxy "$@" +fi + +if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then + prepare_proxy +fi + +if [ "$1" == "init_db_only" ]; then + prepare_db +else + + # Additional configuration every startup + if [ -d "${ZABBIX_USER_HOME_DIR}/dbscripts/startup" ]; then + for sql_script in "${ZABBIX_USER_HOME_DIR}/dbscripts/startup/*.sql"; do + [ -e "$sql_script" ] || continue + echo "** Processing additional '$sql_script' SQL script" + + exec_sql_file "$sql_script" + done + fi + + exec "$@" +fi + +################################################# diff --git a/Dockerfiles/proxy-pgsql/rhel/licenses/AGPL-v3.0.txt b/Dockerfiles/proxy-pgsql/rhel/licenses/AGPL-v3.0.txt new file mode 100644 index 0000000000..be3f7b28e5 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/rhel/licenses/AGPL-v3.0.txt @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/Dockerfiles/proxy-pgsql/ubuntu/.dockerignore b/Dockerfiles/proxy-pgsql/ubuntu/.dockerignore new file mode 100644 index 0000000000..88a84e55aa --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ubuntu/.dockerignore @@ -0,0 +1 @@ +build.sh diff --git a/Dockerfiles/proxy-pgsql/ubuntu/Dockerfile b/Dockerfiles/proxy-pgsql/ubuntu/Dockerfile new file mode 100644 index 0000000000..4b88912e64 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ubuntu/Dockerfile @@ -0,0 +1,137 @@ +# syntax=docker/dockerfile:1 +ARG OS_BASE_IMAGE=ubuntu:noble +ARG MAJOR_VERSION=7.0 +ARG ZBX_VERSION=${MAJOR_VERSION}.17 +ARG BUILD_BASE_IMAGE=zabbix-build-pgsql:ubuntu-${ZBX_VERSION} + +FROM ${BUILD_BASE_IMAGE} AS builder + +FROM ${OS_BASE_IMAGE} + +ARG MAJOR_VERSION +ARG ZBX_VERSION +ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git + +ENV TERM=xterm \ + ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \ + MIBDIRS=/var/lib/mibs/ietf:/var/lib/mibs/iana:/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \ + NMAP_PRIVILEGED="" \ + ZABBIX_USER_HOME_DIR="/var/lib/zabbix" \ + ZABBIX_CONF_DIR="/etc/zabbix" \ + ZBX_FPINGLOCATION="/usr/bin/fping" + +LABEL org.opencontainers.image.authors="Alexey Pustovalov " \ + org.opencontainers.image.description="Zabbix proxy with PostgreSQL database support" \ + org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" \ + org.opencontainers.image.licenses="AGPL v3.0" \ + org.opencontainers.image.source="${ZBX_SOURCES}" \ + org.opencontainers.image.title="Zabbix proxy (PostgreSQL)" \ + org.opencontainers.image.url="https://zabbix.com/" \ + org.opencontainers.image.vendor="Zabbix SIA" \ + org.opencontainers.image.version="${ZBX_VERSION}" + +STOPSIGNAL SIGTERM + +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy", "/usr/sbin/zabbix_proxy"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/general/bin/*", "/usr/bin/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/", "${ZABBIX_CONF_DIR}/"] +COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}-output/proxy/database/postgresql/", "/usr/share/doc/zabbix-proxy-postgresql/"] + +RUN --mount=type=cache,target=/var/cache/apt/,sharing=locked \ + --mount=type=cache,target=/var/lib/apt/,sharing=locked \ + set -eux && \ + echo "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d && \ + INSTALL_PKGS="bash \ + tzdata \ + traceroute \ + nmap \ + krb5-user \ + iputils-ping \ + ca-certificates \ + fping \ + openssl \ + libcurl4t64 \ + libevent-2.1 \ + libevent-pthreads-2.1 \ + libevent-extra-2.1 \ + libopenipmi0t64 \ + libpcre2-8-0 \ + libpq5 \ + libsnmp40t64 \ + libssh-4 \ + libssl3t64 \ + libxml2 \ + postgresql-client-17 \ + snmp-mibs-downloader \ + gzip \ + unixodbc \ + zlib1g" && \ + apt-get -y update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y \ + --no-install-recommends install \ + gpg \ + dirmngr \ + gpg-agent && \ + DISTRIB_CODENAME=$(/bin/bash -c 'source /etc/lsb-release && echo $DISTRIB_CODENAME') && \ + echo "deb http://apt.postgresql.org/pub/repos/apt $DISTRIB_CODENAME-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8' && \ + export GNUPGHOME="$(mktemp -d)" && \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" && \ + gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/postgresql.gpg && \ + gpgconf --kill all && \ + rm -rf "$GNUPGHOME" && \ + apt-get -y update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y \ + --no-install-recommends install \ + ${INSTALL_PKGS} && \ + DEBIAN_FRONTEND=noninteractive apt-get -y \ + purge \ + gpg \ + dirmngr \ + gpg-agent && \ + groupadd \ + --system \ + --gid 1995 \ + zabbix && \ + useradd \ + --system \ + --comment "Zabbix monitoring system" \ + -g zabbix \ + --uid 1997 \ + --shell /sbin/nologin \ + --home-dir ${ZABBIX_USER_HOME_DIR} \ + zabbix && \ + chgrp zabbix /usr/bin/nmap && \ + setcap cap_net_raw+eip /usr/bin/nmap && \ + mkdir -p ${ZABBIX_CONF_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR} && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/mibs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/snmptraps && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssh_keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/certs && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/keys && \ + mkdir -p ${ZABBIX_USER_HOME_DIR}/ssl/ssl_ca && \ + mkdir -p /usr/lib/zabbix/externalscripts && \ + mkdir -p /usr/share/doc/zabbix-proxy-postgresql && \ + chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chgrp -R 0 ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + chmod -R g=u ${ZABBIX_CONF_DIR}/ ${ZABBIX_USER_HOME_DIR}/ && \ + /usr/sbin/zabbix_proxy -V + +EXPOSE 10051/TCP + +WORKDIR ${ZABBIX_USER_HOME_DIR} + +VOLUME ["${ZABBIX_USER_HOME_DIR}/snmptraps"] + +COPY ["docker-entrypoint.sh", "/usr/bin/"] + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +USER 1997 + +CMD ["/usr/sbin/zabbix_proxy", "--foreground", "-c", "/etc/zabbix/zabbix_proxy.conf"] diff --git a/Dockerfiles/proxy-pgsql/ubuntu/README.md b/Dockerfiles/proxy-pgsql/ubuntu/README.md new file mode 120000 index 0000000000..32d46ee883 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ubuntu/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/ubuntu/build.sh b/Dockerfiles/proxy-pgsql/ubuntu/build.sh new file mode 120000 index 0000000000..46b2031346 --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ubuntu/build.sh @@ -0,0 +1 @@ +../../../build.sh \ No newline at end of file diff --git a/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh new file mode 100755 index 0000000000..d5aa604c3b --- /dev/null +++ b/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh @@ -0,0 +1,606 @@ +#!/bin/bash + +set -o pipefail + +set +e + +# Script trace mode +if [ "${DEBUG_MODE,,}" == "true" ]; then + set -o xtrace +fi + +# Default Zabbix server host +: ${ZBX_SERVER_HOST:="zabbix-server"} + +# Default directories +# Internal directory for TLS related files, used when TLS*File specified as plain text values +ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" + +: ${DB_CHARACTER_SET:="utf8mb4"} +: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} + +# usage: file_env VAR [DEFAULT] +# as example: file_env 'MYSQL_PASSWORD' 'zabbix' +# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) +# unsets the VAR_FILE afterwards and just leaving VAR +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local defaultValue="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo "**** Both variables $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$defaultValue" + + if [ "${!var:-}" ]; then + val="${!var}" + echo "** Using ${var} variable from ENV" + elif [ "${!fileVar:-}" ]; then + if [ ! -f "${!fileVar}" ]; then + echo "**** Secret file \"${!fileVar}\" is not found" + exit 1 + fi + val="$(< "${!fileVar}")" + echo "** Using ${var} variable from secret file" + fi + export "$var"="$val" + unset "$fileVar" +} + +escape_spec_char() { + local var_value=$1 + + var_value="${var_value//\\/\\\\}" + var_value="${var_value//[$'\n']/}" + var_value="${var_value//\//\\/}" + var_value="${var_value//./\\.}" + var_value="${var_value//\*/\\*}" + var_value="${var_value//^/\\^}" + var_value="${var_value//\$/\\\$}" + var_value="${var_value//\&/\\\&}" + var_value="${var_value//\[/\\[}" + var_value="${var_value//\]/\\]}" + + echo "$var_value" +} + +update_config_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + local is_multiple=$4 + + local masklist=("DBPassword TLSPSKIdentity") + + if [ ! -f "$config_path" ]; then + echo "**** Configuration file '$config_path' does not exist" + return + fi + + if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then + echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..." + else + echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." + fi + + # Remove configuration parameter definition in case of unset or empty parameter value + if [ -z "$var_value" ]; then + sed -i -e "/^$var_name=/d" "$config_path" + echo "removed" + return + fi + + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi + echo "undefined" + return + fi + + # Use full path to a file for TLS related configuration parameters + if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then + var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value + fi + + # Escaping characters in parameter value and name + var_value=$(escape_spec_char "$var_value") + var_name=$(escape_spec_char "$var_name") + + if [ "$(grep -E "^$var_name=$var_value$" $config_path)" ]; then + echo "exists" + elif [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then + sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path" + echo "updated" + elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then + sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path" + echo "added first occurrence" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path" + echo "added" + fi + +} + +update_config_multiple_var() { + local config_path=$1 + local var_name=$2 + local var_value=$3 + + var_value="${var_value%\"}" + var_value="${var_value#\"}" + + local IFS=, + local OPT_LIST=($var_value) + + for value in "${OPT_LIST[@]}"; do + update_config_var $config_path $var_name $value true + done +} + +file_process_from_env() { + local config_path=$1 + local var_name=$2 + local file_name=$3 + local var_value=$4 + + if [ ! -z "$var_value" ]; then + echo -n "$var_value" > "${ZABBIX_INTERNAL_ENC_DIR}/$var_name" + file_name="${ZABBIX_INTERNAL_ENC_DIR}/${var_name}" + fi + update_config_var $config_path "$var_name" "$file_name" +} + +# Check prerequisites for PostgreSQL database +check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + + file_env POSTGRES_USER + file_env POSTGRES_PASSWORD + + DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} + DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} + + DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} + DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"} + + : ${DB_SERVER_SCHEMA:="public"} + + DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} + + : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi +} + +check_db_connect_postgresql() { + echo "********************" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi + echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" + echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" + if [ "${DEBUG_MODE,,}" == "true" ]; then + echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}" + echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}" + fi + echo "********************" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + WAIT_TIMEOUT=5 + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + while true : + do + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + + echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." + sleep $WAIT_TIMEOUT + done + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +psql_query() { + query=$1 + db=$2 + + local result="" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ + --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + + echo $result +} + +exec_sql_file() { + sql_script=$1 + + local command="cat" + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + if [ "${sql_script: -3}" == ".gz" ]; then + command="zcat" + fi + + $command $sql_script | psql --quiet \ + $psql_connect_args \ + --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY +} + +create_db_database_postgresql() { + DB_EXISTS=$(psql_query "SELECT 1 AS result FROM pg_database WHERE datname='${DB_SERVER_DBNAME}'" "${DB_SERVER_DBNAME}") + + if [ -z ${DB_EXISTS} ]; then + echo "** Database '${DB_SERVER_DBNAME}' does not exist. Creating..." + + if [ -n "${DB_SERVER_ZBX_PASS}" ]; then + export PGPASSWORD="${DB_SERVER_ZBX_PASS}" + fi + + if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then + PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}" + export PGOPTIONS + fi + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + PGSSLMODE=${ZBX_DBTLSCONNECT//_/-} + export PGSSLMODE=${PGSSLMODE//required/require} + export PGSSLROOTCERT=${ZBX_DBTLSCAFILE} + export PGSSLCERT=${ZBX_DBTLSCERTFILE} + export PGSSLKEY=${ZBX_DBTLSKEYFILE} + fi + + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ + --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" + + unset PGPASSWORD + unset PGOPTIONS + unset PGSSLMODE + unset PGSSLROOTCERT + unset PGSSLCERT + unset PGSSLKEY + else + echo "** Database '${DB_SERVER_DBNAME}' already exists. Please be careful with database owner!" + fi + + psql_query "CREATE SCHEMA IF NOT EXISTS ${DB_SERVER_SCHEMA}" "${DB_SERVER_DBNAME}" 1>/dev/null +} + +create_db_schema_postgresql() { + DBVERSION_TABLE_EXISTS=$(psql_query "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = + c.relnamespace WHERE n.nspname = '$DB_SERVER_SCHEMA' AND c.relname = 'dbversion'" "${DB_SERVER_DBNAME}") + + if [ -n "${DBVERSION_TABLE_EXISTS}" ]; then + echo "** Table '${DB_SERVER_DBNAME}.dbversion' already exists." + ZBX_DB_VERSION=$(psql_query "SELECT mandatory FROM ${DB_SERVER_SCHEMA}.dbversion" "${DB_SERVER_DBNAME}") + fi + + if [ -z "${ZBX_DB_VERSION}" ]; then + echo "** Creating '${DB_SERVER_DBNAME}' schema in PostgreSQL" + + exec_sql_file "/usr/share/doc/zabbix-proxy-postgresql/create.sql.gz" + fi +} + +update_zbx_config() { + echo "** Preparing Zabbix proxy configuration file" + + ZBX_CONFIG=${ZABBIX_CONF_DIR}/zabbix_proxy.conf + + update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}" + update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}" + if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then + update_config_var $ZBX_CONFIG "Hostname" "" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + else + update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-postgresql"}" + update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}" + fi + + update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}" + update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}" + update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}" + + update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}" + update_config_var $ZBX_CONFIG "LogType" "console" + update_config_var $ZBX_CONFIG "LogFile" + update_config_var $ZBX_CONFIG "LogFileSize" + update_config_var $ZBX_CONFIG "PidFile" + + update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}" + + if [ -n "${ZBX_DBTLSCONNECT}" ]; then + update_config_var $ZBX_CONFIG "DBTLSConnect" "${ZBX_DBTLSCONNECT}" + update_config_var $ZBX_CONFIG "DBTLSCAFile" "${ZBX_DBTLSCAFILE}" + update_config_var $ZBX_CONFIG "DBTLSCertFile" "${ZBX_DBTLSCERTFILE}" + update_config_var $ZBX_CONFIG "DBTLSKeyFile" "${ZBX_DBTLSKEYFILE}" + update_config_var $ZBX_CONFIG "DBTLSCipher" "${ZBX_DBTLSCIPHER}" + update_config_var $ZBX_CONFIG "DBTLSCipher13" "${ZBX_DBTLSCIPHER13}" + fi + + update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}" + update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}" + + if [ ! -n "${DB_SERVER_SOCKET}" ]; then + update_config_var $ZBX_CONFIG "DBHost" "${DB_SERVER_HOST}" + update_config_var $ZBX_CONFIG "DBPort" "${DB_SERVER_PORT}" + else + update_config_var $ZBX_CONFIG "DBHost" + update_config_var $ZBX_CONFIG "DBPort" + fi + update_config_var $ZBX_CONFIG "DBSocket" "${DB_SERVER_SOCKET}" + update_config_var $ZBX_CONFIG "DBName" "${DB_SERVER_DBNAME}" + update_config_var $ZBX_CONFIG "DBSchema" "${DB_SERVER_SCHEMA}" + + if [ -n "${ZBX_VAULTDBPATH}" ] && [ -n "${ZBX_VAULTURL}" ]; then + update_config_var $ZBX_CONFIG "Vault" "${ZBX_VAULT}" + update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" "${ZBX_VAULTTLSCERTFILE}" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" "${ZBX_VAULTTLSKEYFILE}" + update_config_var $ZBX_CONFIG "VaultPrefix" "${ZBX_VAULTPREFIX}" + update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}" + update_config_var $ZBX_CONFIG "DBUser" + update_config_var $ZBX_CONFIG "DBPassword" + else + update_config_var $ZBX_CONFIG "Vault" + update_config_var $ZBX_CONFIG "VaultDBPath" + update_config_var $ZBX_CONFIG "VaultTLSCertFile" + update_config_var $ZBX_CONFIG "VaultTLSKeyFile" + update_config_var $ZBX_CONFIG "VaultPrefix" + update_config_var $ZBX_CONFIG "VaultURL" + update_config_var $ZBX_CONFIG "DBUser" "${DB_SERVER_ZBX_USER}" + update_config_var $ZBX_CONFIG "DBPassword" "${DB_SERVER_ZBX_PASS}" + fi + + update_config_var $ZBX_CONFIG "AllowUnsupportedDBVersions" "${ZBX_ALLOWUNSUPPORTEDDBVERSIONS}" + update_config_var $ZBX_CONFIG "MaxConcurrentChecksPerPoller" "${ZBX_MAXCONCURRENTCHECKSPERPOLLER}" + + update_config_var $ZBX_CONFIG "ProxyBufferMode" "${ZBX_PROXYBUFFERMODE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferAge" "${ZBX_PROXYMEMORYBUFFERAGE}" + update_config_var $ZBX_CONFIG "ProxyMemoryBufferSize" "${ZBX_PROXYMEMORYBUFFERSIZE}" + + update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}" + update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}" + update_config_var $ZBX_CONFIG "ProxyConfigFrequency" "${ZBX_PROXYCONFIGFREQUENCY}" + update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}" + + update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}" + update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}" + + update_config_var $ZBX_CONFIG "StartAgentPollers" "${ZBX_STARTAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}" + update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_STARTIPMIPOLLERS}" + update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}" + update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}" + update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}" + update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}" + update_config_var $ZBX_CONFIG "StartHTTPAgentPollers" "${ZBX_STARTHTTPAGENTPOLLERS}" + update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}" + update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}" + update_config_var $ZBX_CONFIG "StartSNMPPollers" "${ZBX_STARTSNMPPOLLERS}" + + : ${ZBX_JAVAGATEWAY_ENABLE:="false"} + if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}" + update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}" + update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}" + else + update_config_var $ZBX_CONFIG "JavaGateway" + update_config_var $ZBX_CONFIG "JavaGatewayPort" + update_config_var $ZBX_CONFIG "StartJavaPollers" + fi + + update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}" + update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}" + update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}" + update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}" + + : ${ZBX_ENABLE_SNMP_TRAPS:="false"} + if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then + update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1" + else + update_config_var $ZBX_CONFIG "SNMPTrapperFile" + update_config_var $ZBX_CONFIG "StartSNMPTrapper" + fi + + update_config_var $ZBX_CONFIG "SocketDir" "/tmp/" + update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}" + + update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}" + + update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}" + update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}" + update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}" + + update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}" + update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}" + update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}" + update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}" + update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}" + + update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts" + + update_config_var $ZBX_CONFIG "FpingLocation" "${ZBX_FPINGLOCATION}" + update_config_var $ZBX_CONFIG "Fping6Location" '""' + + update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys" + update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}" + + update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/" + update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/" + update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" + update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/" + update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}" + + update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}" + update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}" + file_process_from_env $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}" "${ZBX_TLSCA}" + file_process_from_env $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}" "${ZBX_TLSCRL}" + + update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}" + update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}" + + file_process_from_env $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}" "${ZBX_TLSCERT}" + update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}" + update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}" + update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}" + update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}" + update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}" + update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}" + file_process_from_env $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}" "${ZBX_TLSKEY}" + + update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}" + file_process_from_env $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}" "${ZBX_TLSPSK}" + + if [ "$(id -u)" != '0' ]; then + update_config_var $ZBX_CONFIG "User" "$(whoami)" + else + update_config_var $ZBX_CONFIG "AllowRoot" "1" + fi + + update_config_var $ZBX_CONFIG "WebDriverURL" "${ZBX_WEBDRIVERURL}" + update_config_var $ZBX_CONFIG "StartBrowserPollers" "${ZBX_STARTBROWSERPOLLERS}" + + command -v openssl >/dev/null 2>&1 && openssl rehash -v "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/" 1>/dev/null +} + +clear_zbx_env() { + [[ "${ZBX_CLEAR_ENV}" == "false" ]] && return + + for env_var in $(env | grep -E "^(ZBX|DB|POSTGRES)_"); do + unset "${env_var%%=*}" + done +} + +prepare_db() { + echo "** Preparing database" + + check_variables_postgresql + check_db_connect_postgresql + create_db_database_postgresql + create_db_schema_postgresql +} + +prepare_proxy() { + echo "** Preparing Zabbix proxy" + + prepare_db + update_zbx_config + clear_zbx_env +} + +################################################# + +if [ "${1#-}" != "$1" ]; then + set -- /usr/sbin/zabbix_proxy "$@" +fi + +if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then + prepare_proxy +fi + +if [ "$1" == "init_db_only" ]; then + prepare_db +else + + # Additional configuration every startup + if [ -d "${ZABBIX_USER_HOME_DIR}/dbscripts/startup" ]; then + for sql_script in "${ZABBIX_USER_HOME_DIR}/dbscripts/startup/*.sql"; do + [ -e "$sql_script" ] || continue + echo "** Processing additional '$sql_script' SQL script" + + exec_sql_file "$sql_script" + done + fi + + exec "$@" +fi + +################################################# diff --git a/build.json b/build.json index 1093ecb00a..0f0c150484 100644 --- a/build.json +++ b/build.json @@ -33,6 +33,7 @@ "agent2": { "base": "build-mysql", "rhel": true, "rhel_project": "66425489c3f1cbe661cf6135" }, "java-gateway": { "base": "build-mysql", "rhel": true, "rhel_project": "66425456fc1b23180a424e19" }, "proxy-mysql": { "base": "build-mysql", "rhel": true, "rhel_project": "6642544aa84deaf9b8e1e987" }, + "proxy-pgsql": { "base": "build-pgsql", "rhel": true, "rhel_project": "" }, "proxy-sqlite3": { "base": "build-sqlite3", "rhel": true, "rhel_project": "6642544aff927b6e9cd8ac61" }, "server-mysql": { "base": "build-mysql", "rhel": true, "rhel_project": "66425419fc1b23180a424c56" }, "server-pgsql": { "base": "build-pgsql", "rhel": true, "rhel_project": "6642543965a1ed1a86f32682" }, diff --git a/compose_zabbix_components.yaml b/compose_zabbix_components.yaml index 0ffb680ffd..0dc69c4cf0 100644 --- a/compose_zabbix_components.yaml +++ b/compose_zabbix_components.yaml @@ -261,6 +261,36 @@ services: com.zabbix.description: "Zabbix proxy with MySQL database support (database init)" com.zabbix.dbtype: "mysql" + proxy-pgsql-db-init: + init: true + profiles: + - all + attach: true + volumes: + - ${DATA_DIRECTORY}/var/lib/zabbix/dbscripts:/var/lib/zabbix/dbscripts:ro +# - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro +# - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/client-cert.pem:ro +# - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/client-key.pem:ro +# - pgsql_socket:/var/run/postgresql + command: init_db_only + tmpfs: /tmp + env_file: + - path: ${ENV_VARS_DIRECTORY}/.env_db_pgsql_proxy + required: true + secrets: + - POSTGRES_USER + - POSTGRES_PASSWORD +# - client-key.pem +# - client-cert.pem +# - root-ca.pem + networks: + database: + aliases: + - zabbix-proxy-pgsql-init + labels: + com.zabbix.description: "Zabbix proxy with PostgreSQL database support (database init)" + com.zabbix.dbtype: "pgsql" + proxy-mysql: extends: service: proxy @@ -296,6 +326,41 @@ services: com.zabbix.description: "Zabbix proxy with MySQL database support" com.zabbix.dbtype: "mysql" + proxy-pgsql: + extends: + service: proxy + ports: + - name: zabbix-trapper + target: 10051 + published: "${ZABBIX_PROXY_PGSQL_PORT}" + protocol: tcp + app_protocol: zabbix-trapper +# volumes: +# - mysql_socket:/var/run/mysqld/ + env_file: + - path: ${ENV_VARS_DIRECTORY}/.env_db_pgsql_proxy + required: true + - path: ${ENV_VARS_DIRECTORY}/.env_prx_pgsql + required: true + - path: ${ENV_VARS_DIRECTORY}/.env_prx_pgsql_override + required: false + secrets: + - POSTGRES_USER + - POSTGRES_PASSWORD +# - client-key.pem +# - client-cert.pem +# - root-ca.pem + networks: + database: + aliases: + - zabbix-proxy-pgsql + backend: + aliases: + - zabbix-proxy-pgsql + labels: + com.zabbix.description: "Zabbix proxy with PostgreSQL database support" + com.zabbix.dbtype: "pgsql" + web-apache: profiles: - all diff --git a/env_vars/.env_db_pgsql_proxy b/env_vars/.env_db_pgsql_proxy new file mode 100644 index 0000000000..62b4631896 --- /dev/null +++ b/env_vars/.env_db_pgsql_proxy @@ -0,0 +1,11 @@ +# DB_SERVER_HOST=postgres-server +# DB_SERVER_PORT=5432 +# POSTGRES_USER=zabbix +POSTGRES_USER_FILE=/run/secrets/POSTGRES_USER +# POSTGRES_PASSWORD=zabbix +POSTGRES_PASSWORD_FILE=/run/secrets/POSTGRES_PASSWORD +# POSTGRES_DB=zabbix +POSTGRES_DB=zabbix +# DB_SERVER_SCHEMA=public +# ENABLE_TIMESCALEDB=false +# POSTGRES_USE_IMPLICIT_SEARCH_PATH=false diff --git a/env_vars/.env_prx_pgsql b/env_vars/.env_prx_pgsql new file mode 100644 index 0000000000..ed0ad42084 --- /dev/null +++ b/env_vars/.env_prx_pgsql @@ -0,0 +1,8 @@ +# ZBX_HOSTNAME=zabbix-proxy-postgresql +# ZBX_DBTLSCONNECT=require # Available since 5.0.0 +# ZBX_DBTLSCAFILE=/run/secrets/root-ca.pem # Available since 5.0.0 +# ZBX_DBTLSCERTFILE=/run/secrets/client-cert.pem # Available since 5.0.0 +# ZBX_DBTLSKEYFILE=/run/secrets/client-key.pem # Available since 5.0.0 +# ZBX_DBTLSCIPHER= # Available since 5.0.0 +# ZBX_DBTLSCIPHER13= # Available since 5.0.0 +# ZBX_ALLOWUNSUPPORTEDDBVERSIONS=0 # Available since 6.0.0 From 5cb1976a2d224b525d8e025415a7fb8256f4222e Mon Sep 17 00:00:00 2001 From: Adam Gelwarg Date: Tue, 5 Aug 2025 15:52:44 -0400 Subject: [PATCH 2/3] Remove unnecessary DB_CHARACTER_SET and DB_CHARACTER_COLLATE --- Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh | 3 --- Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh | 3 --- Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh | 3 --- Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh | 3 --- Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh | 3 --- 5 files changed, 15 deletions(-) diff --git a/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh index d5aa604c3b..db19fe47d0 100755 --- a/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh +++ b/Dockerfiles/proxy-pgsql/alpine/docker-entrypoint.sh @@ -16,9 +16,6 @@ fi # Internal directory for TLS related files, used when TLS*File specified as plain text values ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" -: ${DB_CHARACTER_SET:="utf8mb4"} -: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} - # usage: file_env VAR [DEFAULT] # as example: file_env 'MYSQL_PASSWORD' 'zabbix' # (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) diff --git a/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh index d5aa604c3b..db19fe47d0 100755 --- a/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh +++ b/Dockerfiles/proxy-pgsql/centos/docker-entrypoint.sh @@ -16,9 +16,6 @@ fi # Internal directory for TLS related files, used when TLS*File specified as plain text values ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" -: ${DB_CHARACTER_SET:="utf8mb4"} -: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} - # usage: file_env VAR [DEFAULT] # as example: file_env 'MYSQL_PASSWORD' 'zabbix' # (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) diff --git a/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh index d5aa604c3b..db19fe47d0 100755 --- a/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh +++ b/Dockerfiles/proxy-pgsql/ol/docker-entrypoint.sh @@ -16,9 +16,6 @@ fi # Internal directory for TLS related files, used when TLS*File specified as plain text values ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" -: ${DB_CHARACTER_SET:="utf8mb4"} -: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} - # usage: file_env VAR [DEFAULT] # as example: file_env 'MYSQL_PASSWORD' 'zabbix' # (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) diff --git a/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh index d5aa604c3b..db19fe47d0 100755 --- a/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh +++ b/Dockerfiles/proxy-pgsql/rhel/docker-entrypoint.sh @@ -16,9 +16,6 @@ fi # Internal directory for TLS related files, used when TLS*File specified as plain text values ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" -: ${DB_CHARACTER_SET:="utf8mb4"} -: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} - # usage: file_env VAR [DEFAULT] # as example: file_env 'MYSQL_PASSWORD' 'zabbix' # (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) diff --git a/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh b/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh index d5aa604c3b..db19fe47d0 100755 --- a/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/proxy-pgsql/ubuntu/docker-entrypoint.sh @@ -16,9 +16,6 @@ fi # Internal directory for TLS related files, used when TLS*File specified as plain text values ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal" -: ${DB_CHARACTER_SET:="utf8mb4"} -: ${DB_CHARACTER_COLLATE:="utf8mb4_bin"} - # usage: file_env VAR [DEFAULT] # as example: file_env 'MYSQL_PASSWORD' 'zabbix' # (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file) From f104e9e4464d7f36e0a5e9414805e2ff458a659c Mon Sep 17 00:00:00 2001 From: Adam Gelwarg Date: Tue, 5 Aug 2025 17:34:07 -0400 Subject: [PATCH 3/3] Update the README.md to reference zabbix-proxy-pgsql --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b60e7bb845..ef1f41e037 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Please also follow usage instructions of each Zabbix component image: * [zabbix-web-nginx-pgsql](https://hub.docker.com/r/zabbix/zabbix-web-nginx-pgsql/) - Zabbix web interface on Nginx web server with PostgreSQL database support * [zabbix-proxy-sqlite3](https://hub.docker.com/r/zabbix/zabbix-proxy-sqlite3/) - Zabbix proxy with SQLite3 database support * [zabbix-proxy-mysql](https://hub.docker.com/r/zabbix/zabbix-proxy-mysql/) - Zabbix proxy with MySQL database support +* [zabbix-proxy-pgsql](https://hub.docker.com/r/zabbix/zabbix-proxy-pgsql/) - Zabbix proxy with PostgreSQL database support * [zabbix-java-gateway](https://hub.docker.com/r/zabbix/zabbix-java-gateway/) - Zabbix Java Gateway * [zabbix-web-service](https://hub.docker.com/r/zabbix/zabbix-web-service/) - Zabbix web service for performing various tasks using headless web browser (for example, reporting) * [zabbix-snmptraps](https://hub.docker.com/r/zabbix/zabbix-snmptraps/) - Additional container image for Zabbix server and Zabbix proxy to support SNMP traps