Update 'checkmk.sh'
This commit is contained in:
106
checkmk.sh
106
checkmk.sh
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
# installs the zabbix agent and configures it
|
|
||||||
|
|
||||||
# make sure we are running as sudo
|
# make sure we are running as sudo
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
@@ -24,43 +23,54 @@ else
|
|||||||
VM="false"
|
VM="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# checkmk server
|
set -e
|
||||||
checkmk_server_dns="gauntcheckmk.home.johnhgaunt.com"
|
# set -x
|
||||||
checkmk_server_dns="10.0.10.21"
|
|
||||||
checkmk_site="Gaunt"
|
|
||||||
|
|
||||||
if [ ${OS} == 'Debian' ]; then
|
url="gauntcheckmk.home.johnhgaunt.com/Gaunt"
|
||||||
wget -P /tmp/ https://checkmk.johnhgaunt.com/Gaunt/check_mk/agents/check-mk-agent_2.1.0p22-1_all.deb
|
user="automation"
|
||||||
dpkg -i /tmp/check-mk-agent_2.1.0p22-1_all.deb
|
pass="$3"
|
||||||
# update the cache
|
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" host
|
||||||
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
|
|
||||||
|
|
||||||
|
tmpdir=$(mktemp -d)
|
||||||
cat << EOF >> /etc/firewalld/services/checkmk-agent.xml
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
if [ -x /usr/bin/dpkg ]; then
|
||||||
<service>
|
tmpfile=$tmpdir/checkmkagent.deb
|
||||||
<short>checkmk agent</short>
|
wget -O $tmpfile "$url/check_mk/api/1.0/domain-types/agent/actions/download/invoke?os_type=linux_deb"
|
||||||
<description>checkmk agent</description>
|
if dpkg -l check-mk-agent > /dev/null; then
|
||||||
<port protocol="udp" port="161"/>
|
dpkg -P check-mk-agent
|
||||||
<port protocol="tcp" port="6556"/>
|
fi
|
||||||
</service>
|
apt-get install xinetd curl
|
||||||
EOF
|
dpkg -i $tmpfile
|
||||||
sleep 5
|
elif [ -x /usr/bin/rpm -o -x /bin/rpm ]; then
|
||||||
firewall-cmd --add-service=checkmk-agent --permanent
|
tmpfile=$tmpdir/checkmkagent.rpm
|
||||||
firewall-cmd --reload
|
wget -O $tmpfile "$url/check_mk/api/1.0/domain-types/agent/actions/download/invoke?os_type=linux_rpm"
|
||||||
|
if rpm -q check-mk-agent > /dev/null; then
|
||||||
|
rpm -e check-mk-agent
|
||||||
|
fi
|
||||||
|
if [ -x /usr/bin/zypper ]; then
|
||||||
|
zypper install xinetd curl
|
||||||
|
elif [ -x /usr/bin/yum ]; then
|
||||||
|
yum install xinetd curl
|
||||||
|
fi
|
||||||
|
rpm -i $tmpfile
|
||||||
else
|
else
|
||||||
echo "You are running an unsupported OS"
|
echo "Unknown package system"
|
||||||
echo "Support OSes: Debian/Ubuntu and CentOS/Rocky 9 with EPEL"
|
exit 1
|
||||||
echo "Your OS: ${OS} ${OS_VERSION}"
|
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -rfv $tmpdir
|
||||||
|
rm -fv /etc/cmk-update-agent.state
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Agent installed"
|
||||||
|
|
||||||
|
curl -v "$url/check_mk/webapi.py?action=add_host&_username=$user&_secret=$pass" -d "request={\"hostname\": \"$host\", \"folder\": \"main\"}"
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Host created"
|
||||||
|
|
||||||
|
curl -v "$url/check_mk/webapi.py?action=activate_changes&_username=$user&_secret=$pass"
|
||||||
|
|
||||||
# test if not a VM and if so, install the smartctl stuff
|
# test if not a VM and if so, install the smartctl stuff
|
||||||
if [ "${VM}" == "false" ]; then
|
if [ "${VM}" == "false" ]; then
|
||||||
# hardware inventory script
|
# hardware inventory script
|
||||||
@@ -71,6 +81,30 @@ if [ "${VM}" == "false" ]; then
|
|||||||
chmod +x /usr/lib/check_agent/plugins/smart
|
chmod +x /usr/lib/check_agent/plugins/smart
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" hostname
|
echo
|
||||||
|
read -p "Changes activated"
|
||||||
|
|
||||||
cmk-agent-ctl --server ${checkmk_server_dns} --site ${checkmk_site} --hostname ${hostname} --user ${checkmk_user} --password ${checkmk_password}
|
/usr/bin/cmk-update-agent register -v -U $user -S $pass -H $host
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Agent Updater registered"
|
||||||
|
|
||||||
|
curl -v "$url/check_mk/webapi.py?action=bake_agents&_username=$user&_secret=$pass"
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Agents baked"
|
||||||
|
|
||||||
|
/usr/bin/cmk-update-agent -v
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Agent updated"
|
||||||
|
|
||||||
|
curl -v "$url/check_mk/webapi.py?action=discover_services&_username=$user&_secret=$pass" -d "request={\"hostname\": \"$host\"}"
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Host services discovered"
|
||||||
|
|
||||||
|
curl -v "$url/check_mk/webapi.py?action=activate_changes&_username=$user&_secret=$pass"
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Changes activated"
|
||||||
|
|||||||
Reference in New Issue
Block a user