-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgpdebug.sh
303 lines (260 loc) · 8.48 KB
/
bgpdebug.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
# BGP and RouteD daemon debug on Gaia 0.2.1
#
#
# Version History
# 0.1 Initial version. Only Security Gateways in VSX are supported.
# 0.2 Security Gateway in Gateway Mode is now supported.
# Added new menu options: - Show debug status
# - Switch to other Virtual System (VSX only)
# - Quit the script
# 0.2.1 FIX: Option 6 now only works in VSX mode.
# Minor quality updates
#
#
#====================================================================================================
# Global variables
#====================================================================================================
if [[ -e /etc/profile.d/CP.sh ]]; then
source /etc/profile.d/CP.sh
fi
if [[ -e /etc/profile.d/vsenv.sh ]]; then
source /etc/profile.d/vsenv.sh
fi
#====================================================================================================
# Variables
#====================================================================================================
HOSTNAME=$(hostname -s)
DATE=$(date +%Y%m%d-%H%M%S)
OUTPUTDIR="/var/log/tmp/$HOSTNAME/$DATE"
VERSION="0.2.1"
#====================================================================================================
# Environment checks
#====================================================================================================
clear
printf "BGP and RouteD daemon debug on Gaia v$VERSION\n\n"
printf "Checking my environment...\n"
if [[ ! $ISMGMT -eq 0 ]]; then
printf "NOT PASSED\nINFO: This script is not intended for management servers.\n"
exit 1
fi
CLCHK=$(clish -c exit)
if [[ ! -z "$CLCHK" ]]; then
printf "Clish returns error: $CLCHK\n"
printf "Please resolve this before executing the script again.\n\n"
exit 1
fi
#====================================================================================================
# Functions
#====================================================================================================
gw_type_check() {
ISVSX=`$CPDIR/bin/cpprod_util FwIsVSX`
if [[ $ISVSX -eq 1 ]]; then
printf "Security Gateway runs in VSX Mode\n\n"
select_vs
else
printf "Security Gateway runs in Gateway Mode\n\n"
fi
}
select_vs () {
ALL_VSID=$(clish -c "show virtual-system all")
printf "$ALL_VSID\n\n"
read -p "Select Virtual System ID: " -r VIRTUAL_SYSTEM
printf "\n"
vsenv $VIRTUAL_SYSTEM
VSOK=$(echo $?)
if [[ ! $VSOK -eq 0 ]]; then
printf "\n"
select_vs
fi
}
questionnaire () {
printf "\n"
printf " 1) Enable BGP and RouteD debug\n"
printf " 2) Disable BGP and RouteD debug\n"
printf " 3) Show debug status\n"
printf " 4) Collect debug information\n"
printf " 5) Collect debug information and CPinfo\n"
if [[ $ISVSX -eq 1 ]]; then
printf " 6) Change the context to other Virtual System\n"
fi
printf " q) Quit\n\n"
read -p "Select: " -r ON_OFF
if [[ $ON_OFF == "1" ]]; then
debug_on
elif [[ $ON_OFF == "2" ]]; then
debug_off
elif [[ $ON_OFF == "3" ]]; then
show_debug_status
elif [[ $ON_OFF == "4" ]]; then
get_bgppeers
collect_debug
printf "\nAll collected files are in $OUTPUTDIR\n\n"
elif [[ $ON_OFF == "5" ]]; then
get_bgppeers
collect_debug
get_cpinfo
printf "\nAll collected files are in $OUTPUTDIR\n\n"
elif [[ $ON_OFF == "6" && $ISVSX -eq 1 ]]; then
printf "\n"
select_vs
questionnaire
elif [[ $ON_OFF == "q" ]]; then
if [[ ! $COLLECT -eq 1 && -d "$OUTPUTDIR" ]]; then
printf "\nRemoving temporary directory $OUTPUTDIR\n\n"
rm -rf $OUTPUTDIR
fi
exit 0
else
printf "\n\nERROR: $ON_OFF is not a valid selection\n\n"
questionnaire
fi
}
debug_on () {
if [[ $ISVSX -eq 1 ]]; then
printf "Enabling BGP and RouteD debug for VS$VIRTUAL_SYSTEM\n"
DEBUG_ON_SCRIPT=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"_DEBUG_ENABLE.clish"
echo "set virtual-system $VIRTUAL_SYSTEM" >$DEBUG_ON_SCRIPT
else
printf "Enabling BGP and RouteD debug\n"
DEBUG_ON_SCRIPT="$OUTPUTDIR/DEBUG_ENABLE.clish"
if [ -f "$DEBUG_ON_SCRIPT" ]; then
rm $DEBUG_ON_SCRIPT
touch $DEBUG_ON_SCRIPT
fi
fi
echo "set tracefile size 10" >>$DEBUG_ON_SCRIPT
echo "set tracefile maxnum 20" >>$DEBUG_ON_SCRIPT
echo "set trace kernel all on" >>$DEBUG_ON_SCRIPT
echo "set trace bgp all on" >>$DEBUG_ON_SCRIPT
echo "save config" >>$DEBUG_ON_SCRIPT
clish -i -f $DEBUG_ON_SCRIPT
rm $DEBUG_ON_SCRIPT
show_debug_status
}
debug_off () {
if [[ $ISVSX -eq 1 ]]; then
printf "Disabling BGP and RouteD debug for VS$VIRTUAL_SYSTEM\n"
DEBUG_OFF_SCRIPT=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"_DEBUG_DISABLE.clish"
echo "set virtual-system $VIRTUAL_SYSTEM" >$DEBUG_OFF_SCRIPT
else
printf "Disabling BGP and RouteD debug\n"
DEBUG_OFF_SCRIPT="$OUTPUTDIR/DEBUG_DISABLE.clish"
if [ -f "$DEBUG_OFF_SCRIPT" ]; then
rm $DEBUG_OFF_SCRIPT
touch $DEBUG_OFF_SCRIPT
fi
fi
echo "set trace kernel all off" >>$DEBUG_OFF_SCRIPT
echo "set trace bgp all off" >>$DEBUG_OFF_SCRIPT
echo "save config" >>$DEBUG_OFF_SCRIPT
clish -f $DEBUG_OFF_SCRIPT
rm $DEBUG_OFF_SCRIPT
show_debug_status
}
show_debug_status () {
if [[ $ISVSX -eq 1 ]]; then
printf "\n"
vsenv $VIRTUAL_SYSTEM
fi
printf "\n"
dbget -rv routed | grep traceoptions
printf "\n\n"
questionnaire
}
get_bgppeers () {
if [[ $ISVSX -eq 1 ]]; then
GET_BGP_SCRIPT=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"_GET_BGP_PEERS.clish"
BGP_OUTPUT_TMP=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"bgppeers.tmp"
BGP_OUTPUT=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"bgppeers.txt"
echo "set virtual-system $VIRTUAL_SYSTEM" >$GET_BGP_SCRIPT
else
GET_BGP_SCRIPT="$OUTPUTDIR/GET_BGP_PEERS.clish"
if [ -f "$GET_BGP_SCRIPT" ]; then
rm $GET_BGP_SCRIPT
touch $GET_BGP_SCRIPT
fi
BGP_OUTPUT_TMP="$OUTPUTDIR/bgppeers.tmp"
if [ -f "$BGP_OUTPUT_TMP" ]; then
rm $BGP_OUTPUT_TMP
touch $BGP_OUTPUT_TMP
fi
BGP_OUTPUT="$OUTPUTDIR/bgppeers.txt"
if [ -f "$BGP_OUTPUT" ]; then
rm $BGP_OUTPUT
touch $BGP_OUTPUT
fi
fi
echo "show configuration bgp" >>$GET_BGP_SCRIPT
clish -i -f $GET_BGP_SCRIPT >$BGP_OUTPUT_TMP
grep peer $BGP_OUTPUT_TMP | sed 's/.*\(peer\)/\1/g' | awk '{ print $2 }' | uniq >$BGP_OUTPUT
}
collect_debug () {
if [[ $ISVSX -eq 1 ]]; then
printf "\nCollecting debug information for VS$VIRTUAL_SYSTEM\n\n"
COLLECT_SCRIPT=$OUTPUTDIR"/VS"$VIRTUAL_SYSTEM"_COLLECT_DEBUG.clish"
echo "set virtual-system $VIRTUAL_SYSTEM" >$COLLECT_SCRIPT
else
printf "\nCollecting debug information\n\n"
COLLECT_SCRIPT="$OUTPUTDIR/COLLECT_DEBUG.clish"
if [ -f "$COLLECT_SCRIPT" ]; then
rm $COLLECT_SCRIPT
touch $COLLECT_SCRIPT
fi
fi
echo "show configuration bgp" >>$COLLECT_SCRIPT
echo "show bgp summary" >>$COLLECT_SCRIPT
echo "show bgp errors" >>$COLLECT_SCRIPT
echo "show bgp groups" >>$COLLECT_SCRIPT
echo "show bgp memory" >>$COLLECT_SCRIPT
echo "show bgp paths" >>$COLLECT_SCRIPT
echo "show bgp peers" >>$COLLECT_SCRIPT
echo "show bgp peers detailed" >>$COLLECT_SCRIPT
echo "show bgp peers established" >>$COLLECT_SCRIPT
while read PEER_IP_ADDRESS
do
echo "show bgp peer $PEER_IP_ADDRESS advertise" >>$COLLECT_SCRIPT
echo "show bgp peer $PEER_IP_ADDRESS detailed" >>$COLLECT_SCRIPT
echo "show bgp peer $PEER_IP_ADDRESS received" >>$COLLECT_SCRIPT
done < $BGP_OUTPUT
echo "show bgp routemap" >>$COLLECT_SCRIPT
echo "show route all bgp" >>$COLLECT_SCRIPT
echo "show route bgp" >>$COLLECT_SCRIPT
echo "show route bgp aspath" >>$COLLECT_SCRIPT
echo "show route bgp communities" >>$COLLECT_SCRIPT
echo "show route bgp detailed" >>$COLLECT_SCRIPT
echo "show route bgp metrics" >>$COLLECT_SCRIPT
echo "show route bgp suppressed" >>$COLLECT_SCRIPT
echo "show route inactive bgp" >>$COLLECT_SCRIPT
if [[ $ISVSX -eq 1 ]]; then
CLISH_OUTPUT_TMP=$OUTPUTDIR/"VS"$VIRTUAL_SYSTEM"_CLISH_OUTPUT.tmp"
CLISH_OUTPUT=$OUTPUTDIR/"VS"$VIRTUAL_SYSTEM"_CLISH_OUTPUT.log"
clish -i -o pretty -f $COLLECT_SCRIPT >$CLISH_OUTPUT_TMP
tr "\015" "\n" <$CLISH_OUTPUT_TMP >$CLISH_OUTPUT
cp -p /var/log/routed_$VIRTUAL_SYSTEM.lo* $OUTPUTDIR
vsenv
cp -p $CPDIR/log/cpwd.el* $OUTPUTDIR
else
CLISH_OUTPUT_TMP="$OUTPUTDIR/CLISH_OUTPUT.tmp"
CLISH_OUTPUT="$OUTPUTDIR/CLISH_OUTPUT.log"
clish -i -o pretty -f $COLLECT_SCRIPT >$CLISH_OUTPUT_TMP
tr "\015" "\n" <$CLISH_OUTPUT_TMP >$CLISH_OUTPUT
cp -p /var/log/routed.lo* $OUTPUTDIR
fi
cp -p /var/log/message* $OUTPUTDIR
rm $CLISH_OUTPUT_TMP
rm $GET_BGP_SCRIPT
rm $BGP_OUTPUT_TMP
rm $BGP_OUTPUT
rm $COLLECT_SCRIPT
COLLECT=1
}
get_cpinfo () {
printf "Collecting CPinfo file\n"
cpinfo -D -z -o $OUTPUTDIR/$(uname -n)_BGP_issue.cpinfo
}
#Start
mkdir -p $OUTPUTDIR
gw_type_check
questionnaire
exit 0