#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_site_state.sh 1.5 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1990,2010 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)14 1.5 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_site_state.sh, hacmp.assist, 61haes_r721, 1642B_hacmp721 10/14/16 14:14:11 #============================================================================= # # Name: KLIB_HACMP_get_site_state # # Description: This is the main, FPATH function that is invoked by clmgr # to retrieve the aggregated cluster manager state for a given # site. The "worst case" status wins. # # Inputs: See the "devDoc()" function, below. # # Outputs: The node state is returned on STDOUT, unless the optional # "state" input is provided, in which case the state is stored # in that variable. The only other outputs are any error # messages that might be needed. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function, below, for the standard return # code values/meanings for clmgr. # #============================================================================= function KLIB_HACMP_get_site_state { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=1.5, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_site_state.sh, hacmp.assist, 61haes_r721, 1642B_hacmp721 : INPUTS: $* typeset site=${1//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset LINE= NODE= NODELIST= typeset -u STATE=UNKNOWN typeset -i NODE_COUNT=0 OFFLINE=0 UNCONFIG=0 UNMANAGED=0 typeset -i ERROR=0 NORMAL=0 UNKNOWN=0 rc=$RC_SUCCESS #================= : Validate input #================= if [[ -z $site ]]; then rc=$RC_MISSING_INPUT else print "$0()[$LINENO]($SECONDS): clodmget -q \"name=$site\" -f nodelist HACMPsite" >>$CLMGR_TMPLOG # Always log commands NODELIST=$(clodmget -q "name=$site" -f nodelist HACMPsite) NODELIST=${NODELIST//\"} print "$0()[$LINENO]($SECONDS): clodmget RC: $?; NODELIST == \"$NODELIST\"" >>$CLMGR_TMPLOG # Always log command result #================================================ : Collect and analyze the status from each node #================================================ for NODE in $NODELIST; do (( NODE_COUNT++)) STATE=$(CL=$LINENO KLIB_HACMP_get_node_state "$NODE" 2>>$CLMGR_TMPLOG) if [[ $STATE == *@(INIT|INOPERATIVE)* ]]; then (( OFFLINE++ )) elif [[ $STATE == *NOT_CONFIGURED* ]]; then (( UNCONFIG++ )) elif [[ $STATE == *FAILED* ]]; then (( ERROR++ )) elif [[ $STATE == *@(JOINING|UNSTABLE|VOTING|RUNNING|BARRIER|DONE)* ]]; then (( NORMAL++ )) elif [[ $STATE == *STABLE* ]]; then (( NORMAL++ )) elif [[ $STATE == *UNMANAGED* ]]; then (( UNMANAGED++ )) else (( UNKNOWN++ )) fi done #================================================================== : Aggregate the collected node states to arrive at a relatively : appropriate, overall cluster state. The goal here is to provide : the most useful indicator to the customer. #================================================================== if (( NODE_COUNT > 0 )); then if [[ $CLMGR_GUI == "SMUI" ]]; then if (( ERROR )); then STATE=ERROR elif (( UNCONFIG )); then STATE=NOT_CONFIGURED elif (( OFFLINE == NODE_COUNT )); then STATE=OFFLINE elif (( NORMAL == NODE_COUNT )); then STATE=STABLE elif (( UNMANAGED == NODE_COUNT )); then STATE=UNMANAGED elif (( NORMAL && NORMAL != NODE_COUNT )); then STATE=WARNING else STATE=UNKNOWN fi else if (( ERROR )); then STATE=ERROR elif (( UNCONFIG )); then STATE=NOT_CONFIGURED elif (( OFFLINE == NODE_COUNT )); then STATE=OFFLINE elif (( NORMAL == NODE_COUNT )); then STATE=STABLE elif (( UNMANAGED == NODE_COUNT )); then STATE=UNMANAGED else STATE=UNKNOWN fi fi fi fi print -- $STATE # Do not quote! Avoids leading/trailing whitespace! log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_site_state()" #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose. This feature was originally implemented # using the man page information. However, in a code review it # was pointed out that this approach had to be changed because # customers do not have to install the man pages! Therefore, a # built-in dependency on man page information would break the # automatic help feature of clmgr. So the SYNPOSIS section must # be used instead. # # IMPORTANT: As a result of this, it is imperative that the # information in this SYNOPSIS be kept in sync # with the man page information, which is owned # by the IDD team. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_get_site_state =head1 VERSION Version Number: 1.5 Last Extracted: 10/21/16 17:05:34 Last Changed: 10/14/16 14:14:11 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_site_state.sh, hacmp.assist, 61haes_r721, 1642B_hacmp721 =head1 SYNOPSIS clmgr -cSa state query site [ [,,,...] ] =head1 DESCRIPTION Queries every node in the cluster for its current state (retrieved by calling "lssrc -ls clstrmgrES") and aggregating the results. The currently known statuses are: ST_INIT ST_JOINING ST_STABLE ST_UNSTABLE ST_VOTING ST_RP_RUNNING ST_BARRIER ST_RP_FAILED ST_CBARRIER ST_DONE NOT_CONFIGURED UNMANAGED These raw states are aggregated into seven possible statuses: NOT_CONFIGURED OFFLINE ERROR NORMAL WARNING UNMANAGED UNKNOWN NOT_CONFIGURED indicates that the node has not yet been configued into a cluster. If *any* node in the cluster has this state, then the entire cluster is considered to be "NOT_CONFIGURED". ST_INIT indicates cluster services are inactive, but AIX is running. If all the nodes have this state, the cluster state is set to "OFFLINE". ST_JOINING, ST_UNSTABLE, ST_VOTING, ST_RP_RUNNING, ST_BARRIER, ST_CBARRIER, and ST_DONE all indicate that cluster services are active, and something is happening. If *any* of the nodes in the cluster possess this state, then the cluster state is set to "NORMAL". ST_RP_FAILED indicates a PowerHA error has occurred on that node (other nodes in the cluster may be in *BARRIER in this case). If *any* node in the cluster possesses this state, the cluster state is set to "ERROR". ST_STABLE indicates that cluster services are operating normally. If all nodes in the cluster have this state, the cluster state is set to "NORMAL". However, if any of the nodes in the cluster report "OFFLINE", while the rest report "NORMAL", then the cluster state is set to "WARNING" to indicate a degraded condition within the cluster. If *any* node in the cluster reports an unrecognized state, or cannot be contacted, the state of the cluster is set to "UNKNOWN". =head1 ARGUMENTS 1. site [REQUIRED] [string] The label of one or more sites (comma or space separated) that are to be queried. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =head1 COPYRIGHT COPYRIGHT International Business Machines Corp. 2005,2010 All Rights Reserved =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================