Created
July 28, 2017 19:21
-
-
Save salekseev/c5243ebcde0c6bd40058fc1c589367a4 to your computer and use it in GitHub Desktop.
Script to check Elasticsearch clusters for under-replicated indices
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 | |
# | |
# script accepts URLs of Elasticsearch clusters as arguments | |
# exit code table: | |
# 0 - no underreplicated indices | |
# 1 - found underreplicated indices | |
# 2 - unable to connect to one of those URLs could not be connected to | |
# 3 - timed out getting list of indices | |
# | |
for var in "$@" | |
do | |
if curl --output /dev/null --max-time 1 --connect-timeout 1 --silent --head --fail "$var" | |
then | |
output=$(curl --silent --max-time 30 --connect-timeout 1 "$var/_cat/indices?h=rep,index") | |
status=$? | |
if [ $status -eq 0 ] | |
then | |
matches=$(echo "$output" | egrep "^0\s+") | |
if [ ! -z "$matches" ] | |
then | |
echo "The following indices are underreplicated:" | |
echo "$matches" | |
exit 1 | |
fi | |
else | |
exit 3 | |
fi | |
else | |
exit 2 | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment