From 0e1a4b719cd17fa427e38d4d365f1b6b210c3e37 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Feb 2026 09:50:21 -0300 Subject: [PATCH] Script universal --- zabbix-agent-veloo.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 zabbix-agent-veloo.sh diff --git a/zabbix-agent-veloo.sh b/zabbix-agent-veloo.sh new file mode 100755 index 0000000..fbb3c8d --- /dev/null +++ b/zabbix-agent-veloo.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# 1. Silenciar avisos e preparar ambiente +export LC_ALL=C +ZABBIX_SERVERS="179.97.43.129,192.168.120.231,192.168.120.75,192.168.120.76" +VM_HOSTNAME=$(hostname) +CONFIG_FILE="/etc/zabbix/zabbix_agent2.conf" + +echo "Detectando sistema operacional..." + +if [ -f /etc/debian_version ]; then + # --- Lógica para Debian / Ubuntu --- + echo "Sistema detectado: Debian/Ubuntu" + wget -q https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_latest+debian12_all.deb + dpkg -i zabbix-release_latest+debian12_all.deb > /dev/null 2>&1 + apt-get update -y > /dev/null 2>&1 + apt-get install zabbix-agent2 -y > /dev/null 2>&1 + +elif [ -f /etc/redhat-release ]; then + # --- Lógica para RHEL / CentOS / Rocky / AlmaLinux --- + echo "Sistema detectado: RHEL/CentOS" + rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm > /dev/null 2>&1 + dnf clean all > /dev/null 2>&1 + dnf install zabbix-agent2 -y > /dev/null 2>&1 + +else + echo "Erro: Sistema operacional não suportado por este script automático." + exit 1 +fi + +# 2. Configuração Comum do arquivo zabbix_agent2.conf +if [ -f "$CONFIG_FILE" ]; then + echo "Configurando agente para o host: $VM_HOSTNAME" + + # Backup da config original + cp $CONFIG_FILE "$CONFIG_FILE.bak" + + # Ajusta os parâmetros + sed -i "s|^Server=127.0.0.1|Server=$ZABBIX_SERVERS|" $CONFIG_FILE + sed -i "s|^ServerActive=127.0.0.1|ServerActive=$ZABBIX_SERVERS|" $CONFIG_FILE + sed -i "s|^Hostname=Zabbix server|Hostname=$VM_HOSTNAME|" $CONFIG_FILE + + # 3. Reiniciar e Habilitar o serviço + systemctl restart zabbix-agent2 + systemctl enable zabbix-agent2 + echo "Sucesso: Zabbix Agent 2 configurado e ativo." +else + echo "Erro: Arquivo de configuração não encontrado em $CONFIG_FILE" + exit 1 +fi