-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_redis_non_expiring_elements.sh
executable file
·91 lines (69 loc) · 1.91 KB
/
alert_redis_non_expiring_elements.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
loop_through_db() {
for db in $(split_database_indexes); do
ttls_not_found=$(find_keys_without_ttl)
print_ttls_not_found_keys=$(print_ttls_not_found_keys)
if [ "$print_ttls_not_found_keys" ]; then
create_temp_files
notify
remove_temp_files
fi
done
}
find_keys_without_ttl() {
local ttls_not_found="$(
redis-cli -h $host -p $port -a $password -n $db --no-auth-warning keys "*" |
while read LINE; do
if [[ $exclude_keys == *$LINE* ]]; then
continue
fi
TTL=$(redis-cli -h $host -p $port -a $password -n $db --no-auth-warning ttl "$LINE")
if [ $TTL -eq -1 ]; then echo "$LINE"; fi
done
)"
echo "$ttls_not_found"
}
print_ttls_not_found_keys() {
local result_string=""
if [ "$ttls_not_found" ]; then
result_string+="\n ******* Running in - $host:$port, DB - $db *******"
for key in $ttls_not_found; do
result_string+="\n $key"
done
result_string+="\n"
fi
echo "$result_string"
}
notify() {
notify_via_g_chat
notify_via_slack
}
create_temp_files() {
printf "${print_ttls_not_found_keys}"
local messageInJson="{\"text\":\"$print_ttls_not_found_keys\"}"
echo "$messageInJson" >curl_data.txt
}
remove_temp_files() {
#clean the files
rm -r curl_data.txt
rm -r null
}
split_database_indexes() {
IFS=','
read -ra DBNAME <<<"$database_indexes"
echo "${DBNAME[@]}"
}
notify_via_g_chat() {
if [ "$google_chat_webhook_uri" ]; then
curl -s -o null --request POST "$google_chat_webhook_uri" --header 'Content-Type: application/json' --data-raw "$(cat curl_data.txt)"
fi
}
notify_via_slack() {
if [ "$slack_webhook_uri" ]; then
curl -s -o null --request POST "$slack_webhook_uri" --header 'Content-Type: application/json' --data-raw "$(cat curl_data.txt)"
fi
}
# Main function
echo "Currently executing for $host:$port"
loop_through_db
echo "Finished executing for $host:$port"