77 lines
2.4 KiB
Bash
77 lines
2.4 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
|
|
|
|
# get OS ditro and version
|
|
OS=$(hostnamectl | awk '/Operating System/ {print $3}')
|
|
VM=$(hostnamectl | awk '/Virtualization/ {print $2}')
|
|
if [ ${OS} == 'Ubuntu' ]; then
|
|
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $4}')
|
|
else
|
|
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $5}')
|
|
fi
|
|
|
|
if [ "${VM}" == "vmware" ]; then
|
|
VM="true"
|
|
else
|
|
VM="false"
|
|
fi
|
|
|
|
# checkmk server
|
|
checkmk_server_dns="gauntcheckmk.home.johnhgaunt.com"
|
|
checkmk_server_dns="10.0.10.21"
|
|
checkmk_site="Gaunt"
|
|
|
|
if [ ${OS} == 'Debian' ]; then
|
|
wget -P /tmp/ https://checkmk.johnhgaunt.com/Gaunt/check_mk/agents/check-mk-agent_2.1.0p22-1_all.deb
|
|
dpkg -i /tmp/check-mk-agent_2.1.0p22-1_all.deb
|
|
# update the cache
|
|
apt update
|
|
# install the agent
|
|
apt install -f
|
|
|
|
elif [ ${OS} == 'CentOS' ] || [ "${OS}" == "Rocky" ]; then
|
|
rpm -Uvh https://checkmk.johnhgaunt.com/Gaunt/check_mk/agents/check-mk-agent-2.1.0p22-1.noarch.rpm
|
|
|
|
|
|
cat << EOF >> /etc/firewalld/services/checkmk-agent.xml
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<service>
|
|
<short>checkmk agent</short>
|
|
<description>checkmk agent</description>
|
|
<port protocol="udp" port="161"/>
|
|
<port protocol="tcp" port="6556"/>
|
|
</service>
|
|
EOF
|
|
sleep 5
|
|
firewall-cmd --add-service=checkmk-agent --permanent
|
|
firewall-cmd --reload
|
|
|
|
else
|
|
echo "You are running an unsupported OS"
|
|
echo "Support OSes: Debian/Ubuntu and CentOS/Rocky 9 with EPEL"
|
|
echo "Your OS: ${OS} ${OS_VERSION}"
|
|
exit
|
|
fi
|
|
|
|
# test if not a VM and if so, install the smartctl stuff
|
|
if [ "${VM}" == "false" ]; then
|
|
# hardware inventory script
|
|
wget -O /usr/lib/check_agent/plugins/mk_inventory.linux https://checkmk.johnhgaunt.com/Gaunt/check_mk/agents/plugins/mk_inventory.linux
|
|
chmod +x /usr/lib/check_agent/plugins/mk_inventory.linux
|
|
# Smart script for hard drives
|
|
wget -O /usr/lib/check_agent/plugins/smart https://checkmk.johnhgaunt.com/Gaunt/check_mk/agents/plugins/smart
|
|
chmod +x /usr/lib/check_agent/plugins/smart
|
|
fi
|
|
|
|
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" hostname
|
|
|
|
cmk-agent-ctl --server ${checkmk_server_dns} --site ${checkmk_site} --hostname ${hostname} --user ${checkmk_user} --password ${checkmk_password}
|