#!/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 # create temp directory for downloaded files DIRECTORY="/tmp/zabbix_install" mkdir ${DIRECTORY} if [ -f /etc/debian_version ]; then apt update apt install -y snmpd curl elif [ -f /etc/redhat-release ]; then yum install -y net-snmp net-snmp-utils firewall-cmd --zone=public --add-service=snmp --permanent firewall-cmd --reload else echo "Unable to determine linux distro" exit fi # download the correct file for the correct OS FILENAME="zabbix_repo.deb" DEBIAN_URL="http://repo.zabbix.com/zabbix/3.4/debian/pool/main/z/zabbix-release/zabbix-release_3.4-1+stretch_all.deb" #CENTOS_URL="http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm" #UBUNTU_URL="https://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bbionic_all.deb" wget --output-document=${DIRECTORY}/${FILENAME} $DEBIAN_URL # install the repo dpkg --install ${DIRECTORY}/${FILENAME} ZABBIX_SERVER="gauntzabbix.home.johnhgaunt.com" # update the cache apt update # install the agent apt install --assume-yes zabbix-agent # 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