diff --git a/script/monitor/README.md b/script/monitor/README.md new file mode 100644 index 0000000..55a46d4 --- /dev/null +++ b/script/monitor/README.md @@ -0,0 +1,126 @@ + +How to setup a monitoring dashboard +=================================== + +Inspired by: https://pimylifeup.com/ubuntu-chromium-kiosk/ + +Steps +----- + + + +### 1.) Install Ubuntu Server (no desktop) on your computer than set hostname and timezone. + +```sh +hostnamectl set-hostname check.local +timedatectl set-timezone Europe/Berlin +``` + + + +### 2.) Install minimal GUI and Tools. + +```sh +apt install ubuntu-desktop-minimal +apt install language-pack-gnome-de +apt install xdotool +apt install dbus-x11 +``` + + + +### 3.) Create a kiosk user with home-directory. + +```sh +useradd -m kiosk +``` + +and disable Welocme-Screen +```sh +echo "yes" > /home/kiosk/.config/gnome-initial-setup-done +``` + + + +### 4.) Edit following file `nano /etc/gdm3/custom.conf` to turn of wayland and turn on autologin for user 'kiosk'. + +``` +[daemon] +# Uncomment the line below to force the login screen to use Xorg +#WaylandEnable=false + +WaylandEnable=false + +# Enabling automatic login +# AutomaticLoginEnable = true +# AutomaticLogin = user1 + +AutomaticLoginEnable = true +AutomaticLogin = kiosk +``` + + + +### 5.) Configure GUI of user kiosk to prevent monitor from sleeping + +```sh +#gsettings list-recursively + +# Does not work +#sudo -u kiosk gsettings set org.gnome.desktop.session idle-delay 0 + +# Set idle-delay from "uint32 300" to "uint32 0", needs 'apt install dbus-x11' +# You can check the value in "GUI-Session of kiosk -> Settings -> Power" +sudo -u kiosk dbus-launch dconf write /org/gnome/desktop/session/idle-delay "uint32 0" +``` + + + +### 6.) Create custom service to start firefox loading the page. + +Therefore create a file `/etc/systemd/system/kiosk.service` with this content: + +``` +[Unit] +Description=Firefox Kiosk +Wants=graphical.target +After=graphical.target + +[Service] +Environment=DISPLAY=:0 +# Set firefox language, needs 'apt install language-pack-gnome-de' +Environment=LANG=de_DE.UTF-8 +Type=simple +# Always a fresh firefox ('-' allow error if common does not exist) +ExecStartPre=-/usr/bin/rm -r /home/kiosk/snap/firefox/common +# Move Mouse (should also work on small screens), needs 'apt install dbus-x11' +ExecStartPre=/usr/bin/xdotool mousemove 4096 2160 +# See: https://wiki.mozilla.org/Firefox/CommandLineOptions (just -kiosk URL => Start-Assistant, so use -url too) +ExecStart=/usr/bin/firefox -fullscreen -kiosk -url http://monitor.example.net/check.html +Restart=always +RestartSec=30 +User=kiosk +Group=kiosk + +[Install] +WantedBy=graphical.target +``` + + + +### 7.) Enable the service and reboot + +```sh +systemctl enable kiosk +reboot +``` + + + +Troubleshouting +--------------- + +``` +systemctl disable pd-mapper.service +apt purge cloud-init -y && apt autoremove --purge -y +``` diff --git a/script/monitor/check.html b/script/monitor/check.html new file mode 100644 index 0000000..ee6fe1e --- /dev/null +++ b/script/monitor/check.html @@ -0,0 +1,204 @@ + + + +Monitoring Dashboard + + + + + +
+
+
Loading...
+
+
+ + + + + diff --git a/script/monitor/check.sh b/script/monitor/check.sh new file mode 100755 index 0000000..1787e02 --- /dev/null +++ b/script/monitor/check.sh @@ -0,0 +1,86 @@ +#!/bin/bash + + + +function doChecks(){ + local readonly _TMPDIR="${1:?"doChecks(): Missing parameter TMPDIR:"}" + local readonly _COLOR="${2:-"monocrom"}" + + local _DATETIME=$(date +%H-%M-%S) + + mkdir -p ${_TMPDIR} + rm ${_TMPDIR}/* > /dev/null 2>&1 + + for check in /monitoring/checks/*.on + do + local _CHECK_FILENAME="${check##*/}" + echo -n "${_CHECK_FILENAME%%.on}?" > "${_TMPDIR}/${_CHECK_FILENAME}" + timeout -k 10s 20s bash ${check} >> "${_TMPDIR}/${_CHECK_FILENAME}" 2> /dev/null || echo "TIMEOUT#Timeout" >> "${_TMPDIR}/${_CHECK_FILENAME}" & + done + wait + + local _FAILED=0 + echo "CHECK?RESULT[#MESSAGE]:" + echo "-----------------------" + for resultFile in ${_TMPDIR}/* + do + cat "${resultFile}" + grep -q "FAIL" ${resultFile} && _FAILED=$(expr ${_FAILED} + 1) + done + + if [ "${_COLOR}" == "color" ]; then + #color is for console-output + echo "-----------------------" + if [ ${_FAILED} -ne 0 ]; then + echo "MISSED?${_FAILED}#${_DATETIME}" + else + echo "MISSED?${_FAILED}#${_DATETIME}" + fi + else + echo "MISSED?${_FAILED}#${_DATETIME}" + fi + + rm -r ${_TMPDIR} > /dev/null 2>&1 + return 0 +} + +function usage(){ + printf "\nUsage: /monitoring/check.sh " + echo + echo "possible commands:" + echo + echo "- all" + echo " Executes all checks." + echo "- auto " + echo " Executes quiet all checks and saves the result in the given out_file." + return 0 +} + +main(){ + case "${1:-""}" in + all) + printf "Checks werden ausgeführt..." \ + && doChecks "/tmp/checks" color \ + && printf "Success" \ + && return 0 + ;; + auto) + # If just a filename is given it is created in /tmp, because of 'cd /tmp' + cd /tmp \ + && doChecks "/tmp/checks$(date +%N)" > "$2.new" \ + && mv -f "$2.new" "$2" \ + && return 0 + return 1 + ;; + *) + [ "${1:+isset}" == "isset" ] \ + && printf "Parameter '${1}' ist kein gültiger Befehl.\n" + usage + return 0 + ;; + esac + + return 1 +} + +main "$@" || exit 1 diff --git a/script/monitor/checks/GENERIC_NGINX_CHECK.sh b/script/monitor/checks/GENERIC_NGINX_CHECK.sh new file mode 100755 index 0000000..9d75ff7 --- /dev/null +++ b/script/monitor/checks/GENERIC_NGINX_CHECK.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +_SERVER="${1:?"FQDN of server missing"}" +_PORT="${2:-"22"}" +_USER="monitoring" + +#grep: +# -F Use fixed text, no regexp which has to be interpreted + +#cut: +# -d Delimiter, marker where to cut (here ;) +# -f Index of column to show (One based, so there is no -f0) +_RESULT="$(ssh -p "${_PORT}" "${_USER}"@"${_SERVER}" 'systemctl status nginx.service' | grep -F Active: | grep -F running | cut -d';' -f2)" +! [ -z "${_RESULT}" ] && echo "OK#UPTIME:${_RESULT}" || echo "FAIL" diff --git a/script/monitor/checks/GENERIC_PING_CHECK.sh b/script/monitor/checks/GENERIC_PING_CHECK.sh new file mode 100755 index 0000000..275230b --- /dev/null +++ b/script/monitor/checks/GENERIC_PING_CHECK.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +_SERVER="${1:?"FQDN of server missing"}" + +# -4 Use IPv4 +# -W SECONDS Wait seconds for an answer +# -c COUNT_VALUE Count of pings being executed +_RESULT="$(ping -4 -W 1 -c 1 "${_SERVER}" | grep "time=" | cut -d'=' -f4)" +! [ -z "${_RESULT}" ] && echo "OK#RTT: ${_RESULT}" || echo "FAIL#PLEASE USE FALLBACK!" diff --git a/script/monitor/checks/GENERIC_POOL_SIZE_CHECK.sh b/script/monitor/checks/GENERIC_POOL_SIZE_CHECK.sh new file mode 100755 index 0000000..ed4ba5c --- /dev/null +++ b/script/monitor/checks/GENERIC_POOL_SIZE_CHECK.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +SERVER="${1:?"FQDN of server missing"}" +FILE="pool-size.txt" + +# --connect-timeout SECONDS Maximum time allowed for connection +# -k Allow connections to SSL sites without certs (H) +# -L Follow redirects (H) +# --max-time SECONDS Maximum time allowed for the transfer +# -s Silent mode. Don't output anything +# -f Fail fast with no output on HTTP errors (otherwise no exit-code > 0 on 404) +RESULT="$(curl --connect-timeout 10 --max-time 10 -k -s -f https://$SERVER/monitoring/$FILE || echo WARN#404 on $FILE check HTTPS)" +echo $RESULT diff --git a/script/monitor/checks/GENERIC_REMOTECHECK b/script/monitor/checks/GENERIC_REMOTECHECK new file mode 100755 index 0000000..f3b69fc --- /dev/null +++ b/script/monitor/checks/GENERIC_REMOTECHECK @@ -0,0 +1,17 @@ +#!/bin/bash + +# --connect-timeout SECONDS Maximum time allowed for connection +# -k Allow connections to SSL sites without certs (H) +# -L Follow redirects (H) +# --max-time SECONDS Maximum time allowed for the transfer +# -s Silent mode. Don't output anything +URL="${1:?"URL missing"}" +RESULTS="$(curl --connect-timeout 10 --max-time 10 -k -s "$URL" 2>/dev/null)" +CURTIME="$[ $(date +%s) - 10 * 60 ]" +TIME="$(echo "$RESULTS" | tail -n 1)" +if (echo $TIME | grep -E "[^0-9"] > /dev/null); then echo "FAIL"; exit; fi +RES="$(([ "$CURTIME" -gt "$TIME" ] && echo "TIMEOUT") || (echo "$RESULTS" | head -n 1))" +echo $RES +echo "$RESULTS" | tail -n +2 | head -n -1 + + diff --git a/script/monitor/checks/GENERIC_URL_CHECK.sh b/script/monitor/checks/GENERIC_URL_CHECK.sh new file mode 100755 index 0000000..5625762 --- /dev/null +++ b/script/monitor/checks/GENERIC_URL_CHECK.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +_URL="${1:?"URL of site missing"}" + +#curl: +# --connect-timeout SECONDS Maximum time allowed for connection +# -k Allow connections to SSL sites without certs (H) +# -L Follow redirects (H) +# --max-time SECONDS Maximum time allowed for the transfer +# -s Silent mode. Don't output anything +# --head Show head information only +# --no-progress-meter Clean output for grep + +#grep: +# -q Quite, no output just status codes +# -F Interpret search term as plain text +((curl --connect-timeout 10 --max-time 10 -k -s --head --no-progress-meter "${_URL}" | grep -qF '200 OK') && echo OK) || echo FAIL diff --git a/script/monitor/logo.png b/script/monitor/logo.png new file mode 100644 index 0000000..4864f1d Binary files /dev/null and b/script/monitor/logo.png differ