-
Notifications
You must be signed in to change notification settings - Fork 7
/
render-network-info
executable file
·146 lines (95 loc) · 2.68 KB
/
render-network-info
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
code () {
local indent=${1:-4}
local str
str=$(printf "%${indent}s")
sed "s/^/$str/"
}
# This mess builds our table of contents for us. While some
# markdown implementations have toc generation capabilities, not
# all do, and we want our output to be self-contained.
header () {
local level=$1
local title=$2
local ns=$3
local hdr
local stub
# Converts something like "A name with 'spaces' and punctuation"
# into something like "a-name-with-spaces-and-punctuation".
hdr=$(printf "%${level}s" | tr ' ' '#')
stub=$(tr -dc '[a-zA-Z0-9 -]' <<< $title)
stub=${stub// /-}
stub=${stub,,}
stub="${ns:+$ns-}$stub"
echo "<a name=\"$stub\"></a>"
echo "$hdr $title"
local indent
indent=$(echo $hdr | sed 's/.//' | sed 's/./ /g')
echo "${indent}- [$title](#$stub)" >> $toc
}
if [[ $# -lt 1 ]]; then
echo "ERROR: you must provide the name of an archive" >&2
exit 1
fi
archive=$1
if ! [[ -f $archive ]]; then
echo "ERROR: archive $archive does not exist" >&2
exit 1
fi
head=$(mktemp headXXXXXX)
toc=$(mktemp tocXXXXXX)
body=$(mktemp bodyXXXXXX)
trap 'rm -f $head $toc $body' EXIT
# Extract hostname from archive
hostname=$(tar -xO -f $archive '*/hostname.txt')
cat > $head <<EOF
# Namespace survey for $hostname
EOF
cat <<EOF >> $body
$(header 2 OVS)
$(header 3 "ovs-vsctl show")
$(tar -xO -f $archive '*/ovs-vsctl-show.txt' | code )
$(header 3 "ovs-dptctl show")
$(tar -xO -f $archive '*/ovs-dpctl-show.txt' | code )
EOF
tar -xO -f $archive '*/ovs-bridges.txt' |
while read brdev; do
cat <<-EOF >>$body
$(header 3 "ovs-ofctl dump-flows $brdev")
$(tar -xO -f $archive "*/ovs-ofctl-dump-flows-${brdev}.txt" | code)
EOF
done
tar -xO -f $archive '*/namespace-active.txt' | sort |
while read ns; do
cat <<-EOF >>$body
$(header 2 "namespace $ns")
$(header 3 "interfaces" $ns)
EOF
tar -t -f $archive "*/$ns/interfaces/*" | sort | while read path; do
iface=${path##*/}
iface=${iface%.txt}
cat <<-EOF >>$body
- $iface
$(tar -xO -f $archive $path | code 8)
EOF
done
cat <<-EOF >>$body
$(header 3 routes $ns)
$(tar -xO -f $archive "*/$ns/routes.txt" | code)
$(header 3 "iptables: filter" $ns)
$(tar -xO -f $archive "*/$ns/iptables/filter.txt" | code)
$(header 3 "iptables: nat" $ns)
$(tar -xO -f $archive "*/$ns/iptables/nat.txt" | code)
$(header 3 "connections: tcp" $ns)
$(tar -xO -f $archive "*/$ns/connections/tcp.txt" | code)
$(header 3 "connections: udp" $ns)
$(tar -xO -f $archive "*/$ns/connections/udp.txt" | code)
EOF
if tar -t -f $archive "*/$ns/processes.txt" > /dev/null 2>&1; then
cat <<-EOF >>$body
$(header 3 processes $ns)
$(tar -xO -f $archive "*/$ns/processes.txt" | code)
EOF
fi
done
cat $head $toc $body