-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from pgraziano/apt-cache
updated apt cache sensu check
- Loading branch information
Showing
2 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This checks that the apt cache has been updated recently. | ||
# It relies on the periodic cron job that touches FILE after a successful run. | ||
|
||
# the file that is touched by cron job on successful apt cache update | ||
FILE=/var/lib/apt/update-cache-success | ||
|
||
# arguments passed in for the warning/critical threshold in hours | ||
WARNING_HOURS=$1 | ||
CRITICAL_HOURS=$2 | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "usage: $0 WARNINGHOURS CRITICALHOURS" | ||
exit 3 | ||
fi | ||
|
||
if ! [[ -f $FILE ]]; then | ||
echo "status file missing: $FILE" | ||
exit 3 | ||
fi | ||
|
||
HOURS_SINCE_UPDATE=`echo $(( ($(date +%s) - $(date +%s -r "$FILE"))/60/60))` | ||
MINUTES_SINCE_UPDATE=`echo $(( ($(date +%s) - $(date +%s -r "$FILE"))/60))` | ||
|
||
if [[ $HOURS_SINCE_UPDATE -gt $CRITICAL_HOURS ]]; then | ||
echo "CRITICAL: stale apt cache, $HOURS_SINCE_UPDATE hours old." | ||
exit 2 | ||
elif [[ $HOURS_SINCE_UPDATE -gt $WARNING_HOURS ]]; then | ||
echo "WARNING: stale apt cache, $HOURS_SINCE_UPDATE hours old." | ||
exit 1 | ||
fi | ||
|
||
echo "OK: last apt cache update was ${HOURS_SINCE_UPDATE}h (${MINUTES_SINCE_UPDATE}m) ago" | ||
exit 0 |
This file was deleted.
Oops, something went wrong.