Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 1 | #!/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 | # ----------------------------------------------------------------------------- |
| 22 | function usage() { |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 23 | echo "usage: $(basename $0) [-x] [-n name] [-P port] [-u user] [-p password] [ip1 ip2...]" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 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 | |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 53 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 54 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 55 | ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181' |
| 56 | |
| 57 | . $(dirname $0)/_find-node |
| 58 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 59 | # TODO We should make SR commands optional |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 60 | CLI_COMMANDS=( |
Thomas Vachuska | a40aa0b | 2018-02-01 15:52:10 -0800 | [diff] [blame] | 61 | "feature:repo-list" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 62 | "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" |
Pier | 4099f05 | 2018-04-05 20:45:40 +0200 | [diff] [blame] | 75 | "interfaces" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 76 | |
| 77 | "ports -e" |
| 78 | "portstats -nz" |
| 79 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 80 | "packet-processors" |
| 81 | "packet-requests" |
| 82 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 83 | "intents" |
| 84 | "flows -s" |
| 85 | "groups" |
| 86 | |
| 87 | "roles" |
| 88 | "masters" |
| 89 | |
Pier | b185858 | 2018-05-02 13:31:12 +0200 | [diff] [blame] | 90 | "maps" |
| 91 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 92 | "fpm-connections" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 93 | "routes" |
| 94 | "obj-next-ids" |
| 95 | "obj-pending-nexts" |
Charles Chan | 8b7df41 | 2018-04-24 10:23:21 -0700 | [diff] [blame] | 96 | "obj-queues" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 97 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 98 | "sr-device-subnets" |
| 99 | "sr-ecmp-spg" |
Charles Chan | 8bc75ee | 2018-04-17 18:56:53 -0700 | [diff] [blame] | 100 | "sr-should-program" |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 101 | "sr-link-state" |
| 102 | "sr-mcast-next" |
| 103 | "sr-mcast-tree" |
Pier | 954b368 | 2018-04-18 08:50:29 +0200 | [diff] [blame] | 104 | "sr-mcast-leader" |
Pier | b185858 | 2018-05-02 13:31:12 +0200 | [diff] [blame] | 105 | "sr-mcast-role" |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 106 | "sr-next-hops" |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 107 | "sr-pw-list" |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 108 | "dhcp-relay" |
Pier | 4099f05 | 2018-04-05 20:45:40 +0200 | [diff] [blame] | 109 | |
| 110 | "mcast-host-routes" |
| 111 | "mcast-host-show" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 112 | ) |
| 113 | |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 114 | port=${ONOS_WEB_PORT} |
| 115 | user=${ONOS_WEB_USER} |
| 116 | password=${ONOS_WEB_PASS} |
| 117 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 118 | # Scan arguments for user/password or other options... |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 119 | while getopts n:P:u:p:x?h o; do |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 120 | case "$o" in |
| 121 | n) name=$OPTARG;; |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 122 | P) port=$OPTARG;; |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 123 | u) user=$OPTARG;; |
| 124 | p) password=$OPTARG;; |
| 125 | x) extract=true;; |
| 126 | *) usage;; |
| 127 | esac |
| 128 | done |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 129 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 130 | let OPC=$OPTIND-1 |
| 131 | shift $OPC |
| 132 | |
| 133 | [ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage; |
| 134 | |
| 135 | diags=/tmp/${name:-onos}-diags |
| 136 | rm -fr $diags $diags.tar.gz; mkdir -p $diags |
| 137 | |
| 138 | [ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$* |
| 139 | |
| 140 | # Collect diagnostics from each cluster node |
| 141 | for node in $nodes; do |
| 142 | printf "Collecting diagnostics on $node..." |
| 143 | |
| 144 | # Prepare a clean place for collecting the node diagnostic data |
| 145 | cd $diags; rm -fr $node; mkdir -p $node; cd $node; |
| 146 | |
| 147 | # Acquire locally obtained diagnostics via REST API and extract them |
| 148 | printf "logs " |
| 149 | curl -sS --fail --user $user:$password \ |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 150 | http://$node:$port/onos/v1/diagnostics > ../$node.tar.gz |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 151 | tar zxf ../$node.tar.gz && rm ../$node.tar.gz |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 152 | |
| 153 | # Acquire remotely obtained diagnostics via ssh CLI |
| 154 | for cmd in "${CLI_COMMANDS[@]}"; do |
| 155 | cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt" |
| 156 | printf "$cmdLog " |
| 157 | onos $node $cmd 2>/dev/null >$cmdLog |
| 158 | done |
| 159 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 160 | printf " Done.\n" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 161 | done |
| 162 | |
| 163 | # Tar-up diagnostics from all the nodes |
| 164 | cd $diags |
| 165 | tar zcf $diags.tar.gz * |
| 166 | [ -z $extract ] && rm -fr $diags |