Update script
This commit is contained in:
parent
a5b12337a9
commit
12e46c60c4
@ -1,31 +1,71 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#Install Zabbix Agent
|
# Install Zabbix Agent
|
||||||
|
|
||||||
|
# Define color codes for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
DEFAULT='\033[0m'
|
||||||
|
|
||||||
ROOT_UID=0
|
ROOT_UID=0
|
||||||
|
ZABBIX_SERVER_IP="192.168.1.56"
|
||||||
|
ZABBIX_CONFIG_FILE="/etc/zabbix/zabbix_agentd.conf"
|
||||||
|
|
||||||
if [ "$UID" -ne "$ROOT_UID" ]; then
|
if [ "$UID" -ne "$ROOT_UID" ]; then
|
||||||
echo -e "${RED}Please run script as root user.${DEFAULT}"; exit 1
|
echo -e "${RED}Please run script as root user.${DEFAULT}"; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /etc/zabbix ]; then
|
# Function to check the success of a command
|
||||||
echo "Zabbix Agent Installed"
|
check_success() {
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "${RED}Error: $1 failed.${DEFAULT}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
sed -i 's/Server=.*/Server=192.168.1.56/g' /etc/zabbix/zabbix_agentd.conf
|
# Check if Zabbix Agent is already installed
|
||||||
sed -i 's/ServerActive=.*/ServerActive=192.168.1.56/g' /etc/zabbix/zabbix_agentd.conf
|
if [ -f "$ZABBIX_CONFIG_FILE" ]; then
|
||||||
|
echo -e "${BLUE}Zabbix Agent already installed, resetting config.${DEFAULT}"
|
||||||
|
|
||||||
|
# Update server configuration in Zabbix Agent config file
|
||||||
|
sed -i "s/^Server=.*/Server=$ZABBIX_SERVER_IP/g" $ZABBIX_CONFIG_FILE
|
||||||
|
check_success "Updating Server in config file"
|
||||||
|
|
||||||
|
sed -i "s/^ServerActive=.*/ServerActive=$ZABBIX_SERVER_IP/g" $ZABBIX_CONFIG_FILE
|
||||||
|
check_success "Updating ServerActive in config file"
|
||||||
else
|
else
|
||||||
|
# Download and install Zabbix repository package
|
||||||
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu22.04_all.deb
|
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu22.04_all.deb
|
||||||
|
check_success "Downloading Zabbix repository package"
|
||||||
|
|
||||||
dpkg -i zabbix-release_7.0-2+ubuntu22.04_all.deb
|
dpkg -i zabbix-release_7.0-2+ubuntu22.04_all.deb
|
||||||
|
check_success "Installing Zabbix repository package"
|
||||||
|
|
||||||
|
# Update package lists and install Zabbix Agent
|
||||||
apt update
|
apt update
|
||||||
|
check_success "Updating package lists"
|
||||||
|
|
||||||
apt install zabbix-agent -y
|
apt install zabbix-agent -y
|
||||||
|
check_success "Installing Zabbix Agent"
|
||||||
|
|
||||||
|
# Enable and restart Zabbix Agent service
|
||||||
|
systemctl enable zabbix-agent
|
||||||
|
check_success "Enabling Zabbix Agent service"
|
||||||
|
|
||||||
systemctl restart zabbix-agent
|
systemctl restart zabbix-agent
|
||||||
systemctl enable zabbix-agent
|
check_success "Restarting Zabbix Agent service"
|
||||||
|
|
||||||
sed -i 's/Server=127.0.0.1/Server=192.168.1.56/g' /etc/zabbix/zabbix_agentd.conf
|
# Update server configuration in Zabbix Agent config file
|
||||||
sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.1.56/g' /etc/zabbix/zabbix_agentd.conf
|
sed -i "s/^Server=127.0.0.1/Server=$ZABBIX_SERVER_IP/g" $ZABBIX_CONFIG_FILE
|
||||||
|
check_success "Updating Server in config file"
|
||||||
|
|
||||||
|
sed -i "s/^ServerActive=127.0.0.1/ServerActive=$ZABBIX_SERVER_IP/g" $ZABBIX_CONFIG_FILE
|
||||||
|
check_success "Updating ServerActive in config file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Restart Zabbix Agent service to apply changes
|
||||||
systemctl restart zabbix-agent
|
systemctl restart zabbix-agent
|
||||||
|
check_success "Restarting Zabbix Agent service"
|
||||||
|
|
||||||
echo "Zabbix Agent Installed"
|
echo -e "${GREEN}Zabbix Agent Installed and Configured Successfully${DEFAULT}"
|
||||||
|
Loading…
Reference in New Issue
Block a user