Last active
December 19, 2015 15:09
-
-
Save junaid18183/5973966 to your computer and use it in GitHub Desktop.
#These Nagios plug-in's monitors the Cassandra Cluster for number of nodes connected, and Unreachable nodes in Cassandra Ring; using nodetool ring command
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 | |
#This Plug-in monitors the Unreachable nodes in Cassandra Ring; using nodetool ring command | |
# Author - Juned Memon [email protected] | |
#########THIS part is for Nagios ################################ | |
PROGNAME=`/usr/bin/basename $0` | |
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | |
REVISION=`echo '$Revision: 1749 $' | sed -e 's/[^0-9.]//g'` | |
#. $PROGPATH/utils.sh | |
. /usr/local/nagios/libexec/utils.sh | |
###################################################################### | |
#Function to print Usage | |
function usage | |
{ | |
usage1="Usage: $0 [-w <WARN>] [-c <CRIT>] -H <HOST> -P <PORT>" | |
usage2="<WARN> is Number of Unreachable Nodes for WARNing state Default is 1." | |
usage3="<CRIT> is Number of Unreachable Nodes state Default is 2.\n <HOST> of cassandra node; Default is localhost \n <PORT> JMX port ; Default is 7199 " | |
echo $usage1 | |
echo"" | |
echo $usage2 | |
echo"" | |
echo "$usage3" | |
exit $STATE_UNKNOWN | |
} | |
WARN=5 | |
CRIT=10 | |
HOST="localhost" | |
PORT=7199 | |
##################################################################### | |
# get parameter values in Variables | |
while test -n "$1"; do | |
case "$1" in | |
-c ) | |
CRIT=$2 | |
shift | |
;; | |
-w ) | |
WARN=$2 | |
shift | |
;; | |
-h) | |
usage | |
;; | |
-H) | |
HOST=$2 | |
shift | |
;; | |
-P) | |
PORT=$2 | |
shift | |
;; | |
*) | |
echo "Unknown argument: $1" | |
usage | |
;; | |
esac | |
shift | |
done | |
##################################################################### | |
DOWN=$( nodetool -h $HOST -p $PORT ring | grep Down | wc -l ) | |
#DOWN=$( nodetool -h $HOST -p $PORT ring | grep Up | wc -l ) | |
IP=$( nodetool -h $HOST -p $PORT ring | grep Down | awk '{printf $1 ";"}' ) | |
#IP=$( nodetool -h $HOST -p $PORT ring | grep Up | awk '{printf $1 " ; "}' ) | |
echo "$DOWN Unreachable node in Cassandra Ring. [$IP] " | |
#if CRIT > DOWN >WARN then WARNing | |
if [ $DOWN -ge $WARN ]; then | |
if [ $DOWN -lt $CRIT ]; then | |
exitstatus=$STATE_WARNING | |
exit $exitstatus | |
fi | |
fi | |
# DOWN>CRIT then CRITical | |
if [ $DOWN -ge $CRIT ]; then | |
exitstatus=$STATE_CRITICAL | |
exit $exitstatus | |
fi | |
# 0<=DOWN <WARN | |
if [ $DOWN -le $WARN ]; then | |
exitstatus=$STATE_OK | |
exit $exitstatus | |
fi | |
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 | |
#This Plug-in monitors the Cassandra Cluster for number of nodes connected. | |
# Author - Juned Memon [email protected] | |
#########THIS part is for Nagios ################################ | |
PROGNAME=`/usr/bin/basename $0` | |
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | |
REVISION=`echo '$Revision: 1749 $' | sed -e 's/[^0-9.]//g'` | |
#. $PROGPATH/utils.sh | |
. /usr/local/nagios/libexec/utils.sh | |
###################################################################### | |
#Function to print Usage | |
function usage | |
{ | |
usage="Usage: $0 [-w <WARN>] [-c <CRIT>] -H <HOST> -P <PORT>" | |
echo $usage | |
usage="<WARN> is Number of Live Nodes in Cassandra Cluster for Warning state Default is 3." | |
echo $usage | |
usage="<CRIT> is Number of Live Nodes in Cassandra Cluster for Critical State. Defalt is 2." | |
echo $usage | |
usage="<HOST> of cassandra node; Default is 127.0.0.1" | |
echo $usage | |
usage="<PORT> JMX port ; Default is 7199 " | |
echo $usage | |
exit $STATE_UNKNOWN | |
} | |
WARN=3 | |
CRIT=2 | |
HOST="127.0.0.1" | |
PORT=7199 | |
##################################################################### | |
# get parameter values in Variables | |
while test -n "$1"; do | |
case "$1" in | |
-c ) | |
CRIT=$2 | |
shift | |
;; | |
-w ) | |
WARN=$2 | |
shift | |
;; | |
-h) | |
usage | |
;; | |
-H) | |
HOST=$2 | |
shift | |
;; | |
-P) | |
PORT=$2 | |
shift | |
;; | |
*) | |
echo "Unknown argument: $1" | |
usage | |
;; | |
esac | |
shift | |
done | |
##################################################################### | |
UP=$(nodetool -h $HOST -p $PORT ring | grep Up | wc -l ) | |
IP=$(nodetool -h $HOST -p $PORT ring | grep Up | awk '{printf $1 " ; "}' ) | |
#if CRIT > UP >WARN then WARNing | |
if [ $UP -lt $WARN ]; then | |
if [ $UP -ge $CRIT ]; then | |
exitstatus=$STATE_WARNING | |
echo "WARNING : $UP live nodes in Cassandra Ring. [$IP] " | |
exit $exitstatus | |
fi | |
fi | |
# UP>CRIT then CRITical | |
if [ $UP -lt $CRIT ]; then | |
exitstatus=$STATE_CRITICAL | |
echo "CRITICAL : $UP live nodes in Cassandra Ring. [$IP] " | |
exit $exitstatus | |
fi | |
# 0<=UP <WARN | |
if [ $UP -gt $WARN ]; then | |
exitstatus=$STATE_OK | |
echo "OK : $UP live nodes in Cassandra Ring. [$IP] " | |
exit $exitstatus | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment