#!/bin/bash # **************************************************************************** # * * # * Project: Earth Systems Grid Federation (ESGF) Data Node Software * # * First Author: Gavin M. Bell (gavin@llnl.gov) * # * * # **************************************************************************** # # Description: # # A simple script to do a quick spot check on the system. It simply # pulls down the registration.xml of the nodes supplied, looks at each # of the nodes in the registration and in turn pulls those # registration.xml files giving a count of the known hosts in the # respective registries. As the program suggests a quick P2P 'spot # check'. :-) #The DEFINITIVE values of the following declarations are in the esg-node script!!!!!! # (be sure that they match exactly - a brittle dependency, maybe clean up later) #--------------- # s'all about the bits... :-) #--------------- declare -r INSTALL_BIT=1 >& /dev/null declare -r TEST_BIT=2 >& /dev/null declare -r DATA_BIT=4 >& /dev/null declare -r INDEX_BIT=8 >& /dev/null declare -r IDP_BIT=16 >& /dev/null declare -r COMPUTE_BIT=32 >& /dev/null declare -r WRITE_ENV_BIT=64 >& /dev/null #declare -r PRIVATE_BIT=128 >& /dev/null #NOTE: remember to adjust (below) when adding new bits!! declare -r MIN_BIT=4 >& /dev/null declare -r MAX_BIT=64 >& /dev/null declare -r ALL_BIT=$((DATA_BIT+INDEX_BIT+IDP_BIT+COMPUTE_BIT)) >& /dev/null #--------------- #for OR logic #queryNodeType=${ALL_BIT} #for AND logic queryNodeType=0 show_node_type() { local sel=${sel:=$1} local resolved_to [ $((sel & DATA_BIT)) != 0 ] && resolved_to+="data " [ $((sel & INDEX_BIT)) != 0 ] && resolved_to+="index " [ $((sel & IDP_BIT)) != 0 ] && resolved_to+="idp " [ $((sel & COMPUTE_BIT)) != 0 ] && resolved_to+="compute " echo "[ ${resolved_to}$( ((DEBUG)) && echo "($sel)" )]" } quick_check() { target_node=${1:-pcmdi9.llnl.gov} local peers local count=0 local site local node while read line ; do eval $line ((DEBUG)) && echo "$queryNodeType & $nodeType ==> $((queryNodeType & nodeType))" #OR LOGIC #[ $((queryNodeType & nodeType)) == 0 ] && continue #AND LOGIC [ $((queryNodeType & nodeType)) != "${queryNodeType}" ] && continue echo -n " [$((++count))] looking at $( ((VERBOSE | SHOW_URL)) && echo "site ${site}" || echo "node ${node}") $(show_node_type $nodeType) -> " #explore each one hop peer in a subshell... (for variable scoping reasons) ( ((VERBOSE)) && echo count=0 while read line2; do eval $line2 [ $((queryNodeType & nodeType)) != "${queryNodeType}" ] && continue ((count++)) if((VERBOSE)); then echo $node $(show_node_type $nodeType) fi done < <(curl -s -m ${time_out_secs:-3} $site | sed -n 's#.*hostname="\([^"]*\)".*nodeType="\([^"]*\).*$#node=\1; site=http://\1/esgf-node-manager/registration.xml; nodeType=\2#p') echo $count) done < <(curl -s -m 15 http://${target_node}/esgf-node-manager/registration.xml | sed -n 's#.*hostname="\([^"]*\)".*nodeType="\([^"]*\).*$#node=\1; site=http://\1/esgf-node-manager/registration.xml; nodeType=\2#p') } spot_check() { local hosts=$@ (( $# == 0 )) && _usage for host in ${hosts[@]}; do echo "Spot Checking [${host}]..." quick_check ${host} done } _usage() { printf "usage: > $0 [--timeout | -t ] options: --timeout | -t (default 3 seconds - on secondary hop nodes) --show-type [ data &| index $| idp &| compute ] | [all] - filtering on node type: displays only nodes that match any combination of specified node types (performs logical AND) (no args to this flag can be considered \"ANY\": i.e. all detected nodes are shown; equivalent to not using this flag) --show-url - to show full url to registration document in output --debug - prints debug output --verbose - shows each node visibile by secondary hop nodes --version | -v - version --help | -h - this help information Ex: spotcheck pcmdi9.llnl.gov spotcheck --show-type index compute pcmdi9.llnl.gov " exit 1 } ############################################ # Main ############################################ myargs=($@) i=0 ((DEBUG)) && echo ${myargs[@]} while [ -n "${myargs[i]}" ]; do ((DEBUG)) && echo "now on token ${myargs[i]}" case ${myargs[i]} in -v | --version) echo "Earth Systems Grid Federation (http://esgf.org)" echo "ESGF P2P Spot Check Utility" echo "" exit 0 ;; --verbose) VERBOSE=1; ;; --debug) DEBUG=1; ;; --timeout | -t) ((i++)) time_out_secs=${myargs[i]}; ;; --show-url) SHOW_URL=1 ;; --show-type) let sel=0 ((i++)) until [ -z "${myargs[i]}" ]; do tvalue=$(echo "${myargs[i]}" | tr 'A-Z' 'a-z') hit=0 #turn on the proper bit when string is detected [ "all" = "${tvalue}" ] && sel=$ALL_BIT && ((hit++)) [ "data" = "${tvalue}" ] && ((sel+=DATA_BIT)) && ((hit++)) [ "index" = "${tvalue}" ] && ((sel+=INDEX_BIT)) && ((hit++)) [ "idp" = "${tvalue}" ] && ((sel+=IDP_BIT)) && ((hit++)) [ "compute" = "${tvalue}" ] && ((sel+=COMPUTE_BIT)) && ((hit++)) ((DEBUG)) && echo "hit = ${hit}" if ((hit == 0)); then ((i--)) && break else ((i++)) fi done ((sel != 0)) && queryNodeType=${sel} ((DEBUG)) && echo "node type set to: ${queryNodeType} (sel=${sel}) " unset sel ;; --help | -h) _usage ;; *) spotcheck_hosts=( "${spotcheck_hosts[@]}" "${myargs[i]}" ) ;; esac ((i++)) done spot_check ${spotcheck_hosts[@]}