Update 'checkmk.sh'
This commit is contained in:
106
checkmk.sh
106
checkmk.sh
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# installs the zabbix agent and configures it
|
||||
#!/bin/bash
|
||||
|
||||
# make sure we are running as sudo
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
@@ -24,43 +23,54 @@ else
|
||||
VM="false"
|
||||
fi
|
||||
|
||||
# checkmk server
|
||||
checkmk_server_dns="gauntcheckmk.home.johnhgaunt.com"
|
||||
checkmk_server_dns="10.0.10.21"
|
||||
checkmk_site="Gaunt"
|
||||
set -e
|
||||
# set -x
|
||||
|
||||
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
|
||||
url="gauntcheckmk.home.johnhgaunt.com/Gaunt"
|
||||
user="automation"
|
||||
pass="$3"
|
||||
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" host
|
||||
|
||||
|
||||
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
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
|
||||
if [ -x /usr/bin/dpkg ]; then
|
||||
tmpfile=$tmpdir/checkmkagent.deb
|
||||
wget -O $tmpfile "$url/check_mk/api/1.0/domain-types/agent/actions/download/invoke?os_type=linux_deb"
|
||||
if dpkg -l check-mk-agent > /dev/null; then
|
||||
dpkg -P check-mk-agent
|
||||
fi
|
||||
apt-get install xinetd curl
|
||||
dpkg -i $tmpfile
|
||||
elif [ -x /usr/bin/rpm -o -x /bin/rpm ]; then
|
||||
tmpfile=$tmpdir/checkmkagent.rpm
|
||||
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
|
||||
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
|
||||
echo "Unknown package system"
|
||||
exit 1
|
||||
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
|
||||
if [ "${VM}" == "false" ]; then
|
||||
# hardware inventory script
|
||||
@@ -71,6 +81,30 @@ if [ "${VM}" == "false" ]; then
|
||||
chmod +x /usr/lib/check_agent/plugins/smart
|
||||
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