-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoderror_emailnotif.sh
57 lines (41 loc) · 1.5 KB
/
poderror_emailnotif.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
#!/bin/bash
#nonrunpod=$(oc get pods -A | grep -v Running | grep -v Completed)
#Change the API Endpoint here.
oc login -u kubeadmin -p $(cat /root/ftm4c/auth/kubeadmin-password) https://<API-ENDPOINT>:6443
count_non=$(oc get pods -A --no-headers | grep -v Running | grep -v Completed | wc -l)
if [[ ${count_non} -gt 0 ]]; then
# Define recipient email address
recipient="<recipient-email-address>"
# Define email subject
subject="Failed/Error Pods in ftm4c Cluster at $(date "+%B %d %Y, %I:%M:%S %p")"
# Define sender name
sender_name=$(oc whoami)
hhh=$(hostname)
tabes=$(echo -e "NAMESPACE \t\t NAME")
failed_pods=$(oc get pods -A --no-headers | grep -v Running | grep -v Completed | awk '{print $1 "\t""\t" $2}')
# Create the email content
email_content=$(cat <<EOF
Hello,
Here is the current status of the OpenShift cluster at $(date "+%B %d %Y, %I:%M:%S %p")
Check done by ${sender_name}
============================================================
Pods not running:
------------------------------------------------------------
${tabes}
${failed_pods}
============================================================
This is an automated email from ${sender_name}. Please do not reply.
Sent from ${hhh}
------------------------------------------------------------
EOF
)
# Send the email
echo "$email_content" | mailx -s "$subject" "$recipient"
#echo "$email_content"
exit 0
else
echo -e "No Failed Pods as of $(date "+%B %d %Y, %I:%M:%S %p") \n" >> /root/mail-test/email-log-pod_check.log
exit 0
fi
oc logout
exit 0