Some more logging, now hiding original command ouputs
This commit is contained in:
parent
50527c5366
commit
da1f64c4c2
@ -46,51 +46,71 @@ fi
|
|||||||
# Download and install the Zabbix agent
|
# Download and install the Zabbix agent
|
||||||
if [[ "$OS" == *"CentOS"* ]]; then
|
if [[ "$OS" == *"CentOS"* ]]; then
|
||||||
if [[ "$VERSION" == "6"* ]]; then
|
if [[ "$VERSION" == "6"* ]]; then
|
||||||
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/6/x86_64/zabbix-release-6.4-1.el6.noarch.rpm | tee -a "$LOG_FILE"
|
_info "Downloading and installing Zabbix repositories ..."
|
||||||
yum clean all | tee -a "$LOG_FILE"
|
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/6/x86_64/zabbix-release-6.4-1.el6.noarch.rpm &>> "$LOG_FILE"
|
||||||
yum install zabbix-agent2 zabbix-agent2-plugin-* -y | tee -a "$LOG_FILE"
|
yum clean all &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix Agent 2 ..."
|
||||||
|
yum install zabbix-agent2 zabbix-agent2-plugin-* -y &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "7"* ]]; then
|
elif [[ "$VERSION" == "7"* ]]; then
|
||||||
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm | tee -a "$LOG_FILE"
|
_info "Downloading and installing Zabbix repositories ..."
|
||||||
yum clean all | tee -a "$LOG_FILE"
|
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm &>> "$LOG_FILE"
|
||||||
yum install zabbix-agent2 zabbix-agent2-plugin-* -y | tee -a "$LOG_FILE"
|
yum clean all &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix Agent 2 ..."
|
||||||
|
yum install zabbix-agent2 zabbix-agent2-plugin-* -y &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "8"* ]]; then
|
elif [[ "$VERSION" == "8"* ]]; then
|
||||||
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/8/x86_64/zabbix-release-6.4-1.el8.noarch.rpm | tee -a "$LOG_FILE"
|
_info "Downloading and installing Zabbix repositories ..."
|
||||||
dnf clean all | tee -a "$LOG_FILE"
|
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/8/x86_64/zabbix-release-6.4-1.el8.noarch.rpm &>> "$LOG_FILE"
|
||||||
dnf install zabbix-agent2 zabbix-agent2-plugin-* -y | tee -a "$LOG_FILE"
|
dnf clean all &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix Agent 2 ..."
|
||||||
|
dnf install zabbix-agent2 zabbix-agent2-plugin-* -y &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "9"* ]]; then
|
elif [[ "$VERSION" == "9"* ]]; then
|
||||||
sed -i '/\[epel\]/a excludepkgs=Zabbix*' /etc/yum.repos.d/epel.repo | tee -a "$LOG_FILE"
|
_info "Downloading and installing Zabbix repositories ..."
|
||||||
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm | tee -a "$LOG_FILE"
|
sed -i '/\[epel\]/a excludepkgs=Zabbix*' /etc/yum.repos.d/epel.repo &>> "$LOG_FILE"
|
||||||
dnf clean all | tee -a "$LOG_FILE"
|
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm &>> "$LOG_FILE"
|
||||||
dnf install zabbix-agent2 zabbix-agent2-plugin-* -y | tee -a "$LOG_FILE"
|
dnf clean all &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix Agent 2 ..."
|
||||||
|
dnf install zabbix-agent2 zabbix-agent2-plugin-* -y &>> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
_error "Your CentOS version is not supported."
|
_error "Your CentOS version is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [[ "$OS" == *"Debian"* ]]; then
|
elif [[ "$OS" == *"Debian"* ]]; then
|
||||||
if [[ "$VERSION" == "9"* ]]; then
|
if [[ "$VERSION" == "9"* ]]; then
|
||||||
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian9_all.deb | tee -a "$LOG_FILE"
|
_info "Downloading Zabbix repositories package ..."
|
||||||
dpkg -i zabbix-release_6.4-1+debian9_all.deb | tee -a "$LOG_FILE"
|
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian9_all.deb &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix repositories package ..."
|
||||||
|
dpkg -i zabbix-release_6.4-1+debian9_all.deb &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "10"* ]]; then
|
elif [[ "$VERSION" == "10"* ]]; then
|
||||||
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian10_all.deb | tee -a "$LOG_FILE"
|
_info "Downloading Zabbix repositories package ..."
|
||||||
dpkg -i zabbix-release_6.4-1+debian10_all.deb | tee -a "$LOG_FILE"
|
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian10_all.deb &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix repositories package ..."
|
||||||
|
dpkg -i zabbix-release_6.4-1+debian10_all.deb &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "11"* ]]; then
|
elif [[ "$VERSION" == "11"* ]]; then
|
||||||
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb | tee -a "$LOG_FILE"
|
_info "Downloading Zabbix repositories package ..."
|
||||||
dpkg -i zabbix-release_6.4-1+debian11_all.deb | tee -a "$LOG_FILE"
|
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix repositories package ..."
|
||||||
|
dpkg -i zabbix-release_6.4-1+debian11_all.deb &>> "$LOG_FILE"
|
||||||
elif [[ "$VERSION" == "12"* ]]; then
|
elif [[ "$VERSION" == "12"* ]]; then
|
||||||
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb | tee -a "$LOG_FILE"
|
_info "Downloading Zabbix repositories package ..."
|
||||||
dpkg -i zabbix-release_6.4-1+debian12_all.deb | tee -a "$LOG_FILE"
|
wget https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix repositories package ..."
|
||||||
|
dpkg -i zabbix-release_6.4-1+debian12_all.deb &>> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
_error "Your Debian version is not supported."
|
_error "Your Debian version is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
apt update | tee -a "$LOG_FILE"
|
_info "Running 'apt update' ..."
|
||||||
apt install zabbix-agent2 zabbix-agent2-plugin-* -y | tee -a "$LOG_FILE"
|
apt update &>> "$LOG_FILE"
|
||||||
|
_info "Installing Zabbix Agent 2 ..."
|
||||||
|
apt install zabbix-agent2 zabbix-agent2-plugin-* -y &>> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
_error "Your operating system is not supported."
|
_error "Your operating system is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_info "Installation done!"
|
||||||
|
|
||||||
# Get the IP address and hostname
|
# Get the IP address and hostname
|
||||||
IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/')
|
IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/')
|
||||||
HOST=$(hostname | tr '[:lower:]' '[:upper:]')
|
HOST=$(hostname | tr '[:lower:]' '[:upper:]')
|
||||||
@ -98,6 +118,8 @@ HOST=$(hostname | tr '[:lower:]' '[:upper:]')
|
|||||||
_info "Detected IP: $IP"
|
_info "Detected IP: $IP"
|
||||||
_info "Detected Hostname: $HOST"
|
_info "Detected Hostname: $HOST"
|
||||||
|
|
||||||
|
_info "Updating Zabbix Agent 2 configuration ..."
|
||||||
|
|
||||||
# Update the Zabbix agent configuration
|
# Update the Zabbix agent configuration
|
||||||
sed -i "s/# SourceIP=/SourceIP=$IP/g" /etc/zabbix/zabbix_agent2.conf
|
sed -i "s/# SourceIP=/SourceIP=$IP/g" /etc/zabbix/zabbix_agent2.conf
|
||||||
sed -i "s/Server=127.0.0.1/Server=$ZABBIX_SERVER_IP/g" /etc/zabbix/zabbix_agent2.conf
|
sed -i "s/Server=127.0.0.1/Server=$ZABBIX_SERVER_IP/g" /etc/zabbix/zabbix_agent2.conf
|
||||||
@ -105,6 +127,9 @@ sed -i "s/# ListenIP=0.0.0.0/ListenIP=$IP/g" /etc/zabbix/zabbix_agent2.conf
|
|||||||
sed -i "s/ServerActive=127.0.0.1/ServerActive=$ZABBIX_SERVER_IP/g" /etc/zabbix/zabbix_agent2.conf
|
sed -i "s/ServerActive=127.0.0.1/ServerActive=$ZABBIX_SERVER_IP/g" /etc/zabbix/zabbix_agent2.conf
|
||||||
sed -i "s/Hostname=Zabbix server/Hostname=$HOST/g" /etc/zabbix/zabbix_agent2.conf
|
sed -i "s/Hostname=Zabbix server/Hostname=$HOST/g" /etc/zabbix/zabbix_agent2.conf
|
||||||
|
|
||||||
|
_info "Updating done!"
|
||||||
|
_info "Writing additional configuration file for Proxmox Container support"
|
||||||
|
|
||||||
# Create the zabbix_container.conf file
|
# Create the zabbix_container.conf file
|
||||||
cat << EOF > /etc/zabbix/zabbix_agent2.d/zabbix_container.conf
|
cat << EOF > /etc/zabbix/zabbix_agent2.d/zabbix_container.conf
|
||||||
UserParameter=ct.memory.size[*],free -b | awk 'NR==2 {total=\$2; used=(\$3+\$5); pused=((\$3+\$5)*100/\$2); free=\$4; pfree=(\$4*100/\$2); shared=\$5; buffers=\$6; cached=\$7; available=\$8; pavailable=(\$8*100/\$2); if("\$1" == "") {printf("%.0f", total )} else {printf("%.0f", \$1 "" )} }'
|
UserParameter=ct.memory.size[*],free -b | awk 'NR==2 {total=\$2; used=(\$3+\$5); pused=((\$3+\$5)*100/\$2); free=\$4; pfree=(\$4*100/\$2); shared=\$5; buffers=\$6; cached=\$7; available=\$8; pavailable=(\$8*100/\$2); if("\$1" == "") {printf("%.0f", total )} else {printf("%.0f", \$1 "" )} }'
|
||||||
@ -113,27 +138,29 @@ UserParameter=ct.cpu.load[*],cut -d" " -f1-3 /proc/loadavg | awk -F'[, ]+' '{avg
|
|||||||
UserParameter=ct.uptime,cut -d"." -f1 /proc/uptime
|
UserParameter=ct.uptime,cut -d"." -f1 /proc/uptime
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
_info "Restarting and enabling service ..."
|
||||||
|
|
||||||
# Restart and enable service
|
# Restart and enable service
|
||||||
if [[ $OS == *"CentOS"* ]]; then
|
if [[ $OS == *"CentOS"* ]]; then
|
||||||
if [[ $VERSION == "6"* ]]; then
|
if [[ $VERSION == "6"* ]]; then
|
||||||
service zabbix-agent restart | tee -a "$LOG_FILE"
|
service zabbix-agent restart &>> "$LOG_FILE"
|
||||||
chkconfig --level 35 zabbix-agent on | tee -a "$LOG_FILE"
|
chkconfig --level 35 zabbix-agent on &>> "$LOG_FILE"
|
||||||
elif [[ $VERSION == "7"* ]]; then
|
elif [[ $VERSION == "7"* ]]; then
|
||||||
systemctl restart zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl restart zabbix-agent2 &>> "$LOG_FILE"
|
||||||
systemctl enable zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl enable zabbix-agent2 &>> "$LOG_FILE"
|
||||||
elif [[ $VERSION == "8"* ]]; then
|
elif [[ $VERSION == "8"* ]]; then
|
||||||
systemctl restart zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl restart zabbix-agent2 &>> "$LOG_FILE"
|
||||||
systemctl enable zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl enable zabbix-agent2 &>> "$LOG_FILE"
|
||||||
elif [[ $VERSION == "9"* ]]; then
|
elif [[ $VERSION == "9"* ]]; then
|
||||||
systemctl restart zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl restart zabbix-agent2 &>> "$LOG_FILE"
|
||||||
systemctl enable zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl enable zabbix-agent2 &>> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
_error "Your CentOS version is not supported."
|
_error "Your CentOS version is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [[ $OS == *"Debian"* ]]; then
|
elif [[ $OS == *"Debian"* ]]; then
|
||||||
systemctl restart zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl restart zabbix-agent2 &>> "$LOG_FILE"
|
||||||
systemctl enable zabbix-agent2 | tee -a "$LOG_FILE"
|
systemctl enable zabbix-agent2 &>> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
_error "Your operating system is not supported."
|
_error "Your operating system is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user