-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxgMonitor_SendMsg.sh
130 lines (110 loc) · 3.2 KB
/
cxgMonitor_SendMsg.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#created by lixinhang
IPLIST="xc_allserver"
TARGET_FILE="/home/tlxc/logs/resin/Audit/errors_temp"
SHELL_OUT_FILE="ERROR_INFO"
SEND_FILE="CXG_WARNING_MSG"
SEND_MASSAGE_FLAG=1
WARING_KEY_1="miss datachannelIp zoneWorldId"
WARING_KEY_2="Duplicate entry"
WARING_KEY_3="ServerDecoder decode bodyLen"
function GetErrorLog()
{
#echo "enter function GetErrorLog"
cat $IPLIST | grep "front" | grep -v "#" | grep -v "bak" >> monitor_ip_temp
cat $IPLIST | grep "trade" | grep -v "#" | grep -v "bak" >> monitor_ip_temp
cat $IPLIST | grep "datachannel" | grep -v "#" | grep -v "bak" >> monitor_ip_temp
cat monitor_ip_temp | while read line
do
ip=`echo $line | awk '{print $3}'`
scp $ip:${TARGET_FILE} monitor_error_logs
if [ -f monitor_error_logs ]
then
error_info=`cat monitor_error_logs`
echo "[$ip] $error_info" >> $SHELL_OUT_FILE
rm -f monitor_error_logs
fi
done
if [ -f $SHELL_OUT_FILE ]
then
datestamp=`date +%Y-%m-%d`
hourstamp=`date +%H`
timestamp="$datestamp $hourstamp"
echo "$timestamp" >> $SHELL_OUT_FILE
fi
rm -f monitor_ip_temp
}
function IsNeedCheck()
{
#echo "enterfunction isNeedCheck"
if [ -f $SHELL_OUT_FILE ]
then
last_date=`tail -n 1 $SHELL_OUT_FILE`
last_day=`echo $last_date | awk '{print $1}' | awk 'BEGIN{FS="-"}{print $3}'`
last_hour=`echo $last_date | awk '{print $2}'`
cur_day=`date +%d`
cur_hour=`date +%H`
if [ $cur_day -gt $last_day ]
then
rm -f $SHELL_OUT_FILE
SEND_MASSAGE_FLAG=1
else
if [ $cur_hour -gt $last_hour ]
then
rm -f $SHELL_OUT_FILE
SEND_MASSAGE_FLAG=1
else
SEND_MASSAGE_FLAG=0
fi
fi
fi
}
function sumErrorNum()
{
cat $SHELL_OUT_FILE | grep "$WARING_KEY_1" >> err1
err1_num=`cat err1 | wc -l`
if [ $err1_num -gt 0 ]
then
echo "$WARING_KEY_1 error occurd $err1_num times." >> $SEND_FILE
detail=`head -n 1 err1`
echo "$detail" >> $SEND_FILE
rm -f err1
fi
cat $SHELL_OUT_FILE | grep "$WARING_KEY_2" >> err2
err2_num=`cat err2 | wc -l`
if [ $err2_num -gt 0 ]
then
echo "$WARING_KEY_2 error occurd $err2_num times." >> $SEND_FILE
detail=`head -n 1 err2`
echo "$detail" >> $SEND_FILE
rm -f err2
fi
cat $SHELL_OUT_FILE | grep "$WARING_KEY_3" >> err3
err3_num=`cat err3 | wc -l`
if [ $err3_num -gt 0 ]
then
#echo "$WARING_KEY_3 error occurd $err3_num times." >> $SEND_FILE
detail=`head -n 1 err3`
#echo "$detail" >> $SEND_FILE
rm -f err3
fi
}
#####################################################
sleep 70
IsNeedCheck
#echo "SEND_MASSAGE_FLAG $SEND_MASSAGE_FLAG"
if [ $SEND_MASSAGE_FLAG -eq 0 ]
then
exit
fi
GetErrorLog
sumErrorNum
if [ -f $SEND_FILE ]
then
msg=`cat $SEND_FILE`
Group="cxg"
#echo "$msg"
/usr/bin/curl -d "group=$Group&msg=$msg" http://appmon.changyou-inc.com:8080/msgserver/sendinfo.jsp
fi
rm -f $SEND_FILE
#####################################################