added headers for curl

This commit is contained in:
2024-01-15 15:13:27 -05:00
parent 1b90ba7be0
commit dc530614d4

View File

@@ -26,14 +26,15 @@ set -e
url="gauntcheckmk.home.johnhgaunt.com/Gaunt" url="gauntcheckmk.home.johnhgaunt.com/Gaunt"
user="automation" user="automation"
pass="$3" pass="$1"
header="Authorization: Bearer ${user} ${pass}"
read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" host read -e -p "Enter Hostname: " -i "$(cat /etc/hostname)" host
tmpdir=$(mktemp -d) tmpdir=$(mktemp -d)
if [ -x /usr/bin/dpkg ]; then if [ -x /usr/bin/dpkg ]; then
tmpfile=$tmpdir/checkmkagent.deb tmpfile=$tmpdir/checkmkagent.deb
wget -O $tmpfile "$url/check_mk/api/1.0/domain-types/agent/actions/download/invoke?os_type=linux_deb" wget -O $tmpfile -H "${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 if dpkg -l check-mk-agent > /dev/null; then
dpkg -P check-mk-agent dpkg -P check-mk-agent
fi fi
@@ -41,7 +42,7 @@ if [ -x /usr/bin/dpkg ]; then
dpkg -i $tmpfile dpkg -i $tmpfile
elif [ -x /usr/bin/rpm -o -x /bin/rpm ]; then elif [ -x /usr/bin/rpm -o -x /bin/rpm ]; then
tmpfile=$tmpdir/checkmkagent.rpm tmpfile=$tmpdir/checkmkagent.rpm
wget -O $tmpfile "$url/check_mk/api/1.0/domain-types/agent/actions/download/invoke?os_type=linux_rpm" wget -O $tmpfile -H "${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 if rpm -q check-mk-agent > /dev/null; then
rpm -e check-mk-agent rpm -e check-mk-agent
fi fi
@@ -62,12 +63,12 @@ rm -fv /etc/cmk-update-agent.state
echo echo
read -p "Agent installed" read -p "Agent installed"
curl -v "$url/check_mk/webapi.py?action=add_host&_username=$user&_secret=$pass" -d "request={\"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 echo
read -p "Host created" read -p "Host created"
curl -v "$url/check_mk/webapi.py?action=activate_changes&_username=$user&_secret=$pass" 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
@@ -82,20 +83,28 @@ fi
echo echo
read -p "Changes activated" read -p "Changes activated"
/usr/bin/cmk-update-agent register -v -U $user -S $pass -H $host /usr/bin/cmk-agent-ctl register --hostname $host \
--server gauntcheckmk.home.johnhgaunt.com --site Gaunt \
--user $user --password $pass \
--trust-cert
echo echo
read -p "Agent Updater registered" read -p "Agent registered"
curl -v "$url/check_mk/webapi.py?action=bake_agents&_username=$user&_secret=$pass" #/usr/bin/cmk-update-agent register -v -U $user -S $pass -H $host
echo #echo
read -p "Agents baked" #read -p "Agent Updater registered"
/usr/bin/cmk-update-agent -v #curl -v "$url/check_mk/webapi.py?action=bake_agents&_username=$user&_secret=$pass"
echo #echo
read -p "Agent updated" #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\"}" curl -v "$url/check_mk/webapi.py?action=discover_services&_username=$user&_secret=$pass" -d "request={\"hostname\": \"$host\"}"