blob: 42cf505a14e088d5780dda585640d8869c0ef9d5 [file] [log] [blame]
Thomas Vachuskab1702072018-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() {
23 echo "usage: $(basename $0) [-x] [-n name] [-u user] [-p password] [ip1 ip2...]"
24 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
Charles Chan22433232018-03-08 14:59:42 -080053# TODO We should make SR commands optional
Thomas Vachuskab1702072018-01-30 13:57:38 -080054CLI_COMMANDS=(
Thomas Vachuskab8319112018-02-01 15:52:10 -080055 "feature:repo-list"
Thomas Vachuskab1702072018-01-30 13:57:38 -080056 "feature:list"
57 "bundle:list"
58 "scr:list"
59
60 "summary"
61 "nodes"
62 "apps -s"
63 "netcfg"
64 "cfg get"
65
66 "devices"
67 "links"
68 "hosts"
69
70 "ports -e"
71 "portstats -nz"
72
73 "intents"
74 "flows -s"
75 "groups"
76
77 "roles"
78 "masters"
79
Charles Chan22433232018-03-08 14:59:42 -080080 "fpm-connections"
Thomas Vachuskab1702072018-01-30 13:57:38 -080081 "routes"
82 "obj-next-ids"
83 "obj-pending-nexts"
84
Charles Chan22433232018-03-08 14:59:42 -080085 "sr-device-subnets"
86 "sr-ecmp-spg"
87 "sr-link-state"
88 "sr-mcast-next"
89 "sr-mcast-tree"
90 "sr-next-hops"
91 "pseudowires"
92 "dhcp-relay"
Thomas Vachuskab1702072018-01-30 13:57:38 -080093)
94
95# Scan arguments for user/password or other options...
96while getopts n:u:p:x?h o; do
97 case "$o" in
98 n) name=$OPTARG;;
99 u) user=$OPTARG;;
100 p) password=$OPTARG;;
101 x) extract=true;;
102 *) usage;;
103 esac
104done
105ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
106ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
107user=${user:-$ONOS_WEB_USER}
108password=${password:-$ONOS_WEB_PASS}
109let OPC=$OPTIND-1
110shift $OPC
111
112[ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage;
113
114diags=/tmp/${name:-onos}-diags
115rm -fr $diags $diags.tar.gz; mkdir -p $diags
116
117[ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$*
118
119# Collect diagnostics from each cluster node
120for node in $nodes; do
121 printf "Collecting diagnostics on $node..."
122
123 # Prepare a clean place for collecting the node diagnostic data
124 cd $diags; rm -fr $node; mkdir -p $node; cd $node;
125
126 # Acquire locally obtained diagnostics via REST API and extract them
127 printf "logs "
128 curl -sS --fail --user $user:$password \
129 http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz
130 tar zxf ../$node.tar.gz
131
132 # Acquire remotely obtained diagnostics via ssh CLI
133 for cmd in "${CLI_COMMANDS[@]}"; do
134 cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt"
135 printf "$cmdLog "
136 onos $node $cmd 2>/dev/null >$cmdLog
137 done
138
139 # Tar-up local and remote diagnostics together
140 printf " Done.\n"
141 tar zcf ../$node.tar.gz *
142done
143
144# Tar-up diagnostics from all the nodes
145cd $diags
146tar zcf $diags.tar.gz *
147[ -z $extract ] && rm -fr $diags