Files
homelab-scripts/zabbix_agent.sh
2018-12-18 15:01:08 -05:00

57 lines
1.8 KiB
Bash

#!/bin/bash
# installs the zabbix agent and configures it
# make sure we are running as sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
# zabbix server
ZABBIX_SERVER="gauntzabbix.home.johnhgaunt.com"
if [ -f /etc/debian_version ]; then
# Install the repository configuration package. This package contains apt (software package manager) configuration files.
wget https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb
dpkg -i zabbix-release_4.0-2+stretch_all.deb
# update the cache
apt update
# install the agent
apt install -y zabbix-agent
elif [ -f /etc/redhat-release ]; then
# Install the repository configuration package. This package contains yum (software package manager) configuration files.
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
# install the zabbix agent
yum install -y zabbix-agent
cat << EOF >> /etc/firewalld/services/zabbix-agent.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>zabbix agent</short>
<description>zabbix agent</description>
<port protocol="tcp" port="10050"/>
<port protocol="udp" port="10050"/>
</service>
EOF
sleep 5
firewall-cmd --add-service=zabbix-agent --permanent
firewall-cmd --reload
else
echo "Unable to determine linux distro"
exit
fi
# ask for the hostname
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" hostname
sed --in-place "s/^Hostname=Zabbix\ server/Hostname=${hostname}/" /etc/zabbix/zabbix_agentd.conf
sed --in-place "s/^Server=127.0.0.1/Server=${ZABBIX_SERVER}/" /etc/zabbix/zabbix_agentd.conf
sed --in-place "s/^ServerActive=127.0.0.1/ServerActive=${ZABBIX_SERVER}/" /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
systemctl enable zabbix-agent