-
Notifications
You must be signed in to change notification settings - Fork 7
/
vrouter_jtac_rsi.sh
145 lines (127 loc) · 4.25 KB
/
vrouter_jtac_rsi.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
#!/bin/bash
# Basic bash script to collect common files and outputs JTAC requests for opening contrail issues.
# Debug commands
#set -x
# Variables
work_directory=/tmp/jtac_rsi
# Array of contrail containers
containers=(
vrouter_vrouter-agent_1
vrouter_nodemgr_1
)
logs_local=(
/var/log/contrail
)
configs_local=(
/etc/contrail
)
# This directory will be copied from containers as well as host filesystem
crashes=(
/var/crashes
)
# Array of commands to collect CLI output for troubleshooting
commands=(
"uptime"
"cat /etc/redhat-release"
"uname -a"
"free -mh"
"df -h"
"cat /proc/cpuinfo"
"ifconfig"
"iptables -L"
"contrail-status"
"docker ps|grep contrail"
"ls -alh /var/crashes"
"ulimit -a"
"netstat -pantu"
"lsmod | grep vr"
"docker exec vrouter_vrouter-agent_1 vrouter --info"
"docker exec vrouter_vrouter-agent_1 vif --list"
"docker exec vrouter_vrouter-agent_1 flow -l"
"docker exec vrouter_vrouter-agent_1 dropstats"
"docker exec vrouter_vrouter-agent_1 mpls --dump"
"docker exec vrouter_vrouter-agent_1 nh --list"
)
# Additional commands to run with -x option
extra_commands=(
"lscpu"
"lsof"
"ntpq -p"
"curl -s http://localhost:8085/Snh_AgentXmppConnectionStatusReq?"
)
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Usage: $(basename $0) [-h] [-x]"
echo " -h: this help message"
echo " -x: collect extra info (hw info, contrail sandesh info, etc.)"
exit 0
fi
if [ "$1" == "-x" ]; then
commands=("${commands[@]}" "${extra_commands[@]}")
fi
# Prep work folder to store and compress support information
printf "Creating work folder at $work_directory..."
mkdir $work_directory
printf "Done! \n"
# Create log for CLI outputs
printf "Creating cli output file at $work_directory/cli_output.log..."
touch $work_directory/cli_output.log
printf "Done! \n"
# Commonly run server CLI command outputs
for cli in "${commands[@]}"; do
printf "Gathering output from '$cli'..."
echo "# $cli" >> $work_directory/cli_output.log
eval $cli >> $work_directory/cli_output.log
echo -e "\n\n########################################\\n########################################\\n\n" >> $work_directory/cli_output.log
printf "Done! \n"
done
# Gather docker logs
for container in "${containers[@]}"; do
printf "Gathering docker logs for container $container..."
mkdir -p $work_directory/$container/logs
docker logs $container &> $work_directory/$container/logs/${container}.log
printf "Done! \n"
done
# Gather host filesystem logs
for directory in "${logs_local[@]}"; do
printf "Gathering host filesystem logs at $directory..."
mkdir -p $work_directory/$directory
cp -Lrf $directory $work_directory/$directory
printf "Done! \n"
done
# Configs from host filesystem
for directory in "${configs_local[@]}"; do
printf "Copying configs from $directory..."
mkdir -p $work_directory/$directory
cp -Lrf $directory/* $work_directory/$directory/
printf "Done! \n"
done
# Move all crashes to temp directory for later compressing
printf "Copying crash files from containers (if any)..."
for container in "${containers[@]}"; do
for directory in "${crashes[@]}"; do
# If directory exists and is not empty
if docker exec $container find $directory -mindepth 1 2> /dev/null | read; then
## Skip iteration if directory does not exist or is empty
mkdir -p $work_directory/$container/$directory
docker cp $container:$directory $work_directory/$container/$(dirname $directory)
fi
done
done
printf "Done! \n"
for directory in "${crashes[@]}"; do
printf "Copying crash files files from host filesystem $directory..."
if [ -z "$(ls -A $directory)" ]; then
printf "Empty Directory! \n"
else
mkdir -p $work_directory/$directory
mv -f $directory/* $work_directory/$directory
printf "Done! \n"
fi
done
# Compress RSI folder
# DO NOT use bzip2 (-j option to tar); it will kill Chemtrails. See RCE-2145
printf "Compressing all collected data and saving to /tmp/$(date +%Y%m%d)-$HOSTNAME-RSI.tar.gz..."
cd $work_directory && tar -czf /tmp/$(date +%Y%m%d)-$HOSTNAME-RSI.tar.gz . &>/dev/null
printf "Done! \n"
# Cleanup mess
rm -rf $work_directory