Modify zabbix ServerActive lines - Now monitoring live VMs
This commit is contained in:
parent
8788c25fa7
commit
f86417b22c
@ -15,7 +15,7 @@ fi
|
|||||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "apk add zabbix-agent2"
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "apk add zabbix-agent2"
|
||||||
|
|
||||||
# Configure 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"
|
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=zabbix.moeny.ai,zabbix.moeny.internal/' /etc/zabbix/zabbix_agent2.conf"
|
||||||
|
|
||||||
# Add zabbix-agent2 to default runlevel
|
# Add zabbix-agent2 to default runlevel
|
||||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "rc-update add zabbix-agent2 default"
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "rc-update add zabbix-agent2 default"
|
||||||
|
28
bolt/vm_automation/common/tasks/post_modify_zabbix.sh
Normal file
28
bolt/vm_automation/common/tasks/post_modify_zabbix.sh
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
CONFIG_FILE="/etc/zabbix/zabbix_agent2.conf"
|
||||||
|
SEARCH_STRING="10.44.0.5"
|
||||||
|
REPLACE_STRING="zabbix.moeny.internal"
|
||||||
|
|
||||||
|
# Check if the configuration file exists using sudo
|
||||||
|
if ! sudo test -f "$CONFIG_FILE"; then
|
||||||
|
echo "Error: File $CONFIG_FILE not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the search string exists in the file using sudo
|
||||||
|
if sudo grep -q -F "$SEARCH_STRING" "$CONFIG_FILE"; then
|
||||||
|
# Escape dots in the search string for sed
|
||||||
|
ESCAPED_SEARCH_STRING=$(echo "$SEARCH_STRING" | sed 's/\./\\./g')
|
||||||
|
|
||||||
|
# Replace the string in place using sudo without creating a backup
|
||||||
|
sudo sed -i "s/$ESCAPED_SEARCH_STRING/$REPLACE_STRING/g" "$CONFIG_FILE"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: Failed to replace string."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Replacement done."
|
||||||
|
else
|
||||||
|
echo "No replacement needed. The string '$SEARCH_STRING' was not found."
|
||||||
|
fi
|
@ -23,7 +23,7 @@ sudo apt update
|
|||||||
sudo apt install -y zabbix-agent2
|
sudo apt install -y zabbix-agent2
|
||||||
|
|
||||||
# Configure the Zabbix agent
|
# 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
|
sudo sed -i -e 's/^Server=127\.0\.0\.1/# Server=127.0.0.1/' -e 's/^ServerActive=127\.0\.0\.1/ServerActive=zabbix.moeny.ai,zabbix.moeny.internal/' -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
|
# Enable the Zabbix agent
|
||||||
sudo systemctl enable zabbix-agent2
|
sudo systemctl enable zabbix-agent2
|
||||||
|
Loading…
Reference in New Issue
Block a user