This commit is contained in:
2025-04-24 19:42:14 +03:00
parent 22cb685d90
commit 43acf825d7
15 changed files with 94 additions and 389 deletions

View File

@@ -1,23 +0,0 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# shellcheck disable=SC2207
# ==============================================================================
# Home Assistant Add-on: Vector
# Copy default config
# ==============================================================================
readonly CONFIG_PATH="/config/vector.yaml"
readonly DEFAULT_CONFIG="/vector.yaml"
if ! bashio::fs.file_exists "$CONFIG_PATH"; then
bashio::log.info "Copying default configuration from $DEFAULT_CONFIG"
if cp "$DEFAULT_CONFIG" "$CONFIG_PATH"; then
bashio::log.info "Default configuration copied successfully"
else
bashio::log.error "Failed to copy default configuration!"
exit 1
fi
else
bashio::log.info "Using existing configuration at $CONFIG_PATH"
fi

View File

@@ -1 +0,0 @@
oneshot

View File

@@ -1 +0,0 @@
/etc/s6-overlay/s6-rc.d/init-vector/run

View File

@@ -1,85 +1,30 @@
ARG MAJOR_VERSION=7.0
ARG ZBX_VERSION=${MAJOR_VERSION}.0
ARG BUILD_BASE_IMAGE=zabbix/zabbix-build-mysql:alpine-${ZBX_VERSION}
# ARG BUILD_FROM
ARG BUILD_FROM=ghcr.io/hassio-addons/base:16.1.0
FROM ${BUILD_BASE_IMAGE} AS builder
# FROM $BUILD_FROM
# FROM alpine:3.19
ARG BUILD_FROM=ghcr.io/hassio-addons/debian-base:7.8.2
# hadolint ignore=DL3006
FROM ${BUILD_FROM}
ARG MAJOR_VERSION
ARG ZBX_VERSION
ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES}
ARG MAJOR_VERSION=7.2
ARG ZABBIX_VERSION=${MAJOR_VERSION}.6
ARG ZABBIX_DEB_URL="https://repo.zabbix.com/zabbix/${MAJOR_VERSION}/release/debian/pool/main/z/zabbix-release"
ARG ZABBIX_DEB_PKG="zabbix-release_latest_${MAJOR_VERSION}+debian12_all.deb"
STOPSIGNAL SIGTERM
RUN apt-get update && \
apt-get install -y wget gnupg2 lsb-release && \
wget ${ZABBIX_DEB_URL}/${ZABBIX_DEB_PKG} -O /tmp/zabbix-release.deb && \
dpkg -i /tmp/zabbix-release.deb && \
apt-get update && \
apt-get install -y \
zabbix-agent2=1:${ZABBIX_VERSION}* \
smartmontools \
sudo \
iputils-ping && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/zabbix-release.deb
COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}/src/go/bin/zabbix_agent2", "/usr/sbin/zabbix_agent2"]
COPY --from=builder ["/tmp/zabbix-${ZBX_VERSION}/conf/zabbix_agentd.conf", "/etc/zabbix/zabbix_agent2.conf"]
LABEL \
org.opencontainers.image.title="Zabbix Agent2 Add-on" \
org.opencontainers.image.description="Zabbix Agent2 for monitoring Home Assistant and related components" \
org.opencontainers.image.url="https://www.zabbix.com" \
org.opencontainers.image.documentation="https://www.zabbix.com/documentation/current/manual/agent2"
# COPY run.sh /run.sh
COPY rootfs /
RUN set -eux && \
INSTALL_PKGS="bash \
tzdata \
pcre2 \
coreutils \
smartmontools \
sudo \
iputils" && \
apk add \
--no-cache \
--clean-protected \
${INSTALL_PKGS} && \
addgroup \
--system \
--gid 1995 \
zabbix && \
addgroup \
--system \
--gid 102 \
docker && \
adduser \
--system \
--gecos "Zabbix monitoring system" \
--disabled-password \
--uid 1997 \
--ingroup zabbix \
--shell /sbin/nologin \
--home /var/lib/zabbix/ \
zabbix && \
adduser zabbix docker && \
echo "zabbix ALL=(root) NOPASSWD: /usr/sbin/smartctl" >> /etc/sudoers.d/zabbix && \
mkdir -p /etc/zabbix && \
mkdir -p /etc/zabbix/zabbix_agentd.d && \
mkdir -p /var/lib/zabbix && \
mkdir -p /var/lib/zabbix/enc && \
mkdir -p /var/lib/zabbix/modules && \
mkdir -p /var/lib/zabbix/buffer && \
chown --quiet -R zabbix:root /etc/zabbix/ /var/lib/zabbix/ && \
chgrp -R 0 /etc/zabbix/ /var/lib/zabbix/ && \
chmod -R g=u /etc/zabbix/ /var/lib/zabbix/ && \
chmod a+x /etc/services.d/zabbix_agent2/run && \
chmod a+x /etc/services.d/zabbix_agent2/finish && \
chmod a+x /run.sh
EXPOSE 10050/TCP
WORKDIR /var/lib/zabbix
# COPY run.sh /run.sh
# RUN chown --quiet -R zabbix:root /run.sh && chmod a+x /run.sh
# COPY ["docker-entrypoint.sh", "/usr/bin/"]
ENTRYPOINT ["/run.sh"]
CMD ["/run.sh"]
USER 1997
# CMD ["/usr/sbin/zabbix_agent2", "--foreground", "-c", "/config/zabbix_agent2.conf"]

View File

@@ -1,8 +1,5 @@
---
build_from:
aarch64: ghcr.io/hassio-addons/base:16.1.0
amd64: ghcr.io/hassio-addons/base:16.1.0
armv7: ghcr.io/hassio-addons/base:16.1.0
amd64: ghcr.io/hassio-addons/debian-base/amd64:7.8.2
codenotary:
base_image: codenotary@frenck.dev
signer: codenotary@frenck.dev

View File

@@ -1,21 +1,27 @@
---
name: zabbix-agent2
version: '7.0.0'
version: '7.2.6'
slug: zabbix-agent2
description: Zabbix agent 2
url: https://gitea.sinav-lab.com/sinav/haos-addons
arch:
- amd64
startup: services
boot: auto
apparmor: false
full_access: true
host_ipc: true
host_pid: true
host_network: true
docker_api: true
init: false
journald: true
startup: system
advanced: true
docker_api: true
map:
- addon_config:rw
options: {}
schema: {}
ports:
10050/tcp: 10050
10051/tcp: 10051
devices:
- /dev/nvme0
privileged:
- SYS_ADMIN
- SYS_RAWIO
full_access: true

View File

@@ -1,226 +0,0 @@
#!/bin/bash
set -o pipefail
set +e
# Script trace mode
if [ "${DEBUG_MODE,,}" == "true" ]; then
set -o xtrace
fi
# Default Zabbix installation name
# Default Zabbix server host
: ${ZBX_SERVER_HOST:="zabbix-server"}
# Default Zabbix server port number
: ${ZBX_SERVER_PORT:="10051"}
# Default directories
# User 'zabbix' home directory
ZABBIX_USER_HOME_DIR="/var/lib/zabbix"
# Configuration files directory
ZABBIX_ETC_DIR="/etc/zabbix"
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=("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 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 double quoted parameter value
if [ "$var_value" == '""' ]; then
sed -i -e "/^$var_name=/s/=.*/=/" "$config_path"
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=" $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"
elif [ "$(grep -Ec "^[#;] $var_name=" $config_path)" -gt 0 ]; then
sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path"
echo "added"
else
sed -i -e '$a\' -e "$var_name=$var_value" "$config_path"
echo "added at the end"
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
}
prepare_zbx_agent_config() {
echo "** Preparing Zabbix agent configuration file"
ZBX_AGENT_CONFIG=$ZABBIX_ETC_DIR/zabbix_agent2.conf
: ${ZBX_PASSIVESERVERS:=""}
: ${ZBX_ACTIVESERVERS:=""}
[ -n "$ZBX_PASSIVESERVERS" ] && ZBX_PASSIVESERVERS=","$ZBX_PASSIVESERVERS
ZBX_PASSIVESERVERS=$ZBX_SERVER_HOST$ZBX_PASSIVESERVERS
[ -n "$ZBX_ACTIVESERVERS" ] && ZBX_ACTIVESERVERS=","$ZBX_ACTIVESERVERS
ZBX_ACTIVESERVERS=$ZBX_SERVER_HOST":"$ZBX_SERVER_PORT$ZBX_ACTIVESERVERS
update_config_var $ZBX_AGENT_CONFIG "PidFile"
update_config_var $ZBX_AGENT_CONFIG "LogType" "console"
update_config_var $ZBX_AGENT_CONFIG "LogFile"
update_config_var $ZBX_AGENT_CONFIG "LogFileSize"
update_config_var $ZBX_AGENT_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}"
update_config_var $ZBX_AGENT_CONFIG "SourceIP"
: ${ZBX_PASSIVE_ALLOW:="true"}
if [ "${ZBX_PASSIVE_ALLOW,,}" == "true" ]; then
echo "** Using '$ZBX_PASSIVESERVERS' servers for passive checks"
update_config_var $ZBX_AGENT_CONFIG "Server" "${ZBX_PASSIVESERVERS}"
else
update_config_var $ZBX_AGENT_CONFIG "Server"
fi
update_config_var $ZBX_AGENT_CONFIG "ListenPort" "${ZBX_LISTENPORT}"
update_config_var $ZBX_AGENT_CONFIG "ListenIP" "${ZBX_LISTENIP}"
: ${ZBX_ACTIVE_ALLOW:="true"}
if [ "${ZBX_ACTIVE_ALLOW,,}" == "true" ]; then
echo "** Using '$ZBX_ACTIVESERVERS' servers for active checks"
update_config_var $ZBX_AGENT_CONFIG "ServerActive" "${ZBX_ACTIVESERVERS}"
else
update_config_var $ZBX_AGENT_CONFIG "ServerActive"
fi
update_config_var $ZBX_AGENT_CONFIG "HeartbeatFrequency" "${ZBX_HEARTBEAT_FREQUENCY}"
update_config_var $ZBX_AGENT_CONFIG "ForceActiveChecksOnStart" "${ZBX_FORCEACTIVECHECKSONSTART}"
if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then
update_config_var $ZBX_AGENT_CONFIG "EnablePersistentBuffer" "1"
update_config_var $ZBX_AGENT_CONFIG "PersistentBufferFile" "$ZABBIX_USER_HOME_DIR/buffer/agent2.db"
update_config_var $ZBX_AGENT_CONFIG "PersistentBufferPeriod" "${ZBX_PERSISTENTBUFFERPERIOD}"
else
update_config_var $ZBX_AGENT_CONFIG "EnablePersistentBuffer" "0"
fi
if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then
update_config_var $ZBX_AGENT_CONFIG "StatusPort" "31999"
fi
update_config_var $ZBX_AGENT_CONFIG "HostInterface" "${ZBX_HOSTINTERFACE}"
update_config_var $ZBX_AGENT_CONFIG "HostInterfaceItem" "${ZBX_HOSTINTERFACEITEM}"
update_config_var $ZBX_AGENT_CONFIG "Hostname" "${ZBX_HOSTNAME}"
update_config_var $ZBX_AGENT_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}"
update_config_var $ZBX_AGENT_CONFIG "HostMetadata" "${ZBX_METADATA}"
update_config_var $ZBX_AGENT_CONFIG "HostMetadataItem" "${ZBX_METADATAITEM}"
update_config_var $ZBX_AGENT_CONFIG "RefreshActiveChecks" "${ZBX_REFRESHACTIVECHECKS}"
update_config_var $ZBX_AGENT_CONFIG "BufferSend" "${ZBX_BUFFERSEND}"
update_config_var $ZBX_AGENT_CONFIG "BufferSize" "${ZBX_BUFFERSIZE}"
# Please use include to enable Alias feature
# update_config_multiple_var $ZBX_AGENT_CONFIG "Alias" ${ZBX_ALIAS}
update_config_var $ZBX_AGENT_CONFIG "Timeout" "${ZBX_TIMEOUT}"
update_config_var $ZBX_AGENT_CONFIG "Include" "/etc/zabbix/zabbix_agent2.d/plugins.d/*.conf"
update_config_var $ZBX_AGENT_CONFIG "Include" "/etc/zabbix/zabbix_agentd.d/*.conf" "true"
update_config_var $ZBX_AGENT_CONFIG "UnsafeUserParameters" "${ZBX_UNSAFEUSERPARAMETERS}"
update_config_var $ZBX_AGENT_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}"
update_config_var $ZBX_AGENT_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}"
update_config_var $ZBX_AGENT_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}"
update_config_var $ZBX_AGENT_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}"
update_config_var $ZBX_AGENT_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}"
update_config_var $ZBX_AGENT_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}"
update_config_var $ZBX_AGENT_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}"
update_config_var $ZBX_AGENT_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}"
update_config_var $ZBX_AGENT_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}"
update_config_var $ZBX_AGENT_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}"
update_config_multiple_var $ZBX_AGENT_CONFIG "DenyKey" "${ZBX_DENYKEY}"
update_config_multiple_var $ZBX_AGENT_CONFIG "AllowKey" "${ZBX_ALLOWKEY}"
}
prepare_zbx_agent_plugin_config() {
echo "** Preparing Zabbix agent plugin configuration files"
update_config_var "/etc/zabbix/zabbix_agent2.d/plugins.d/mongodb.conf" "Plugins.MongoDB.System.Path" "/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-mongodb"
update_config_var "/etc/zabbix/zabbix_agent2.d/plugins.d/postgresql.conf" "Plugins.PostgreSQL.System.Path" "/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-postgresql"
}
prepare_agent() {
echo "** Preparing Zabbix agent"
prepare_zbx_agent_config
prepare_zbx_agent_plugin_config
}
#################################################
if [ "${1#-}" != "$1" ]; then
set -- /usr/sbin/zabbix_agent2 "$@"
fi
if [ "$1" == '/usr/sbin/zabbix_agent2' ]; then
prepare_agent
fi
exec "$@"
#################################################

View File

@@ -0,0 +1,45 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Vector
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="zabvbix-agent2"
bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"
# Received a signal
if [[ "${exit_code_service}" -eq 256 ]]; then
# The signal might be a result of another service crashing. Only
# overwrite the container exit code if it is not already set.
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
# If the signal is SIGTERM, we should halt the container and take down
# the whole process tree.
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
# The service exited with a non-zero exit code, which means it crashed.
elif [[ "${exit_code_service}" -ne 0 ]]; then
# The service might be a result of another service crashing. Only
# overwrite the container exit code if it is not already set.
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
# We should halt the container and take down the whole process tree.
exec /run/s6/basedir/bin/halt
# The service exited with a zero exit code, which means it exited, let
# S6 supervision restart it.
else
bashio::log.info "Service ${service} restarting..."
fi

View File

@@ -0,0 +1,10 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Zabbix Agent2
# Runs zabbix_agent2
# ==============================================================================
bashio::log.info "Starting Zabbix Agent2..."
exec /usr/sbin/zabbix_agent2 -c /config/zabbix-agent2.conf --foreground

View File

@@ -0,0 +1 @@
longrun

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env bashio
# ==============================================================================
# Take down the S6 supervision tree when zabbix agent 2 fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
declare APP_EXIT_CODE=${1}
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt
fi
bashio::log.info "Service restart after closing"

View File

@@ -1,20 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Zabbix agent 2
# Runs zabbix agent 2
# ==============================================================================
declare -a options
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
options+=(--foreground)
options+=(-c /config/zabbix_agent2.conf)
exec zabbix_agent2 "${options[@]}"

View File

@@ -1,13 +0,0 @@
#!/usr/bin/with-contenv bashio
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
# Run zabbix-agent2 in foreground
# zabbix_agent2 --foreground -c /config/zabbix_agent2.conf
exec /etc/services.d/zabbix_agent2/run