Created
June 21, 2014 19:57
-
-
Save rchrd2/38b56c77403e63cd9918 to your computer and use it in GitHub Desktop.
Nagios check_redis_llen.sh
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
#!/bin/bash | |
# A simple nagios check for Redis set length | |
# | |
# It doesn't require any redis libraries and uses the raw api | |
# | |
# @author Richard Caceres (me@rchrd.net) | |
# @license MIT | |
# @example check_redis_llen -c 50 -w 10 -k celery -h localhost -p 6379 | |
# Parse -c -w args | |
critical=50 | |
warning=10 | |
key="celery" | |
host="localhost" | |
port="6379" | |
set -- $(getopt c:w:k:h:p: "$@") | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
(-c) critical=$2; shift;; | |
(-w) warning=$2; shift;; | |
(-k) key=$2; shift;; | |
(-h) host=$2; shift;; | |
(-p) port=$2; shift;; | |
(--) shift; break;; | |
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; | |
(*) break;; | |
esac | |
shift | |
done | |
# Run redis command | |
result_raw=$((echo -en "llen $key\r\n";) | nc $host $port) | |
result=$(echo $result_raw | sed 's/[^0-9]*//g') | |
re='^[0-9]+$' | |
if ! [[ $result =~ $re ]]; then | |
echo "Invalid input (not numeric): $result_raw" | |
exit 2 | |
fi | |
if [ "$result" -ge $warning ]; then exit 1; | |
elif [ "$result" -ge $critical ]; then exit 2; | |
else exit 0; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment