Created
February 15, 2014 14:49
-
-
Save sankars/9020237 to your computer and use it in GitHub Desktop.
Shell script to check data availability in HBase through its REST interface and notifies user if no data is found
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
| #!/bin/sh | |
| HBASE_REST_SERVER='http://hbase_rest_server:8080' | |
| ### Open customers file and read customer list | |
| while read line | |
| do | |
| IFS=', ' read -a array <<< $line | |
| CUSTOMER="${array[0]}" | |
| export TZ="${array[1]}" | |
| DATE_STR=$(date +%F) | |
| EPOCH_DAY_START=$(date --date $DATE_STR +%s) | |
| EPOCH_NOW=$(date --date now +%s) | |
| echo "Checking for customer : $CUSTOMER on $DATE_STR" | |
| ### Open tables file and read table list | |
| while read t | |
| do | |
| TABLE=$t | |
| if [ ! -z "$t" -a "$t" != " " -a ! -z "$CUSTOMER" -a "$CUSTOMER" != " " ] | |
| then | |
| TABLE="$CUSTOMER"_"$TABLE" | |
| echo Checking : "$TABLE" | |
| ### Create a scanner | |
| URL="$HBASE_REST_SERVER"/"$TABLE"/scanner | |
| ### Get the redirected url | |
| URL=$(curl -D - -H "Content-Type: application/json" -X POST -d "{\"batch\":1,\"startTime\":$(( $EPOCH_DAY_START*1000 )),\"endTime\":$(( $EPOCH_NOW*1000 ))}" "$URL" --silent | awk '/Location: (.*)/ {print $2}' | tail -n 1) | |
| ### Check for data | |
| count=$(curl "$URL" --silent | grep -c "timestamp") | |
| if [ $count -lt 1 ] | |
| then | |
| ### Check failed. Trigger a mail | |
| echo "Data not available in $TABLE for $DATE_STR. Kindly check!" | mail -s "ALERT: No data in $TABLE " "[email protected]" | |
| echo "Data not available in $TABLE. Mail Sent!" | |
| fi | |
| curl -X DELETE --silent --output /dev/null "$URL" | |
| fi | |
| done < tables | |
| done < customers | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment