-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelasticpulse_indexcount.sh
53 lines (47 loc) · 1.37 KB
/
elasticpulse_indexcount.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
eshost="elastic.domain.com"
timeback="15m"
credentials="elastic:changeme"
indexname="default"
datatype="default"
datename="indexdate"
while getopts H:t:u:i:d:k: option
do
case "${option}"
in
H) eshost=${OPTARG};;
t) timeback=${OPTARG};;
u) credentials=${OPTARG};;
i) indexname=${OPTARG};;
d) datatype=${OPTARG};;
k) datename=${OPTARG};;
esac
done
# Debug
#echo $eshost
#echo $timeback
#echo $credentials
#echo $indexname
#echo $datatype
index_count=`curl -s -XGET -u $credentials $eshost'/'$indexname'/'$datatype'/_search' \
-H 'Content-Type: application/json' -d '{"query": { "range" : { "'$datename'" : { "gte" : "now-'$timeback'", "lt" : "now"}}}}' | \
python -c "import sys, json; print json.load(sys.stdin)['hits']['total']"`
# echo "Index Count: $index_count"
# The echo message is "Status Information | Performance data"
# Split up by |
if ((5<=$index_count))
then
echo "OK - Index count is $index_count in the last $timeback. | $index_count"
exit 0
elif ((1<=$index_count && $index_count<=4))
then
echo "WARNING - Index count is $index_count in the last $timeback. | $index_count"
exit 1
elif ((0==$index_count))
then
echo "CRITICAL - Index count is $index_count in the last $timeback. | $index_count"
exit 2
else
echo "UNKNOWN - Index count is $index_count in the last $timeback. | $index_count"
exit 3
fi