From dc530614d4ee05935290683e731d9c9798e97293 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 15 Jan 2024 15:13:27 -0500 Subject: [PATCH] added headers for curl --- checkmk.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/checkmk.sh b/checkmk.sh index 608e190..6c81b50 100644 --- a/checkmk.sh +++ b/checkmk.sh @@ -26,14 +26,15 @@ set -e url="gauntcheckmk.home.johnhgaunt.com/Gaunt" user="automation" -pass="$3" +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 "$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 dpkg -P check-mk-agent fi @@ -41,7 +42,7 @@ if [ -x /usr/bin/dpkg ]; then 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" + 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 rpm -e check-mk-agent fi @@ -62,12 +63,12 @@ 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\": \"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" +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 @@ -82,20 +83,28 @@ fi echo 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 -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 -read -p "Agents baked" +#echo +#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 -read -p "Agent updated" +#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\"}"