blob: 9cccb0e7a1a392d606fed923e35c695d9e29e42f [file] [log] [blame]
Thomas Vachuskaaf0cf7a2018-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# -----------------------------------------------------------------------------
Thomas Vachuskabee8a912018-02-28 10:02:16 -080022
23ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
24ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
25
26. $(dirname $0)/_find-node
27
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080028function usage() {
29 echo "usage: $(basename $0) [-x] [-n name] [-u user] [-p password] [ip1 ip2...]"
30 echo ""
31 echo "Environment Variables:"
32 echo " ONOS_INSTANCES IPs or hostnames of ONOS cluster machines"
33 echo " ONOS_WEB_USER username for REST API"
34 echo " ONOS_WEB_PASS password for REST API"
35 echo ""
36 echo "Example Usages:"
37 echo " # Collect compressed diagnostics for the cluster."
38 echo " # REST API user and password are drawn from environment variables."
39 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
40 echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable."
41 echo " > $(basename $0) "
42 echo ""
43 echo " # Collect diagnostics for the cluster and leave them extracted. "
44 echo " # Collection directory will be named /tmp/prague-diags/"
45 echo " # Collection archive will be named /tmp/prague-diags.tar.gz."
46 echo " # REST API user name is 'onos' and password is 'rules'."
47 echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable."
48 echo " > $(basename $0) -x -n prague -u onos -p rules"
49 echo ""
50 echo " # Collect compressed diagnostics for a cluster."
51 echo " # REST API user name is 'onos' and password is 'rules'."
52 echo " # Collection archive will be named /tmp/onos-diags.tar.gz"
53 echo " # The cluster node IPs are listed explicitly."
54 echo " > $(basename $0) -u onos -p rules 172.17.0.11 172.17.0.12 172.17.0.13"
55
56 exit 1
57}
58
Charles Chan415bb232018-03-08 14:59:42 -080059# TODO We should make SR commands optional
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080060CLI_COMMANDS=(
Thomas Vachuskae99e7a32018-02-01 15:52:10 -080061 "feature:repo-list"
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080062 "feature:list"
63 "bundle:list"
64 "scr:list"
65
66 "summary"
67 "nodes"
68 "apps -s"
69 "netcfg"
70 "cfg get"
71
72 "devices"
73 "links"
74 "hosts"
Pier2d87c9f2018-04-05 20:45:40 +020075 "interfaces"
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080076
77 "ports -e"
78 "portstats -nz"
79
Thomas Vachuskabee8a912018-02-28 10:02:16 -080080 "packet-processors"
81 "packet-requests"
82
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080083 "intents"
84 "flows -s"
85 "groups"
86
87 "roles"
88 "masters"
89
Charles Chan415bb232018-03-08 14:59:42 -080090 "fpm-connections"
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -080091 "routes"
92 "obj-next-ids"
93 "obj-pending-nexts"
94
Charles Chan415bb232018-03-08 14:59:42 -080095 "sr-device-subnets"
96 "sr-ecmp-spg"
97 "sr-link-state"
98 "sr-mcast-next"
99 "sr-mcast-tree"
100 "sr-next-hops"
Andreas Pantelopoulosa1812332018-03-12 16:30:20 -0700101 "sr-pw-list"
Charles Chan415bb232018-03-08 14:59:42 -0800102 "dhcp-relay"
Pier2d87c9f2018-04-05 20:45:40 +0200103
104 "mcast-host-routes"
105 "mcast-host-show"
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -0800106)
107
108# Scan arguments for user/password or other options...
109while getopts n:u:p:x?h o; do
110 case "$o" in
111 n) name=$OPTARG;;
112 u) user=$OPTARG;;
113 p) password=$OPTARG;;
114 x) extract=true;;
115 *) usage;;
116 esac
117done
Thomas Vachuskabee8a912018-02-28 10:02:16 -0800118
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -0800119user=${user:-$ONOS_WEB_USER}
120password=${password:-$ONOS_WEB_PASS}
121let OPC=$OPTIND-1
122shift $OPC
123
124[ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage;
125
126diags=/tmp/${name:-onos}-diags
127rm -fr $diags $diags.tar.gz; mkdir -p $diags
128
129[ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$*
130
131# Collect diagnostics from each cluster node
132for node in $nodes; do
133 printf "Collecting diagnostics on $node..."
134
135 # Prepare a clean place for collecting the node diagnostic data
136 cd $diags; rm -fr $node; mkdir -p $node; cd $node;
137
138 # Acquire locally obtained diagnostics via REST API and extract them
139 printf "logs "
140 curl -sS --fail --user $user:$password \
141 http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz
Thomas Vachuskabee8a912018-02-28 10:02:16 -0800142 tar zxf ../$node.tar.gz && rm ../$node.tar.gz
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -0800143
144 # Acquire remotely obtained diagnostics via ssh CLI
145 for cmd in "${CLI_COMMANDS[@]}"; do
146 cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt"
147 printf "$cmdLog "
148 onos $node $cmd 2>/dev/null >$cmdLog
149 done
150
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -0800151 printf " Done.\n"
Thomas Vachuskaaf0cf7a2018-01-30 13:57:38 -0800152done
153
154# Tar-up diagnostics from all the nodes
155cd $diags
156tar zcf $diags.tar.gz *
157[ -z $extract ] && rm -fr $diags