Last active
July 2, 2024 18:01
-
-
Save jp1337/f55352de920b75cccbe6e50c6ad4b4cd to your computer and use it in GitHub Desktop.
Check_MK Agent Update Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this script works with the latest version of Check_MK. Tested using Raw 1.6.0b7 on Debian and RedHat. | |
# be sure that curl is installed! | |
# apt install -y curl | |
# yum install -y curl | |
# use the script with these steps: | |
# curl -Os -H 'Cache-Control: no-cache' https://gist.githubusercontent.com/jpylypiw/f55352de920b75cccbe6e50c6ad4b4cd/raw/update_check_mk_agent.sh | |
# bash update_check_mk_agent.sh -h myservername -i/s myinstance/mysite [-p http/https] [-d /usr/lib/check_mk_agent/plugins] | |
# Example: | |
# (sudo) bash update_check_mk_agent.sh -h test.example.com -s test -p http -d /usr/local/lib/check_mk_agent/plugins | |
# (sudo) bash update_check_mk_agent.sh -h test.example.com -i test | |
CHECK_MK_HOST="myservername" | |
CHECK_MK_INSTANCE="myinstance" | |
CHECK_MK_PROTOCOL="https" | |
CHECK_MK_PLUGIN_DIR="/usr/lib/check_mk_agent/plugins" | |
if [ "$EUID" -ne 0 ]; then | |
echo "This script must be run as root. Try again using sudo or log in as root user." | |
exit 1 | |
fi | |
while getopts "h:i:p:d:s:" opt; do | |
case ${opt} in | |
h) | |
CHECK_MK_HOST=$OPTARG | |
;; | |
i) | |
CHECK_MK_INSTANCE=$OPTARG | |
;; | |
s) | |
CHECK_MK_INSTANCE=$OPTARG | |
;; | |
p) | |
CHECK_MK_PROTOCOL=$OPTARG | |
;; | |
d) | |
CHECK_MK_PLUGIN_DIR=$OPTARG | |
;; | |
*) | |
echo "Usage: cmd -h -i [-p] [-d]" | |
;; | |
esac | |
done | |
OS= | |
if grep 'Debian' /etc/issue >/dev/null 2>&1; then | |
OS=debian | |
fi | |
if grep 'Debian' /etc/os-release >/dev/null 2>&1; then | |
OS=debian | |
fi | |
if grep 'Ubuntu' /etc/issue >/dev/null 2>&1; then | |
OS=debian | |
fi | |
if grep 'ubuntu' /etc/os-release >/dev/null 2>&1; then | |
OS=debian | |
fi | |
if grep 'CentOS' /etc/issue >/dev/null 2>&1; then | |
OS=rhel | |
fi | |
if grep 'CentOS' /etc/os-release >/dev/null 2>&1; then | |
OS=rhel | |
fi | |
if grep 'Red' /etc/issue >/dev/null 2>&1; then | |
OS=rhel | |
fi | |
if [ ! $OS ]; then | |
echo "Could not detect OS" | |
exit 1 | |
fi | |
echo "OS: $OS" | |
if [ "$OS" == "debian" ]; then | |
echo "Downloading Agent Package" | |
FILENAME=$(curl -s "$CHECK_MK_PROTOCOL"://"$CHECK_MK_HOST"/"$CHECK_MK_INSTANCE"/check_mk/agents/ | grep -oP "check-mk-agent\w[a-z\-\_0-9\.]+" | head -1) | |
URL=$CHECK_MK_PROTOCOL"://$CHECK_MK_HOST/$CHECK_MK_INSTANCE/check_mk/agents/"$FILENAME | |
curl -Os "$URL" | |
dpkg -i "$FILENAME" | |
rm "$FILENAME" | |
cd "$CHECK_MK_PLUGIN_DIR" || exit 1 | |
echo "updating plugins" | |
for filename in $(find . -type f | cut -c 3-); do | |
echo "downloading $filename from check_mk server" | |
curl -sO "$CHECK_MK_PROTOCOL"://"$CHECK_MK_HOST"/"$CHECK_MK_INSTANCE"/check_mk/agents/plugins/"$filename" | |
chmod +x "$filename" | |
done | |
fi | |
if [ "$OS" == "rhel" ]; then | |
echo "Downloading Agent Package" | |
FILENAME=$(curl -s "$CHECK_MK_PROTOCOL"://"$CHECK_MK_HOST"/"$CHECK_MK_INSTANCE"/check_mk/agents/ | grep -oP "check-mk-agent\-\w[a-z\-0-9\.]+" | head -1) | |
URL=$CHECK_MK_PROTOCOL"://$CHECK_MK_HOST/$CHECK_MK_INSTANCE/check_mk/agents/"$FILENAME | |
curl -Os "$URL" | |
rpm --install --quiet --replacefiles "$FILENAME" | |
rm "$FILENAME" | |
cd "$CHECK_MK_PLUGIN_DIR" || exit 1 | |
echo "updating plugins" | |
for filename in $(find . -type f | cut -c 3-); do | |
echo "downloading $filename from check_mk server" | |
curl -sO "$CHECK_MK_PROTOCOL"://"$CHECK_MK_HOST"/"$CHECK_MK_INSTANCE"/check_mk/agents/plugins/"$filename" | |
chmod +x "$filename" | |
done | |
fi | |
echo 'Complete' |
Hi there! I changed the script so you won't have any issues any more.
You need to have the latest version of Check_MK installed to run the script. The latest version does not need xinetd or gdebi anymore.
For a command line arguments example look at the comment at the first lines.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am using this script for a Red Hat distro, and it keeps erroring out with
Any suggestions as to why this is the case?