Created
April 23, 2021 14:26
-
-
Save realtebo/f4d43c837fd7ce5fbb483457569385ae to your computer and use it in GitHub Desktop.
Nagios Plugin to monitor number of upgradable packages
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
#!/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