blob: 0daa320cec75239a2b498510d51d225fdf5a6853 [file] [log] [blame]
Thomas Vachuska15370d22018-01-30 13:57:38 -08001#!/bin/bash
2
3#
4# Copyright 2015-present Open Networking Foundation
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19# -----------------------------------------------------------------------------
20# Tool to collect cluster-wide diagnostics into a single tar stream.
21# -----------------------------------------------------------------------------
22function usage() {
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080023 echo "usage: $(basename $0) [-x] [-j] [-n name] [-P port] [-u user] [-p password] [ip1 ip2...]"
Thomas Vachuska15370d22018-01-30 13:57:38 -080024 echo ""
25 echo "Environment Variables:"
26 echo " ONOS_INSTANCES IPs or hostnames of ONOS cluster machines"
27 echo " ONOS_WEB_USER username for REST API"
28 echo " ONOS_WEB_PASS password for REST API"
29 echo ""
30 echo "Example Usages:"
31 echo " # Collect compressed diagnostics for the cluster."
32 echo " # REST API user and password are drawn from environment variables."
33 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
34 echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable."
35 echo " > $(basename $0) "
36 echo ""
37 echo " # Collect diagnostics for the cluster and leave them extracted. "
38 echo " # Collection directory will be named /tmp/prague-diags/"
39 echo " # Collection archive will be named /tmp/prague-diags.tar.gz."
40 echo " # REST API user name is 'onos' and password is 'rules'."
41 echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable."
42 echo " > $(basename $0) -x -n prague -u onos -p rules"
43 echo ""
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080044 echo " # Collect diagnostics for the cluster and store them in JSON files."
45 echo " # JSON_CLI_COMMANDS below lists JSON-supported diagnostics commands."
46 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
47 echo " > $(basename $0) -j"
48 echo ""
Thomas Vachuska15370d22018-01-30 13:57:38 -080049 echo " # Collect compressed diagnostics for a cluster."
50 echo " # REST API user name is 'onos' and password is 'rules'."
51 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
52 echo " # The cluster node IPs are listed explicitly."
53 echo " > $(basename $0) -u onos -p rules 172.17.0.11 172.17.0.12 172.17.0.13"
54
55 exit 1
56}
57
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070058ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
59ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
60ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181'
61
62. $(dirname $0)/_find-node
63
Charles Chanc6576fa2018-03-08 14:59:42 -080064# TODO We should make SR commands optional
Thomas Vachuska15370d22018-01-30 13:57:38 -080065CLI_COMMANDS=(
Thomas Vachuskaa40aa0b2018-02-01 15:52:10 -080066 "feature:repo-list"
Thomas Vachuska15370d22018-01-30 13:57:38 -080067 "feature:list"
68 "bundle:list"
Charles Chandc77af52019-02-12 17:47:41 -080069 "scr-list"
Thomas Vachuska15370d22018-01-30 13:57:38 -080070
71 "summary"
72 "nodes"
73 "apps -s"
74 "netcfg"
75 "cfg get"
76
77 "devices"
Seyeon Jeong80a62462020-03-10 17:41:14 -070078 "device-drivers"
Thomas Vachuska15370d22018-01-30 13:57:38 -080079 "links"
80 "hosts"
Pier4099f052018-04-05 20:45:40 +020081 "interfaces"
Thomas Vachuska15370d22018-01-30 13:57:38 -080082
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080083 "ports"
Thomas Vachuska15370d22018-01-30 13:57:38 -080084 "portstats -nz"
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080085 "edge-ports"
Thomas Vachuska15370d22018-01-30 13:57:38 -080086
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080087 "packet-processors"
88 "packet-requests"
89
Thomas Vachuska15370d22018-01-30 13:57:38 -080090 "intents"
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080091 "flows"
Thomas Vachuska15370d22018-01-30 13:57:38 -080092 "groups"
93
94 "roles"
95 "masters"
96
Pierb1858582018-05-02 13:31:12 +020097 "maps"
98
Charles Chanc6576fa2018-03-08 14:59:42 -080099 "fpm-connections"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800100 "routes"
101 "obj-next-ids"
102 "obj-pending-nexts"
Charles Chan8b7df412018-04-24 10:23:21 -0700103 "obj-queues"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800104
Charles Chanc6576fa2018-03-08 14:59:42 -0800105 "sr-device-subnets"
106 "sr-ecmp-spg"
Charles Chan8bc75ee2018-04-17 18:56:53 -0700107 "sr-should-program"
Charles Chanc6576fa2018-03-08 14:59:42 -0800108 "sr-link-state"
Charles Chanc6576fa2018-03-08 14:59:42 -0800109 "sr-mcast-tree"
Pier954b3682018-04-18 08:50:29 +0200110 "sr-mcast-leader"
Pierb1858582018-05-02 13:31:12 +0200111 "sr-mcast-role"
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -0700112 "sr-pw-list"
Charles Chan3fe60be2018-10-26 15:54:32 -0700113 "sr-next-mcast"
Harshada Chaundkarb42abd42019-07-02 16:01:24 +0000114 "sr-filt-mcast"
Charles Chan3fe60be2018-10-26 15:54:32 -0700115 "sr-next-dst"
116 "sr-next-port"
117 "sr-next-vlan"
118 "sr-next-pw"
119 "sr-next-xconnect"
Ruchi Sahotaef0761c2019-01-28 01:08:18 +0000120 "sr-next-mac-vlan"
Charles Chanc6576fa2018-03-08 14:59:42 -0800121 "dhcp-relay"
Pier4099f052018-04-05 20:45:40 +0200122
123 "mcast-host-routes"
124 "mcast-host-show"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800125)
126
Seyeon Jeong8d3cad22020-02-28 01:17:34 -0800127JSON_CLI_COMMANDS=(
128 "netcfg -j"
129 "devices -j"
130 "device-drivers -j"
131 "links -j"
132 "hosts -j"
133 "ports -j"
134 "edge-ports -j"
135 "flows -j"
136 "groups -j"
137 "masters -j"
138 "routes -j"
139 "mcast-host-show -j"
140)
141
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700142port=${ONOS_WEB_PORT}
143user=${ONOS_WEB_USER}
144password=${ONOS_WEB_PASS}
145
Thomas Vachuska15370d22018-01-30 13:57:38 -0800146# Scan arguments for user/password or other options...
Seyeon Jeong8d3cad22020-02-28 01:17:34 -0800147while getopts n:P:u:p:x?j?h o; do
Thomas Vachuska15370d22018-01-30 13:57:38 -0800148 case "$o" in
149 n) name=$OPTARG;;
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700150 P) port=$OPTARG;;
Thomas Vachuska15370d22018-01-30 13:57:38 -0800151 u) user=$OPTARG;;
152 p) password=$OPTARG;;
153 x) extract=true;;
Seyeon Jeong8d3cad22020-02-28 01:17:34 -0800154 j) json=true;;
Thomas Vachuska15370d22018-01-30 13:57:38 -0800155 *) usage;;
156 esac
157done
Thomas Vachuska7f2a3562018-02-28 10:02:16 -0800158
Thomas Vachuska15370d22018-01-30 13:57:38 -0800159let OPC=$OPTIND-1
160shift $OPC
161
162[ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage;
163
164diags=/tmp/${name:-onos}-diags
165rm -fr $diags $diags.tar.gz; mkdir -p $diags
166
167[ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$*
168
169# Collect diagnostics from each cluster node
170for node in $nodes; do
171 printf "Collecting diagnostics on $node..."
172
173 # Prepare a clean place for collecting the node diagnostic data
174 cd $diags; rm -fr $node; mkdir -p $node; cd $node;
175
176 # Acquire locally obtained diagnostics via REST API and extract them
177 printf "logs "
178 curl -sS --fail --user $user:$password \
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700179 http://$node:$port/onos/v1/diagnostics > ../$node.tar.gz
Thomas Vachuska7f2a3562018-02-28 10:02:16 -0800180 tar zxf ../$node.tar.gz && rm ../$node.tar.gz
Thomas Vachuska15370d22018-01-30 13:57:38 -0800181
182 # Acquire remotely obtained diagnostics via ssh CLI
Seyeon Jeong8d3cad22020-02-28 01:17:34 -0800183 [ ! -z $json ] && CLI_COMMANDS=("${JSON_CLI_COMMANDS[@]}")
Thomas Vachuska15370d22018-01-30 13:57:38 -0800184 for cmd in "${CLI_COMMANDS[@]}"; do
185 cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt"
Seyeon Jeong8d3cad22020-02-28 01:17:34 -0800186 [ ! -z $json ] && cmdLog="${cmdLog%.txt}.json"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800187 printf "$cmdLog "
188 onos $node $cmd 2>/dev/null >$cmdLog
189 done
190
Thomas Vachuska15370d22018-01-30 13:57:38 -0800191 printf " Done.\n"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800192done
193
194# Tar-up diagnostics from all the nodes
195cd $diags
196tar zcf $diags.tar.gz *
197[ -z $extract ] && rm -fr $diags