120 lines
3.3 KiB
Bash
120 lines
3.3 KiB
Bash
#!/bin/bash
|
|
|
|
# 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
|
|
|
|
set -e
|
|
# set -x
|
|
|
|
url="gauntcheckmk.home.johnhgaunt.com/Gaunt"
|
|
user="automation"
|
|
pass="$1"
|
|
header="Authorization: Bearer ${user} ${pass}"
|
|
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" host
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
if [ -x /usr/bin/dpkg ]; then
|
|
tmpfile=$tmpdir/checkmkagent.deb
|
|
wget -O $tmpfile --header="${header}" "${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 --header="${header}" "${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 "Unknown package system"
|
|
exit 1
|
|
fi
|
|
|
|
rm -rfv $tmpdir
|
|
rm -fv /etc/cmk-update-agent.state
|
|
|
|
echo
|
|
read -p "Agent installed"
|
|
|
|
wget --header=${header} "${url}/check_mk/api/1.0/domain-types/host_config/collections/all" --post-data="{\"hostname\": \"$host\", \"folder\": \"Servers\"}"
|
|
|
|
#curl -v "${url}/check_mk/webapi.py?action=add_host&_username=$user&_secret=$pass" -d "request={\"hostname\": \"$host\", \"folder\": \"Servers\"}"
|
|
|
|
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
|
|
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
|
|
|
|
echo
|
|
read -p "Changes activated"
|
|
|
|
/usr/bin/cmk-agent-ctl register --hostname $host \
|
|
--server gauntcheckmk.home.johnhgaunt.com --site Gaunt \
|
|
--user $user --password $pass \
|
|
--trust-cert
|
|
|
|
echo
|
|
read -p "Agent registered"
|
|
|
|
#/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"
|