blob: 2ac2310c3660cb4fa806bed8a89cde8596377530 [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() {
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070023 echo "usage: $(basename $0) [-x] [-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 ""
44 echo " # Collect compressed diagnostics for a cluster."
45 echo " # REST API user name is 'onos' and password is 'rules'."
46 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
47 echo " # The cluster node IPs are listed explicitly."
48 echo " > $(basename $0) -u onos -p rules 172.17.0.11 172.17.0.12 172.17.0.13"
49
50 exit 1
51}
52
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070053ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
54ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
55ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181'
56
57. $(dirname $0)/_find-node
58
Charles Chanc6576fa2018-03-08 14:59:42 -080059# TODO We should make SR commands optional
Thomas Vachuska15370d22018-01-30 13:57:38 -080060CLI_COMMANDS=(
Thomas Vachuskaa40aa0b2018-02-01 15:52:10 -080061 "feature:repo-list"
Thomas Vachuska15370d22018-01-30 13:57:38 -080062 "feature:list"
63 "bundle:list"
Charles Chandc77af52019-02-12 17:47:41 -080064 "scr-list"
Thomas Vachuska15370d22018-01-30 13:57:38 -080065
66 "summary"
67 "nodes"
68 "apps -s"
69 "netcfg"
70 "cfg get"
71
72 "devices"
Seyeon Jeong7812deb2020-03-10 17:41:14 -070073 "device-drivers"
Thomas Vachuska15370d22018-01-30 13:57:38 -080074 "links"
75 "hosts"
Pier4099f052018-04-05 20:45:40 +020076 "interfaces"
Thomas Vachuska15370d22018-01-30 13:57:38 -080077
78 "ports -e"
79 "portstats -nz"
80
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080081 "packet-processors"
82 "packet-requests"
83
Thomas Vachuska15370d22018-01-30 13:57:38 -080084 "intents"
85 "flows -s"
86 "groups"
87
88 "roles"
89 "masters"
90
Pierb1858582018-05-02 13:31:12 +020091 "maps"
92
Charles Chanc6576fa2018-03-08 14:59:42 -080093 "fpm-connections"
Thomas Vachuska15370d22018-01-30 13:57:38 -080094 "routes"
95 "obj-next-ids"
96 "obj-pending-nexts"
Charles Chan8b7df412018-04-24 10:23:21 -070097 "obj-queues"
Thomas Vachuska15370d22018-01-30 13:57:38 -080098
Charles Chanc6576fa2018-03-08 14:59:42 -080099 "sr-device-subnets"
100 "sr-ecmp-spg"
Charles Chan8bc75ee2018-04-17 18:56:53 -0700101 "sr-should-program"
Charles Chanc6576fa2018-03-08 14:59:42 -0800102 "sr-link-state"
Charles Chanc6576fa2018-03-08 14:59:42 -0800103 "sr-mcast-tree"
Pier954b3682018-04-18 08:50:29 +0200104 "sr-mcast-leader"
Pierb1858582018-05-02 13:31:12 +0200105 "sr-mcast-role"
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -0700106 "sr-pw-list"
Charles Chan3fe60be2018-10-26 15:54:32 -0700107 "sr-next-mcast"
Harshada Chaundkar4c73fe22019-07-02 16:01:24 +0000108 "sr-filt-mcast"
Charles Chan3fe60be2018-10-26 15:54:32 -0700109 "sr-next-dst"
110 "sr-next-port"
111 "sr-next-vlan"
112 "sr-next-pw"
113 "sr-next-xconnect"
Ruchi Sahotaef0761c2019-01-28 01:08:18 +0000114 "sr-next-mac-vlan"
Charles Chanc6576fa2018-03-08 14:59:42 -0800115 "dhcp-relay"
Pier4099f052018-04-05 20:45:40 +0200116
117 "mcast-host-routes"
118 "mcast-host-show"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800119)
120
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700121port=${ONOS_WEB_PORT}
122user=${ONOS_WEB_USER}
123password=${ONOS_WEB_PASS}
124
Thomas Vachuska15370d22018-01-30 13:57:38 -0800125# Scan arguments for user/password or other options...
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700126while getopts n:P:u:p:x?h o; do
Thomas Vachuska15370d22018-01-30 13:57:38 -0800127 case "$o" in
128 n) name=$OPTARG;;
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700129 P) port=$OPTARG;;
Thomas Vachuska15370d22018-01-30 13:57:38 -0800130 u) user=$OPTARG;;
131 p) password=$OPTARG;;
132 x) extract=true;;
133 *) usage;;
134 esac
135done
Thomas Vachuska7f2a3562018-02-28 10:02:16 -0800136
Thomas Vachuska15370d22018-01-30 13:57:38 -0800137let OPC=$OPTIND-1
138shift $OPC
139
140[ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage;
141
142diags=/tmp/${name:-onos}-diags
143rm -fr $diags $diags.tar.gz; mkdir -p $diags
144
145[ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$*
146
147# Collect diagnostics from each cluster node
148for node in $nodes; do
149 printf "Collecting diagnostics on $node..."
150
151 # Prepare a clean place for collecting the node diagnostic data
152 cd $diags; rm -fr $node; mkdir -p $node; cd $node;
153
154 # Acquire locally obtained diagnostics via REST API and extract them
155 printf "logs "
156 curl -sS --fail --user $user:$password \
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -0700157 http://$node:$port/onos/v1/diagnostics > ../$node.tar.gz
Thomas Vachuska7f2a3562018-02-28 10:02:16 -0800158 tar zxf ../$node.tar.gz && rm ../$node.tar.gz
Thomas Vachuska15370d22018-01-30 13:57:38 -0800159
160 # Acquire remotely obtained diagnostics via ssh CLI
161 for cmd in "${CLI_COMMANDS[@]}"; do
162 cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt"
163 printf "$cmdLog "
164 onos $node $cmd 2>/dev/null >$cmdLog
165 done
166
Thomas Vachuska15370d22018-01-30 13:57:38 -0800167 printf " Done.\n"
Thomas Vachuska15370d22018-01-30 13:57:38 -0800168done
169
170# Tar-up diagnostics from all the nodes
171cd $diags
172tar zcf $diags.tar.gz *
173[ -z $extract ] && rm -fr $diags