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