Thomas Vachuska | b170207 | 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() { |
| 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 Chan | 2243323 | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 53 | # TODO We should make SR commands optional |
Thomas Vachuska | b170207 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 54 | CLI_COMMANDS=( |
Thomas Vachuska | b831911 | 2018-02-01 15:52:10 -0800 | [diff] [blame] | 55 | "feature:repo-list" |
Thomas Vachuska | b170207 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 56 | "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 Chan | 2243323 | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 80 | "fpm-connections" |
Thomas Vachuska | b170207 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 81 | "routes" |
| 82 | "obj-next-ids" |
| 83 | "obj-pending-nexts" |
| 84 | |
Charles Chan | 2243323 | 2018-03-08 14:59:42 -0800 | [diff] [blame] | 85 | "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 Vachuska | b170207 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 93 | ) |
| 94 | |
| 95 | # Scan arguments for user/password or other options... |
| 96 | while 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 |
| 104 | done |
| 105 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 106 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 107 | user=${user:-$ONOS_WEB_USER} |
| 108 | password=${password:-$ONOS_WEB_PASS} |
| 109 | let OPC=$OPTIND-1 |
| 110 | shift $OPC |
| 111 | |
| 112 | [ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage; |
| 113 | |
| 114 | diags=/tmp/${name:-onos}-diags |
| 115 | rm -fr $diags $diags.tar.gz; mkdir -p $diags |
| 116 | |
| 117 | [ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$* |
| 118 | |
| 119 | # Collect diagnostics from each cluster node |
| 120 | for 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 * |
| 142 | done |
| 143 | |
| 144 | # Tar-up diagnostics from all the nodes |
| 145 | cd $diags |
| 146 | tar zcf $diags.tar.gz * |
| 147 | [ -z $extract ] && rm -fr $diags |