From 8788c25fa770711712335ec0e1a8fb80f596cc53 Mon Sep 17 00:00:00 2001 From: moeny-matt Date: Tue, 22 Apr 2025 19:17:37 -0400 Subject: [PATCH] post install zabbix tasks --- .../alpine/tasks/post_install_zabbix.sh | 37 +++++++++++++++++++ .../ubuntu/tasks/post_install_zabbix.sh | 32 ++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 bolt/vm_automation/alpine/tasks/post_install_zabbix.sh create mode 100644 bolt/vm_automation/ubuntu/tasks/post_install_zabbix.sh diff --git a/bolt/vm_automation/alpine/tasks/post_install_zabbix.sh b/bolt/vm_automation/alpine/tasks/post_install_zabbix.sh new file mode 100644 index 0000000..ad326e5 --- /dev/null +++ b/bolt/vm_automation/alpine/tasks/post_install_zabbix.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Task to Install Zabbix on an Alpine VM (alpine::post_install_zabbix) + +# Install zabbix-agent2 +sudo apk add zabbix-agent2 || { + echo '{"status": "failure", "message": "Failed to install zabbix-agent2", "output": "'"$(sudo apk add zabbix-agent2 2>&1)"'"}' + exit 1 +} + +# Configure zabbix-agent2 +sudo 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 || { + echo '{"status": "failure", "message": "Failed to configure zabbix-agent2", "output": "Configuration failed"}' + exit 1 +} + +# Add zabbix-agent2 to default runlevel +sudo rc-update add zabbix-agent2 default || { + echo '{"status": "failure", "message": "Failed to add zabbix-agent2 to default runlevel", "output": "'"$(sudo rc-update add zabbix-agent2 default 2>&1)"'"}' + exit 1 +} + +# Start zabbix-agent2 with debug output +service_start=$(sudo rc-service zabbix-agent2 start 2>&1) +if [ $? -ne 0 ]; then + echo '{"status": "failure", "message": "Failed to start zabbix-agent2", "output": "'"$service_start"'"}' + exit 1 +fi + +# Verify installation with more detailed status check +status_output=$(sudo rc-service zabbix-agent2 status 2>&1) +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 status check failed", "output": "'"$status_output"'"}' + exit 1 +fi \ No newline at end of file diff --git a/bolt/vm_automation/ubuntu/tasks/post_install_zabbix.sh b/bolt/vm_automation/ubuntu/tasks/post_install_zabbix.sh new file mode 100644 index 0000000..f6d90c9 --- /dev/null +++ b/bolt/vm_automation/ubuntu/tasks/post_install_zabbix.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Task to Install Zabbix on Ubuntu (ubuntu::post_install_zabbix) + +# Download the Zabbix release package +sudo wget -O /tmp/zabbix-release.deb https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu22.04_all.deb + +# install the zabbix release package +sudo dpkg -i /tmp/zabbix-release.deb + +# Update the package list +sudo apt update + +# Install the Zabbix agent +sudo apt install -y zabbix-agent2 + +# Configure the Zabbix agent +sudo 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/' -e 's/^LogFileSize=0/LogFileSize=1/' -e 's/^Hostname=Zabbix server/# Hostname=Zabbix server/' -e 's/^# HostnameItem=system\.hostname/HostnameItem=system.hostname/' /etc/zabbix/zabbix_agent2.conf + +# Enable the Zabbix agent +sudo systemctl enable zabbix-agent2 + +# Start the Zabbix agent +sudo systemctl start zabbix-agent2 + +# Verify installation +if sudo systemctl is-active --quiet zabbix-agent2; then + echo "Zabbix agent installed and running successfully" + exit 0 +else + echo "Zabbix agent installation failed or service is not running" + exit 1 +fi \ No newline at end of file