Skip to content

Instantly share code, notes, and snippets.

@realtebo
Created April 23, 2021 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realtebo/f4d43c837fd7ce5fbb483457569385ae to your computer and use it in GitHub Desktop.
Save realtebo/f4d43c837fd7ce5fbb483457569385ae to your computer and use it in GitHub Desktop.
Nagios Plugin to monitor number of upgradable packages
#!/usr/bin/env bash
PACKAGES=`apt list --upgradable 2>/dev/null | wc -l`
echo "Trovati $PACKAGES package da aggiornare"
# soglie da default
WARNING=10
CRITICAL=20
# Leggo i valori delle opzioni
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-w)
WARNING="$2"
shift # past argument
shift # past value
;;
-c)
CRITICAL="$2"
shift # past argument
shift # past value
;;
esac
done
if [[ $(expr PACKAGES) -ge $(expr CRITICAL) ]]; then
echo "CRITICAL: $PACKAGES upgradable"
exit 2
fi
if [[ $(expr PACKAGES) -ge $(expr WARNING) ]]; then
echo "WARNING: $PACKAGES upgradable"
exit 1
fi
echo "OK: $PACKAGES upgradable"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment