-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_mail_tracker.sh
More file actions
241 lines (200 loc) · 10.5 KB
/
api_mail_tracker.sh
File metadata and controls
241 lines (200 loc) · 10.5 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
PGSQLNONCE=`grep 'pgsql_nonce' /data1/message_studio/conf/msgstudio.conf |cut -d= -f2`
PGSQLPASS=`grep 'pgsql_password' /data1/message_studio/conf/msgstudio.conf |cut -d= -f2`
PGPASSWORD=`JAVA_HOME="/data1/message_studio/thirdparty/java64/jre1.7.0"; JAVA_CLASSPATH='/data1/message_studio/lib/sm/WEB-INF:/data1/message_studio/lib/sm/WEB-INF/lib/*:/data1/message_studio/lib/sm/WEB-INF/classes:/data1/message_studio/lib/bfj220.jar:/data1/message_studio/lib/sm/WEB-INF/lib/sm_common_business.jar:/data1/message_studio/lib/sm/WEB-INF/lib/commons-lang-2.1.jar:/data1/message_studio/lib/sm/WEB-INF/lib/commons-logging-1.0.4.jar:/data1/message_studio/lib/sm/WEB-INF/lib/spring.jar:/data1/message_studio/lib/sm/WEB-INF/lib/postgresql-8.0-310.jdbc3.jar:/data1/message_studio/lib/sm/WEB-INF/lib/mysql-connector-java-5.1.16-bin.jar:/data1/message_studio/lib/sm/WEB-INF/lib/log4j-1.2.14.jar:/data1/message_studio/lib/sm/WEB-INF/lib/commons-io-2.0.1.jar'; ${JAVA_HOME}/bin/java -cp ${JAVA_CLASSPATH} com.sm.common.business.security.StrongMailSymmetricEncryptionUtility D $PGSQLPASS $PGSQLNONCE`
Today=`date +"%Y-%m-%d"`
AppServerLog=/data1/message_studio/log/system/appserver.log
DBFile=`find /data1/strongmail/data/databases/ -name 1*.db -mtime -1`
RetryLOG=/data1/strongmail/log/strongmail-retryfailed.log
SuccessLOG=/data1/strongmail/log/strongmail-success.log
BCCSuccessLOG=/data1/strongmail/log/strongmail-success-bcc-cc.log
BCCRetryLOG=/data1/strongmail/log/strongmail-retryfailed-bcc-cc.log
MTASERVERS=`grep HostName /data1/strongmail/config/strongmail-client.conf | cut -d, -f1 | cut -d= -f2 | sort | uniq`
export PGPASSWORD=$PGPASSWORD
/data1/message_studio/thirdparty/pgsql/bin/psql -U postgres -c "COPY (select ip_address from strongmail_eas_server) TO '/tmp/eas_servers'" > /dev/null
EASSERVERS=`cat /tmp/eas_servers`
Prompt()
{
echo "\
------------------------------------------------------------------------------------------
$1
------------------------------------------------------------------------------------------"
}
UsageEx()
{
(
exec 1>&2
if [ $# -ge 1 ]
then
Prompt "ERROR: $1";
fi
Prompt "\
Usage:
trace_message.sh -t <deployment type> -m <serial or unique identifier>
deployment type: tier1, tier2, tier3
";
)
exit 1;
}
GetCmdlineOptions()
{
while getopts ":t:m:h:" opt
do
case $opt in
t )
type=$OPTARG
;;
m )
MID=$OPTARG
;;
h )
shift
UsageEx;
;;
* )
echo "Invalid option:[$option_str]"
exit 1
;;
esac
done
if [ -z "$type" -a -z "$MID" ]
then
UsageEx "You must enter the parameters";
fi
}
tier1_search()
{
echo "searching appserver log..."
echo "###############################################################################################"
#grep $MID $AppServerLog
awk '/'"$MID"'/ {flag=1;next} /'"$MID"'/{flag=0} flag {print}' $AppServerLog
echo "###############################################################################################"
echo "searching db files..."
echo "###############################################################################################"
for f in "${DBFile[@]}"; do grep $MID "$f"; done
echo "###############################################################################################"
echo "searching success logs..."
echo "###############################################################################################"
grep $MID $SuccessLOG
grep $MID $SuccessLOG.processed-$Today
echo "###############################################################################################"
echo "searching retry failed logs..."
echo "###############################################################################################"
grep $MID $RetryLOG
grep $MID $RetryLOG.processed-$Today
echo "###############################################################################################"
echo "searching bcc success logs..."
echo "###############################################################################################"
grep $MID $BCCSuccessLOG
grep $MID $BCCSuccessLOG.processed-$Today
echo "###############################################################################################"
echo "searching bcc retry failed logs..."
echo "###############################################################################################"
grep $MID $BCCRetryLOG
grep $MID $BCCRetryLOG.processed-$Today
echo "###############################################################################################"
}
tier2_search()
{
echo "searching appserver log..."
echo "###############################################################################################"
awk '/'"$MID"'/ {flag=1;next} /'"$MID"'/{flag=0} flag {print}' $AppServerLog
echo "###############################################################################################"
echo "searching db files..."
echo "###############################################################################################"
for f in "${DBFile[@]}"; do grep "${i}" "$f"; done
echo "###############################################################################################"
echo "searching success logs..."
echo "###############################################################################################"
for h in "${MTASERVERS[@]}"; do ssh root@"$h" "grep $MID $SuccessLOG.processed-$Today" && "grep $MID $SuccessLOG"; done
echo "###############################################################################################"
echo "searching retry failed logs..."
echo "###############################################################################################"
for h in "${MTASERVERS[@]}"; do ssh root@"$h" "grep $MID $RetryLOG.processed-$Today" && "grep $MID $RetryLOG"; done
echo "###############################################################################################"
echo "searching bcc success logs..."
echo "###############################################################################################"
for h in "${MTASERVERS[@]}"; do ssh root@"$h" "grep $MID $BCCSuccessLOG.processed-$Today" && "grep $MID $BCCSuccessLOG"; done
echo "###############################################################################################"
echo "searching bcc retry failed logs..."
echo "###############################################################################################"
for h in "${MTASERVERS[@]}"; do ssh root@"$h" "grep $MID $BCCRetryLOG.processed-$Today" && "grep $MID $BCCRetryLOG"; done
echo "###############################################################################################"
}
tier3_search()
{
for s in "${EASSERVERS[@]}"; do MTAHOSTS=$(ssh root@"$s" "grep HostName /data1/strongmail/config/strongmail-client.conf | cut -d, -f1 | cut -d= -f2 | sort | uniq"); done
echo "searching appserver log..."
echo "###############################################################################################"
awk '/'"$MID"'/ {flag=1;next} /'"$MID"'/{flag=0} flag {print}' $AppServerLog
echo "###############################################################################################"
echo "searching db files..."
echo "###############################################################################################"
for s in "${EASSERVERS[@]}"; do ssh root@"$s" "for f in "${DBFile[@]}"; do grep $MID "$f"; done"; done
echo "###############################################################################################"
echo "searching success logs..."
echo "###############################################################################################"
for h in "${MTAHOSTS[@]}"; do ssh root@"$h" "grep $MID $SuccessLOG.processed-$Today" && "grep $MID $SuccessLOG"; done
echo "###############################################################################################"
echo "searching retry failed logs..."
echo "###############################################################################################"
for h in "${MTAHOSTS[@]}"; do ssh root@"$h" "grep $MID $RetryLOG.processed-$Today" && "grep $MID $RetryLOG"; done
echo "###############################################################################################"
echo "searching bcc success logs..."
echo "###############################################################################################"
for h in "${MTAHOSTS[@]}"; do ssh root@"$h" "grep $MID $BCCSuccessLOG.processed-$Today" && "grep $MID $BCCSuccessLOG"; done
echo "###############################################################################################"
echo "searching bcc retry failed logs..."
echo "###############################################################################################"
for h in "${MTAHOSTS[@]}"; do ssh root@"$h" "grep $MID $BCCRetryLOG.processed-$Today" && "grep $MID $BCCRetryLOG"; done
echo "###############################################################################################"
}
setSSHPassword2()
{
echo "copying ssh key pair to MTA Servers..."
echo "###############################################################################################"
ssh-keygen
for h in "${MTASERVERS[@]}"; do ssh-copy-id -i ~/.ssh/id_rsa.pub "$h"; echo "copied to "$h" completed"; done
}
setSSHPassword3()
{
echo "generating ssh key pair..."
echo "###############################################################################################"
ssh-keygen
echo "copying ssh key pair to EAS Servers..."
echo "###############################################################################################"
for e in "${EASSERVERS[@]}"; do ssh-copy-id -i ~/.ssh/id_rsa.pub "$e"; echo "copied to "$e" completed"; done
echo "copying ssh key pair to MTA Servers..."
echo "###############################################################################################"
for s in "${EASSERVERS[@]}"; do MTAHOSTS=$(ssh root@"$s" "grep HostName /data1/strongmail/config/strongmail-client.conf | cut -d, -f1 | cut -d= -f2 | sort | uniq"); done
for k in "${MTAHOSTS[@]}"; do ssh-copy-id -i ~/.ssh/id_rsa.pub "$k"; echo "copied to "$k" completed"; done
}
main()
{
GetCmdlineOptions "$@"
if [ $type == "tier1" ]
then
tier1_search
elif [ $type == "tier2" ]
then
while true; do
read -p "Do you wish to set SSH password free (y/n)? " yn
case $yn in
[Yy]* ) setSSHPassword2; tier2_search; break;;
[Nn]* ) tier2_search; break;;
* ) echo "Please answer yes or no.";;
esac
done
elif [ $type == "tier3" ]
then
while true; do
read -p "Do you wish to set SSH password free (y/n)? " yn
case $yn in
[Yy]* ) setSSHPassword3; tier3_search; break;;
[Nn]* ) tier3_search; break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
}
main "$@"