From 344d248a305158d7e25f65f41ae95b5d9f0643e9 Mon Sep 17 00:00:00 2001 From: sinav Date: Sun, 7 Apr 2024 15:50:57 +0300 Subject: [PATCH] wip --- zabbix-agent2/Dockerfile | 31 ++++++------------- zabbix-agent2/config.yaml | 12 ++----- .../rootfs/services.d/zabbix-agent2/run | 16 ++++++++++ zabbix-agent2/run.sh | 31 ------------------- 4 files changed, 27 insertions(+), 63 deletions(-) create mode 100644 zabbix-agent2/rootfs/services.d/zabbix-agent2/run delete mode 100644 zabbix-agent2/run.sh diff --git a/zabbix-agent2/Dockerfile b/zabbix-agent2/Dockerfile index 4418da8..4baf2aa 100644 --- a/zabbix-agent2/Dockerfile +++ b/zabbix-agent2/Dockerfile @@ -1,27 +1,14 @@ -ARG BUILD_ARCH -ARG BUILD_VERSION -ARG BUILD_BASE_IMAGE=zabbix/zabbix-agent2:alpine-trunk +ARG BUILD_FROM=ghcr.io/hassio-addons/debian-base/amd64 +ARG BUILD_ARCH=amd64 -FROM ${BUILD_BASE_IMAGE} as builder +FROM ${BUILD_FROM} -FROM alpine +RUN apt-get update && apt-get install -y wget +RUN wget https://repo.zabbix.com/zabbix/6.5/debian/pool/main/z/zabbix-release/zabbix-release_6.5-1+debian12_all.deb && dpkg -i zabbix-release_6.5-1+debian12_all.deb -LABEL maintainer "sinav" +RUN apt-get update && apt-get install -y zabbix-agent2 zabbix-agent2-plugin-* +RUN usermod -aG docker zabbix -ENV LANG C.UTF-8 +COPY rootfs / -# Install requirements for add-on -RUN apk add --no-cache jq zabbix-agent2 && \ - addgroup -g 1003 docker && \ - addgroup zabbix docker && \ - mkdir -p /etc/zabbix/zabbix_agent2.d/plugins.d - -# Copy zabbix-agent2 plugins -COPY --from=builder ["/usr/sbin/zabbix-agent2-plugin", "/usr/sbin/zabbix-agent2-plugin"] -RUN echo -e "\nPlugins.PostgreSQL.System.Path=/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-mongodb\nPlugins.PostgreSQL.System.Path=/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-postgresql\n" >> /etc/zabbix/zabbix_agent2.conf - -# Copy data for add-on -COPY run.sh / -RUN chmod a+x /run.sh - -CMD [ "/run.sh" ] \ No newline at end of file +RUN chmod a+x /etc/services.d/zabbix-agent2/run diff --git a/zabbix-agent2/config.yaml b/zabbix-agent2/config.yaml index 2331fe0..41ad4dc 100644 --- a/zabbix-agent2/config.yaml +++ b/zabbix-agent2/config.yaml @@ -18,15 +18,7 @@ host_pid: true host_network: true docker_api: true advanced: true +map: + - addon_config:rw ports: 10050/tcp: 10050 -options: - server: zabbix-server.local - serveractive: zabbix-server.local - hostname: homeassistant -schema: - server: str - serveractive: str - hostname: str - tlspskidentity: str? - tlspsksecret: str? diff --git a/zabbix-agent2/rootfs/services.d/zabbix-agent2/run b/zabbix-agent2/rootfs/services.d/zabbix-agent2/run new file mode 100644 index 0000000..867c4c8 --- /dev/null +++ b/zabbix-agent2/rootfs/services.d/zabbix-agent2/run @@ -0,0 +1,16 @@ +#!/usr/bin/with-contenv bashio +# shellcheck shell=bash +# ============================================================================== +# Home Assistant Add-on: Zabbix Agent2 +# Runs Zabbix Agent2 +# ============================================================================== + +readonly ZBX_CFG_FILE='/config/zabbix_agent2.conf' +bashio::log.info 'Starting zabbix-agent2...' + +if ! bashio::fs.file_exists "${ZBX_CFG_FILE}" || [ -z "$(ls -A ${ZBX_CFG_FILE})" ]; then + bashio::log.info "No config ${ZBX_CFG_FILE} exists, copying default." + cp /etc/zabbix/zabbix_agent2.conf ${ZBX_CFG_FILE} +fi + +/usr/sbin/zabbix_agent2 -c /config/zabbix_agent2.conf diff --git a/zabbix-agent2/run.sh b/zabbix-agent2/run.sh deleted file mode 100644 index c4617e5..0000000 --- a/zabbix-agent2/run.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env ash -# shellcheck shell=dash - -# Extract config data -CONFIG_PATH=/data/options.json -ZABBIX_SERVER=$(jq --raw-output ".server" "${CONFIG_PATH}") -ZABBIX_SERVER_ACTIVE=$(jq --raw-output ".serveractive" "${CONFIG_PATH}") -ZABBIX_HOSTNAME=$(jq --raw-output ".hostname" "${CONFIG_PATH}") -ZABBIX_TLSPSK_IDENTITY=$(jq --raw-output ".tlspskidentity" "${CONFIG_PATH}") -ZABBIX_TLSPSK_SECRET=$(jq --raw-output ".tlspsksecret" "${CONFIG_PATH}") - -# Update zabbix-agent config -ZABBIX_CONFIG_FILE=/etc/zabbix/zabbix_agent2.conf -sed -i 's@^\(Server\)=.*@\1='"${ZABBIX_SERVER}"'@' "${ZABBIX_CONFIG_FILE}" -sed -i 's@^\(ServerActive\)=.*@\1='"${ZABBIX_SERVER_ACTIVE}"'@' "${ZABBIX_CONFIG_FILE}" -sed -i 's@^#\?\s\?\(Hostname\)=.*@\1='"${ZABBIX_HOSTNAME}"'@' "${ZABBIX_CONFIG_FILE}" - -# Add TLS PSK config if variables are used -if [ "${ZABBIX_TLSPSK_IDENTITY}" != "null" ] && [ "${ZABBIX_TLSPSK_SECRET}" != "null" ]; then - ZABBIX_TLSPSK_SECRET_FILE=/etc/zabbix/tls_secret - echo "${ZABBIX_TLSPSK_SECRET}" > "${ZABBIX_TLSPSK_SECRET_FILE}" - sed -i 's@^#\?\s\?\(TLSConnect\)=.*@\1='"psk"'@' "${ZABBIX_CONFIG_FILE}" - sed -i 's@^#\?\s\?\(TLSAccept\)=.*@\1='"psk"'@' "${ZABBIX_CONFIG_FILE}" - sed -i 's@^#\?\s\?\(TLSPSKIdentity\)=.*@\1='"${ZABBIX_TLSPSK_IDENTITY}"'@' "${ZABBIX_CONFIG_FILE}" - sed -i 's@^#\?\s\?\(TLSPSKFile\)=.*@\1='"${ZABBIX_TLSPSK_SECRET_FILE}"'@' "${ZABBIX_CONFIG_FILE}" -fi -unset ZABBIX_TLSPSK_IDENTITY -unset ZABBIX_TLSPSK_SECRET - -# Run zabbix-agent2 in foreground -exec su zabbix -s /bin/ash -c "zabbix_agent2 -f" \ No newline at end of file