-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotify_redis.sh
49 lines (44 loc) · 1.99 KB
/
notify_redis.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
#!/bin/bash
event_type=$event1
event_desc=$event2
OUTPUT_FILE="/dev/shm/notify_redis_event_output"
mail_subject=""
mail_body=""
THIS_IP="x.x.x.x"
SMTP_SERVER="y.y.y.y"
ADMIN="[email protected]"
TEST_ADMIN="[email protected]"
TARGET=$ADMIN
function send_mail(){
mail_subject="${event1}"
mail_body="${evvent2}"
cat ${mail_body} | /bin/mail -s "${mail_subject}" -S smtp=smtp://${SMTP_SERVER} -S from="Admin_Notify_Redis_Sentinel<[email protected]>" "$TARGET"
}
echo -e "=== Event ===\nType: ${event_type}\nDescription: ${event_desc}" > "${OUTPUT_FILE}"
if [ "${event_type}" == "+sdown" ]; then
mail_subject = "[WARNING] Sentinel on `hostname` (${THIS_IP}) detect: There is something is DOWN"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
elif [ "${event_type}" == "-sdown" ]; then
mail_subject = "[NOTICE] Sentinel on `hostname` (${THIS_IP}) detect: There is something is UP"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
elif [ "${event_type}" == "+odown" ]; then
mail_subject = "[WARNING] Sentinel on `hostname` (${THIS_IP}) detect: Master is DOWN"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
elif [ "${event_type}" == "+new-epoch" ]; then
mail_subject = "[WARNING] Sentinel on `hostname` (${THIS_IP}) say: We will TRY FAILOVER this redis replication"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
elif [ "${event_type}" == "-failover-abort-not-elected" ]; then
mail_subject = "[ERROR] Sentinel on `hostname` (${THIS_IP}) shout: ABORT FAILOVER. I need you, system admins"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
elif [ "${event_type}" == "+switch-master" ]; then
mail_subject = "[NOTICE] Sentinel on `hostname` (${THIS_IP}) claim: Switch to new master SUCCESSFULLY"
mail_body=${OUTPUT_FILE}
send_mail "${mail_subject}" "${mail_body}"
else
### do nothing
fi