blob: 442b1fd3391fadd55bb9b0a126b3a328eb138485 [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() {
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
53CLI_COMMANDS=(
Thomas Vachuskaa40aa0b2018-02-01 15:52:10 -080054 "feature:repo-list"
Thomas Vachuska15370d22018-01-30 13:57:38 -080055 "feature:list"
56 "bundle:list"
57 "scr:list"
58
59 "summary"
60 "nodes"
61 "apps -s"
62 "netcfg"
63 "cfg get"
64
65 "devices"
66 "links"
67 "hosts"
68
69 "ports -e"
70 "portstats -nz"
71
72 "intents"
73 "flows -s"
74 "groups"
75
76 "roles"
77 "masters"
78
79 "routes"
80 "obj-next-ids"
81 "obj-pending-nexts"
82
83 "log:display -l WARN"
84)
85
86# Scan arguments for user/password or other options...
87while getopts n:u:p:x?h o; do
88 case "$o" in
89 n) name=$OPTARG;;
90 u) user=$OPTARG;;
91 p) password=$OPTARG;;
92 x) extract=true;;
93 *) usage;;
94 esac
95done
96ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
97ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
98user=${user:-$ONOS_WEB_USER}
99password=${password:-$ONOS_WEB_PASS}
100let OPC=$OPTIND-1
101shift $OPC
102
103[ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage;
104
105diags=/tmp/${name:-onos}-diags
106rm -fr $diags $diags.tar.gz; mkdir -p $diags
107
108[ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$*
109
110# Collect diagnostics from each cluster node
111for node in $nodes; do
112 printf "Collecting diagnostics on $node..."
113
114 # Prepare a clean place for collecting the node diagnostic data
115 cd $diags; rm -fr $node; mkdir -p $node; cd $node;
116
117 # Acquire locally obtained diagnostics via REST API and extract them
118 printf "logs "
119 curl -sS --fail --user $user:$password \
120 http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz
121 tar zxf ../$node.tar.gz
122
123 # Acquire remotely obtained diagnostics via ssh CLI
124 for cmd in "${CLI_COMMANDS[@]}"; do
125 cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt"
126 printf "$cmdLog "
127 onos $node $cmd 2>/dev/null >$cmdLog
128 done
129
130 # Tar-up local and remote diagnostics together
131 printf " Done.\n"
132 tar zcf ../$node.tar.gz *
133done
134
135# Tar-up diagnostics from all the nodes
136cd $diags
137tar zcf $diags.tar.gz *
138[ -z $extract ] && rm -fr $diags