-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfirm_all_es_alias.sh
executable file
·43 lines (38 loc) · 1.11 KB
/
confirm_all_es_alias.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
#!/usr/bin/env bash
##-------------------------------------------------------------------
## File: confirm_all_es_alias
## Author : Denny
## Description :
## --
## Created : <2018-01-29>
## Updated: Time-stamp: <2018-01-29 16:25:54>
##-------------------------------------------------------------------
function get_alias_from_index() {
local index=${1?}
alias="${index%-new*}"
echo "${alias//-index/}"
}
function list_indices() {
local es_ip=${1?}
local es_port=${2?}
curl -XGET "http://${es_ip}:${es_port}/_cat/indices?v" | grep "\-index" | awk '{print $3}'
}
function shell_exit() {
errcode=$?
if [ $errcode -eq 0 ]; then
echo "All es alias is OK"
else
echo "Some es alias has issues"
fi
exit $errcode
}
es_ip=${1?}
es_port=${2?}
trap shell_exit SIGHUP SIGINT SIGTERM 0
index_list=$(list_indices "$es_ip" "$es_port")
# echo $index_list
for index in $index_list; do
alias_name=$(get_alias_from_index "$index")
echo "index: $index. Get alias doc count. alias_name: $alias_name"
curl "http://$es_ip:$es_port/${alias_name}/_count" | grep -v error
done