diff --git a/nagios/check_forgejo_version.sh b/nagios/check_forgejo_version.sh new file mode 100755 index 0000000..d9d1515 --- /dev/null +++ b/nagios/check_forgejo_version.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +# Little monitoring script to check that the version of a +# Forgejo instance is up to date. +# +# Licence: WTFPL +# Copyright: chl-dev@bugness.org 2023 + +PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' ) +REVISION="0.1" + +# Default values +DNS_RECORD_RELEASES="release.forgejo.org" +RELEASE_MEDIUM="dns" +URL_RSS_RELEASES="https://codeberg.org/forgejo/forgejo/releases.rss" +URL_LOCAL_HOSTNAME="localhost:3000" +URL_LOCAL_VERSION_TEMPLATE="%s://%s/api/v1/version" +URL_LOCAL_PROTOCOL="http" + +# Include check_range() +# Not needed at the moment +#. $PROGPATH/utils.sh +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 +STATE_DEPENDENT=4 + +# Stop at first uncaught error +set -e + +# Wrapper to use whatever is available to make HTTP queries +fetch_with_curl_wget_or_whatever () { + if which "wget" >/dev/null 2>&1; then + wget -q -O - "$1" + elif which "curl" >/dev/null 2>&1 ; then + curl -s "$1" + else + echo "UNKNOWN: no wget/curl/whatever available to make HTTP queries." + exit $STATE_UNKNOWN + fi +} + +# Wrapper to use whatever is available to make DNS queries +fetch_with_dig_or_whatever () { + if which "dig" >/dev/null 2>&1; then + dig +short "$1" "$2" + elif which "nslookup" >/dev/null 2>&1; then + nslookup -query="$2" "$1" | sed -n "/$1/p" + else + echo "UNKNOWN: no dig/nslookup/whatever available to make DNS queries." + exit $STATE_UNKNOWN + fi +} + +# Sort the multiple