1
0
Fork 0

nagios/check_gitea_version: proper nagios' way to separate address and hostname

This commit is contained in:
Chl 2024-01-07 15:52:20 +01:00
parent 365c100066
commit 4baa8fdde3

View file

@ -6,14 +6,43 @@
# Stop at first uncatched error # Stop at first uncatched error
set -e set -e
# note: some local problems with IPv4, the quickest way was to force IPv6. usage() {
LOCAL_VERSION="$( wget -6 -O - -q "https://$( hostname -f )/api/v1/version" | sed -n 's/{"version":"\([^"]\+\)"}/\1/p' )" cat <<EOF
$0 -H hostname -I address
TODO: write the rest :)
EOF
}
while getopts H:I: f; do
case "$f" in
'H')
HOSTNAME="$OPTARG"
;;
'I')
HOSTADDRESS="$OPTARG"
# If there is some ":" in the adress, we treat it as IPv6
if echo "$HOSTADDRESS" | grep ":" >/dev/null 2>&1; then
HOSTADDRESS="[$HOSTADDRESS]"
fi
;;
\?)
usage
exit 1
;;
esac
done
INSTALLED_VERSION="$( wget -O - --header="Host: $HOSTNAME" --no-check-certificate -q "https://$HOSTADDRESS/api/v1/version" | sed -n 's/{"version":"\([^"]\+\)"}/\1/p' )"
UPSTREAM_VERSION="$( wget -q -O - "https://dl.gitea.io/gitea/" | egrep -- '<a href="/gitea/[0-9]+\.[0-9]+\.[0-9]+/?"' | egrep -o "[0-9]+\.[0-9]+\.[0-9]+" | sort --version-sort | tail -n 1 )" UPSTREAM_VERSION="$( wget -q -O - "https://dl.gitea.io/gitea/" | egrep -- '<a href="/gitea/[0-9]+\.[0-9]+\.[0-9]+/?"' | egrep -o "[0-9]+\.[0-9]+\.[0-9]+" | sort --version-sort | tail -n 1 )"
if [ "$UPSTREAM_VERSION" = "$LOCAL_VERSION" ]; then if [ "$UPSTREAM_VERSION" = "$INSTALLED_VERSION" ]; then
echo "OK ($LOCAL_VERSION / $UPSTREAM_VERSION)" echo "OK ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
exit 0 exit 0
else else
echo "WARNING ($LOCAL_VERSION / $UPSTREAM_VERSION)" echo "WARNING ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
exit 1 exit 1
fi fi