34 lines
1.3 KiB
Bash
34 lines
1.3 KiB
Bash
#!/bin/bash
|
|
# Task to Install Zabbix on an Alpine VM (alpine::install_zabbix)
|
|
|
|
# Input Variables
|
|
INSTALL_ZABBIX="${PT_install_zabbix_bool}"
|
|
STAGING_IP="${PT_staging_ip}"
|
|
|
|
# Check if Zabbix installation is requested
|
|
if [ "$INSTALL_ZABBIX" != "true" ]; then
|
|
echo '{"status": "skipped", "message": "Zabbix installation not requested, skipping..."}'
|
|
exit 0
|
|
fi
|
|
|
|
# Install zabbix-agent2
|
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "apk add zabbix-agent2"
|
|
|
|
# Configure zabbix-agent2
|
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i -e 's/^Server=127\.0\.0\.1/# Server=127.0.0.1/' -e 's/^ServerActive=127\.0\.0\.1/ServerActive=10.44.0.5,zabbix.moeny.ai/' /etc/zabbix/zabbix_agent2.conf"
|
|
|
|
# Add zabbix-agent2 to default runlevel
|
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "rc-update add zabbix-agent2 default"
|
|
|
|
# Start zabbix-agent2
|
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "rc-service zabbix-agent2 start"
|
|
|
|
# Verify installation
|
|
status_output=$(ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "rc-service zabbix-agent2 status")
|
|
if echo "$status_output" | grep -q "status: started"; then
|
|
echo '{"status": "success", "message": "Zabbix agent installed and running", "output": "'"$status_output"'"}'
|
|
exit 0
|
|
else
|
|
echo '{"status": "failure", "message": "Zabbix agent installation failed", "output": "'"$status_output"'"}'
|
|
exit 1
|
|
fi |