#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2018,2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_event_attributes.sh 1.4.1.3 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2012,2016 # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_event_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_event_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect event information (both custom, and pre-defined). # The cllscustom utility is used for retreiving data for # custom events. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: The properties hash is populated. 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 at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_get_event_attributes { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : INPUTS: $* typeset events=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then events= typeset -n properties=$1 else typeset -n properties=$2 fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset EVENTS= event= OUTPUT= typeset -i INDEX=0 rc=$RC_SUCCESS typeset key= value= typeset -i matches=0 typeset -u uc_attr= uc_key= uc_value= typeset -A queries typeset -i i=0 #=================================================== : Check for any specified attribute=value pairs. : If any are found, use those to query the output. #=================================================== while (( $# > 0 )); do value="$1" if [[ $value == *=* ]]; then uc_attr=${value%%=*} if [[ $uc_attr == "TYPE" ]]; then uc_value=${value#*=} queries[$uc_attr]=$uc_value else queries[$uc_attr]="${value#*=}" fi fi shift done #======================================= : Make sure we have something to query #======================================= if [[ $events != *([[:space:]]) ]]; then #============================================ : If they did not specify a particular type : of event, we need to check them all. #============================================ [[ -z ${queries[TYPE]} ]] && queries[TYPE]="ALL" #===================================================== : For convenience, support wildcards in the provided : name list. This is equivalent to using wildcards : filtering via something like NAME=some_search. #===================================================== if [[ $events == *[\*\?]* ]]; then typeset object= newList= for object in ${events//,/ }; do if [[ $object == *[\*\?]* ]]; then unset available typeset available CL=$LINENO KLIB_HACMP_list_events available ${queries[TYPE]} NAME=$object for (( i=0; i<${#available[*]}; i++ )); do if [[ ",$newList," != *,${available[$i]},* ]]; then [[ -n $newList ]] && newList="$newList," newList="$newList${available[$i]}" fi done elif [[ ",$newList," != *,$object,* ]]; then [[ -n $newList ]] && newList="$newList," newList="$newList$object" fi done [[ -n $newList ]] && events=$newList fi [[ $events != *,* ]] && unset INDEX for event in ${events//,/ }; do typeset TYPE=${queries[TYPE]} CL=$LINENO KLIB_HACMP_is_known_event "$event" "" TYPE if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 465 '\nERROR: "%1$s", of type "%2$s", does not appear to exist!\n\n' "$event" "${queries[TYPE]}" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 171 'Available %1$s Events:\n\n' "${queries[TYPE]}" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_events available ${queries[TYPE]} for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" rc=$RC_NOT_FOUND dspmsg -s $CLMGR_SET $CLMGR_MSGS 172 'Available Event Types:\n\n' 1>&2 for type in ALL CUSTOM PREDEFINED; do print -u2 "\t$type" done print -u2 "" else [[ -n $TYPE && -z ${queries[TYPE]} ]] && queries[TYPE]=$TYPE EVENTS="$EVENTS $event" fi done elif (( $CLMGR_VERBOSE == 1 || ${#queries[*]} > 0 )); then #=================================================== : Since there are so many pre-defined events, only : display them if specifically asked to do so. #=================================================== if [[ ${queries[TYPE]} == *([[:space:]]) ]]; then queries[TYPE]="CUSTOM" fi typeset available CL=$LINENO KLIB_HACMP_list_events available ${queries[TYPE]} for (( i=0; i<${#available[*]}; i++ )); do EVENTS="$EVENTS ${available[$i]}" done else dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi (( $rc != RC_SUCCESS )) && unset EVENTS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for event in $EVENTS; do properties[NAME$INDEX]=$event #======================== # CUSTOM CLUSTER EVENTS #======================== if [[ -z ${queries[TYPE]} || ${queries[TYPE]} == @(\*|A|C)* ]]; then print -- "$0()[$LINENO]($SECONDS): cllscustom -c -t event -n $event" >>$CLMGR_TMPLOG # Always log commands OUTPUT=$(cllscustom -c -t event -n $event 2>>$CLMGR_TMPLOG | grep -v '^#') rc=$? print "$0()[$LINENO]($SECONDS): cllscustom RC: $rc; OUTPUT == \"$OUTPUT\"" >>$CLMGR_TMPLOG # Always log command result if (( $rc == RC_SUCCESS )) && [[ $OUTPUT != *([[:space:]]) ]]; then print -- "$OUTPUT" |\ while IFS=: read name type desc file relation status; do [[ $name == \#* ]] && continue properties[NAME$INDEX]="$name" properties[TYPE$INDEX]="CUSTOM" properties[FILE$INDEX]=$file desc=${desc%%+([[:space:]])} properties[DESCRIPTION$INDEX]="${desc//+([[:space:]])/ }" done fi fi #==================== # PREDEFINED EVENTS #==================== if [[ ${queries[TYPE]} == @(\*|A|P)* ]]; then print -- "$0()[$LINENO]($SECONDS): clodmget -q\"name = $event\" -f \"name,cmd,notify,pre,post,,desc,catalog,setno,msgno,error_on_fail\" -n HACMPevent" >>$CLMGR_TMPLOG OUTPUT=$(clodmget -q"name = $event" -f name,cmd,notify,pre,post,desc,catalog,setno,msgno,error_on_fail -n HACMPevent 2>>$CLMGR_TMPLOG) rc=$? print "$0()[$LINENO]($SECONDS): clodmget RC: $rc" >>$CLMGR_TMPLOG if (( $rc != RC_SUCCESS )) && [[ $OUTPUT != $event:* ]] then dspmsg -s $CLMGR_SET $CLMGR_MSGS 466 '\nERROR: the specified object, "%1$s", could not be found.\n\n' "$event" 1>&2 rc=$RC_NOT_FOUND break fi if [[ $OUTPUT != *([[:space:]]) ]]; then print -- "$OUTPUT" |\ while IFS=: read name cmd notify pre post desc catalog setno msgno error_on_fail; do properties[NAME$INDEX]="$name" properties[TYPE$INDEX]="PREDEFINED" properties[COMMAND$INDEX]="$cmd" properties[NOTIFY_COMMAND$INDEX]="$notify" properties[PRE_EVENT_COMMAND$INDEX]="$pre" properties[POST_EVENT_COMMAND$INDEX]="$post" properties[PREPOSTFAILS$INDEX]="False" (( error_on_fail )) && properties[PREPOSTFAILS$INDEX]="True" if [[ $setno == +([[:digit:]]) && \ $msgno == +([[:digit:]]) && $catalog != *([[:space:]]) && \ $desc != *([[:space:]]) ]] then desc=$(dspmsg -s $setno $catalog $msgno "$desc") desc=${desc%%+([[:space:]])} properties[DESCRIPTION$INDEX]="${desc//+([[:space:]])/ }" fi done fi fi #============================================================== : Even if there is no value for a given attribute, we want to : display a placeholder for it, so the customer always sees a : consistent, complete set of attributes. #============================================================== for key in ${_COLON_ATTR_ORDER[event]}; do if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done if [[ ${properties[TYPE$INDEX]} == "CUSTOM" ]]; then #======================================================== : Remove attributes that do not apply to a custom event #======================================================== for key in COMMAND NOTIFY_COMMAND PRE_EVENT_COMMAND \ POST_EVENT_COMMAND PREPOSTFAILS do unset properties[$key$INDEX] done elif [[ ${properties[TYPE$INDEX]} == PRE* ]]; then unset properties[FILE$INDEX] fi (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done #========================================================== : If any searches/filters were specified, handle them now #========================================================== unset queries[TYPE] if (( $rc == RC_SUCCESS && ${#queries[*]} > 0 )); then CL=$LINENO search_properties queries properties rc=$? fi (( $rc == RC_SUCCESS )) && CL=$LINENO prune_indexes properties log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_event_attributes()" #============================================================================ # # 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_event_attributes =head1 SYNOPSIS clmgr query event [,,...] clmgr -v query event NOTE: the alias for "event" is "ev". =head1 DESCRIPTION Retrieves the configuration data for one or more PowerHA SystemMirror cluster events. =head1 ARGUMENTS 1. events [REQUIRED] [string] The label of one or more events (comma or space separated) that are to be queried. 2. properties [REQUIRED] [hash ref] An associative array within which data about the queried objects can be returned to the caller. =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 =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 #==============================================================================