#!/usr/bin/perl # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # # # Licensed Materials - Property of IBM # # (C) COPYRIGHT International Business Machines Corp. 2000,2019 # 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 # sccsid = "@(#)78 1.14.1.9 src/rsct/rm/ER/cli/bin/rmcondresp.perl, errmcli, rsct_rady, rady2035a 11/12/15 16:39:46" ###################################################################### # # # Module: rmcondresp # # # # Purpose: # # rmcondresp - remove a link bewteen a condition and a response # # # # Syntax: # # rmcondresp [-h] [-q] [-TV] Condition[:Node_name] [Response # # [Response...]] # # # # rmcondresp [-h] [-q] -r [-TV] Response [Response ...][:Node_name]# # # # rmcondresp [-h] -U|-L Condition[:Node_name] Response # # # # Flags: # # -h help - writes this command's usage statement to stdout # # -q does not return an error if condition or response does # # not exist. # # -r All command operands are responses. There are no # # conditions specified. This deletes links from all # # conditions that are linked to the specified responses. # # -L Lock. Lock the link between a condition and response so # # that the monitoring state cannot be changed using the # # startcondresp or stopcondresp command or the link # # between the condition and response be removed using the # # rmcondresp command. # # -U Unlock. Unlock the link between a condition and response # # so that the monitoring state can be changed using the # # startcondresp or stopcondresp command or the link # # between the condition and response removed using the # # rmcondresp command. # # -T Trace. IBM Support Center use only. # # -V Verbose. # # # # Operands: # # Condition Specifies the name of the condition linked to the # # response. The condition is always specified first, # # unless the -r flag is used. Node_name specifies where # # the condition is defined. # # Response Specifies the name of a response, or more than one # # response. The links from the specified responses to the # # condition are removed. Node_name specifies where the # # the response is defined. # # # # Description: # # The rmcondresp command deletes the link between a condition and # # a response. More than one response can be specified. The # # response is no longer run when the condition occurs. Use the # # -r flag to specify that the command operands consist only of # # responses. This deletes all links to conditions for these # # responses. If only a condition is specified, links to all # # responses for that condition are deleted. # # # # Exit Values: # # 0 ERRM_CLI_SUCCESS Command completed successfully. # # 1 ERRM_CLI_RMC_ERROR Command terminated due to an underlying # # RMC error. # # 2 ERRM_CLI_ERROR Command terminated due to an underlying # # error in the command script. # # 3 ERRM_CLI_BAD_FLAG Command terminated due to user # # specifying an invalid flag. # # 4 ERRM_CLI_BAD_OPERAND Command terminated due to user # # specifying a bad operand. # # 5 ERRM_CLI_USER_ERROR Command terminated due to a user error. # # For example specifying a name that # # already exists. # # # # Examples: # # 1. Remove the response "Broadcast event on-shift" from the # # condition "JFS space used": # # rmcondresp "JFS space used" "Broadcast event on-shift" # # 2. Remove all the responses from the condition "JFS space used": # # rmcondresp "JFS space used" # # 3. Remove the responses "Broadcast event on-shift" and # # "E-mail root anytime" from the condition "JFS space used": # # rmcondresp "JFS space used" "Broadcast event on-shift" \ # # "E-mail root anytime" # # 4. Remove the response "Broadcast event on-shift" from all # # conditions that use it: # # rmcondresp -r "Broadcast event on-shift" # # # # Man Page: # # For the most current detailed description of this command see # # the rmcondresp man page in /opt/rsct/man. # # # #--------------------------------------------------------------------# # Inputs: # # /opt/rsct/msgmaps/errmcli.rmcondresp.map - message mapping # # # # Outputs: # # stdout - display information on the condition. # # stderr - any error message. # # # # External Ref: # # Commands: ctdspmsg # # Modules: ERRM_cli_utils.pm, ERRM_cli_rc.pm # # CT_cli_utils.pm # # Perl library routines: Getopt::Std # # # # Tab Settings: # # 4 and tabs should be expanded to spaces before saving this file. # # in vi: (:set ts=4 and :%!expand -4) # # # # Change Activity: # # 001106 JAC 67469: Initial design & write. # # 001227 JAC 67470: Completed rmcondresp command. # # 010103 JAC 70296: Make TRUE/FALSE come from utils. # # 010109 JAC 70406: Update syntax to remove -c and -r flags. # # 010125 JAC 70355: Updates for final messages ship. # # 010129 JAC 70951: Shift rc after RMC calls if error occurs. # # 010301 JAC 71185: Continue removing resources even if a # # condition or response is not found. # # 010402 JAC 72894: Eliminate extra call to lsrsrc to get handles # # 010507 JAC 73620: Check for RMC CLI user error (rc=5) and # # return ERRM user error for this case. # # 011120 JAC 77597: Add distributed RMC changes # # 011206 JAC 78841: Fix selection string for locating resources. # # 011213 JAC 78976: Fix selection string for locating resources. # # 020118 JAC 79558: Fix selection string for locating resources # # and fix incorrect message name. # # 020128 JAC 79559: Change how destination/locator node is used. # # 020416 JAC 81754: Fix exit code check and switch to xxx-api cmds.# # 020719 JAC 84425: Add $rc to process_api_error call. # # 020729 JAC 85061: Use 4 (DM/SR/local) for scope if locator used # # and scope not set. # # 030610 JAC 95615: Add support for locked attribute. # # 030620 JAC 96060: Add -U|-L for Locked attribute. # # 071026 JAC 146726: set delimiter for -api commands. # ###################################################################### #--------------------------------------------------------------------# # General Program Flow/Logic: # # # # 1. Parse command line flags and operands, determine which flavor # # of this command we are actually invoking. # # This command allows a user to remove condition-response assoc. # # 2. Print usage if -h specified # # 3. If a condition is specifed, make sure only one condition was # # specified, make sure it exists and it is in an association. # # 4. If any responses are specifed, make sure they exist and that # # they are in an associations. # # 5. If -q is specified, don't return errors if something doesn't # # exist. # # 6. If only a condition was specified, call RMC rmrsrc using the # # condition handle in the selection string to remove all # # associations with that condition handle. # # 7. If only responses were specified, loop calling RMC rmrsrc using # # the response handle in the selection string to remove all # # associations with that response handle. # # 8. If both condition and responses were specified, loop calling # # RMC rmrsrc using the condition handle and response handle in # # the selection string to remove all associations with those # # condition and response handles. # # 9. Return back any errors. # # # #--------------------------------------------------------------------# #--------------------------------------------------------------------# # Included Libraries and Extensions # #--------------------------------------------------------------------# use lib "/opt/rsct/pm"; use locale; use Getopt::Long; use CT_cli_utils qw(printIMsg printEMsg); use ERRM_cli_rc qw(ERRM_CLI_SUCCESS ERRM_CLI_RMC_ERROR ERRM_CLI_ERROR ERRM_CLI_BAD_FLAG ERRM_CLI_BAD_OPERAND ERRM_CLI_USER_ERROR); use ERRM_cli_utils qw(error_exit printCIMsg printCEMsg get_handle get_source_node find_resource_handle get_locator_node find_resource_name find_association_handle get_assoc_handles set_orig_rmc_scope check_set_cluster_scope change_locked_attr process_api_error process_exit_code $TRUE $FALSE $CTDIR $CTBINDIR $DELIMITERI $DELIMITERO $RMC_CLI_USER_ERROR $RMC_LOCAL_SCOPE $RMRSRC $RSCASSC $RSCCOND $RSCEVRS); #--------------------------------------------------------------------# # Global Variables # #--------------------------------------------------------------------# Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case", "require_order", "prefix_pattern=(--|-)"); $Trace = $FALSE; # default - trace off $Verbose = $FALSE; # default - verbose turned off $Scope_orig_set = $FALSE; # default - no CT_MANAGEMENT_SCOPE $Scope_orig_value = 0; # default - scope value $Opt_Lock = $FALSE; # default - no set lock $Opt_Unlock = $FALSE; # default - no set unlock $PROGNAME = "rmcondresp"; # Program Name for messages $LSMSG = "$CTBINDIR/ctdspmsg"; # list / display message rtn $MSGCAT = "errmcli.cat"; # msg catalogue for this cmd $ENV{'MSGMAPPATH'} = "$CTDIR/msgmaps"; # msg maps used by $LSMSG #--------------------------------------------------------------------# # Variables # #--------------------------------------------------------------------# my $condition = ""; # condition to use -c my @responses = (); # responses to use -r my $cond_handle = ""; # handle for condition my $resp_handle = ""; # handle for response my $resp_handle2 = ""; # handle for response my @resp_handles = (); # handles for response my @cond_handles = (); # handles for condition my $passopts = ""; # options to pass to RMC my $i = 0; # loop counter my $k = 0; # loop counter my $Quiet_req = $FALSE; # is -q requested for quiet? my $Responses_only = $FALSE; # -r for only responses my $temp_name = ""; # holds resource name my $node_select = ""; # used for NodeNameList my $locator = ""; # locator my @cmd_out = (); # command output my @cond_names = (); my @resp_names = (); my $lock_val = 0; # Locked attr value my $a_handles = ""; # association handle by ref my $actflags = ""; # active flags by ref #--------------------------------------------------------------------# # Main Code # #--------------------------------------------------------------------# my $rc = 0; my $rc2 = 0; my $errmcli_rc = 0; # parse the command line, exit if there are errors ($rc, $condition, @responses) = &parse_cmd_line; ($rc == 0) || error_exit($rc); if ($Trace || $Verbose) { $passopts = $passopts." -"; } if ($Trace) { $passopts = $passopts."T"; } if ($Verbose) { $passopts = $passopts."V"; } # process rmcondresp when only responses specified if ($condition eq "") { # no conditions # parser makes sure there's a response when there is not condition. # get the locator from the last response, if it exists ($temp_name, $locator) = get_locator_node($responses[$#responses]); # put back response name without locator if ($locator ne "") { $responses[$#responses] = $temp_name; } # for each response, make sure it exists for ($i=0; $i<=$#responses; $i++) { # does the response exist? (and get the handle) ($rc, $resp_handle) = get_handle($responses[$i], $RSCEVRS, $locator); if ($rc != 0) { # response does not exist $rc = 0; # if RMC CLI user error, set ERRM user error if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } else { if (!$Quiet_req) { printEMsg("EMsgrmcondrespResponseNotFound",$responses[$i]); $errmcli_rc = ERRM_CLI_USER_ERROR; } } } else { # response does exist # check Association for this handle $rc = find_resource_handle($resp_handle,"r",$locator); if ($rc == 0) { # found in an Association # add the handle to the array for deleting push @resp_handles, $resp_handle; if ($Verbose) { printIMsg("IMsgrmcondrespStartNoCond",$responses[$i]);} } else { # not found in Association # if RMC CLI user error if ($rc != $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } else { $rc = 0; if (!$Quiet_req) { printEMsg("EMsgrmcondrespResponseNotFound",$responses[$i]); $errmcli_rc = ERRM_CLI_USER_ERROR; } } } } } # end of for loop # delete the Associations by response handles for ($i=0; $i<=$#resp_handles; $i++) { # get rid of quotes in handle $resp_handles[$i] =~ s/"//g; # set CT_MANAGEMENT_SCOPE to original setting, in case it was used set_orig_rmc_scope; # if the destination node was not specified, delete the local definition. # Make sure rmc scope is set to local scope. if ($locator eq "") { $ENV{CT_MANAGEMENT_SCOPE} = $RMC_LOCAL_SCOPE; } # a locator was specified, use it for NodeNameList else { $node_select = " && NodeNameList |< {\\\"$locator\\\"}"; # use DM/SR/Local scope if scope not set and there's a locator check_set_cluster_scope; } if ($Trace) { print STDERR "$PROGNAME: calling rmrsrc-api\n";} # call rmrsrc to remove the association # `$CTBINDIR/$RMRSRC $passopts -s "EventResponseHandle==\\\"$resp_handles[$i]\\\" $node_select" $RSCASSC`; @cmd_out=`$CTBINDIR/rmrsrc-api -I $DELIMITERI -D $DELIMITERO -s ${RSCASSC}${DELIMITERI}"EventResponseHandle==\\\"$resp_handles[$i]\\\"${node_select}" 2>&1`; $rc = $?; $rc = process_exit_code($rc); if ($Trace) { print STDERR "rmrsrc-api results:\n"; print STDERR "@cmd_out";} if ($Trace) { print STDERR "$PROGNAME: rmrsrc-api returned $rc\n";} # show any locked errors if there was a bad rc if ($rc != 0) { ($rc2,@cmd_out) = &remove_locked_errors(@cmd_out); } # print any errors for locked attribute if ($rc2 != 0) { # reset error code if ($#cmd_out <0) { $rc = 0;} # have response name. need condition name # get response handles # get rid of quotes in handle $resp_handle2 = $resp_handle; $resp_handle2 =~ s/"//g; @cond_handles = &get_locked_list ($locator, "EventResponseHandle==\"$resp_handle2\"",ConditionHandle); # get names for the response handles @cond_names = &find_names_from_rhs($locator,@cond_handles); # print the error messages for ($k=0; $k <= $#cond_names; $k++){ printEMsg("EMsgrmcondrespAssocLocked",$cond_names[$k],$responses[$i]); } $errmcli_rc = ERRM_CLI_USER_ERROR; } # show any errors if there was a bad rc if ($rc != 0) { process_api_error($DELIMITERO,$rc,@cmd_out); } # if rmrsrc command failed due to RMC CLI user error 73620 # set ERRM CLI user error and go to next condition/response if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } # if rmrsrc command failed, print RMC error message and exit else { if ($rc != 0) { printCEMsg("EMsgERRMcliUnExpectRMCrc",$rc); exit(ERRM_CLI_RMC_ERROR); } } } # end of for loop } # end of if no conditions else { # a condition was specified # get the locator from the condition, if it exists ($temp_name, $locator) = get_locator_node($condition); # put back condition name without locator if ($locator ne "") { $condition = $temp_name; } # does the condition exist? (and get the handle) ($rc, $cond_handle) = get_handle($condition, $RSCCOND,$locator); if ($rc != 0) { # condition does not exist # if RMC CLI user error, exit if ($rc == $RMC_CLI_USER_ERROR) { exit(ERRM_CLI_USER_ERROR); } $rc = 0; if (!$Quiet_req) { printEMsg("EMsgrmcondrespConditionNotFound",$condition); exit(ERRM_CLI_USER_ERROR); } } else { # condition does exist # are there responses specified or only a condition if ($#responses >=0) { # there are responses # for each response, get the handle, delete cond/resp by handles # for each response, get the handle for ($i=0; $i<=$#responses; $i++) { # does the response exist? (and get the handle) ($rc, $resp_handle) = get_handle($responses[$i], $RSCEVRS, $locator); if ($rc != 0) { # response does not exist # if RMC CLI user error, set ERRM user error if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } else { $rc = 0; if (!$Quiet_req) { printEMsg("EMsgrmcondrespResponseNotFound",$responses[$i]); $errmcli_rc = ERRM_CLI_USER_ERROR; } } } else { # response exists # check Association for this handle combination ($rc, $a_handles, $actflags) = get_assoc_handles($cond_handle,$resp_handle,$locator); if ($rc == 0) { # found in an Association # get rid of quotes in handles $$a_handles[0] =~ s/"//g; # if only changing Locked attribute, do it and leave if ($Opt_Lock || $Opt_Unlock) { # set lock value if ($Opt_Lock) { $lock_val = 1;} if ($Opt_Unlock) { $lock_val = 0;} # call function to change Locked attribute $rc = change_locked_attr($lock_val,$locator,$RSCASSC,$$a_handles[0]); if ($Verbose) { printIMsg("IMsgrmcondrespEnd");} exit($rc); } # set CT_MANAGEMENT_SCOPE to original setting, in case it was used set_orig_rmc_scope; # if the destination node was not specified, delete the local definition. # Make sure rmc scope is set to local scope. if ($locator eq "") { $ENV{CT_MANAGEMENT_SCOPE} = $RMC_LOCAL_SCOPE; } # a locator was specified, use it for NodeNameList else { $node_select = " && NodeNameList |< {\\\"$locator\\\"}"; # use DM/SR/Local scope if scope not set and there's a locator check_set_cluster_scope; } # delete if ($Verbose) { printIMsg("IMsgrmcondrespStart",$condition,$responses[$i]);} if ($Trace) { print STDERR "$PROGNAME: calling rmrsrc-api\n";} @cmd_out=`$CTBINDIR/rmrsrc-api -I $DELIMITERI -D $DELIMITERO -r "$$a_handles[0]" 2>&1`; # @cmd_out=`$CTBINDIR/rmrsrc-api -D $DELIMITER -s ${RSCASSC}::"ConditionHandle=\\\"$cond_handle\\\" && EventResponseHandle==\\\"$resp_handle\\\"${node_select}" 2>&1`; # `$CTBINDIR/$RMRSRC $passopts -s "ConditionHandle==\\\"$cond_handle\\\" && EventResponseHandle==\\\"$resp_handle\\\" $node_select" $RSCASSC`; $rc = $?; $rc = process_exit_code($rc); if ($Trace) { print STDERR "rmrsrc-api results:\n"; print STDERR "@cmd_out";} if ($Trace) { print STDERR "$PROGNAME: rmrsrc-api returned $rc\n";} # show any locked errors if there was a bad rc if ($rc != 0) { ($rc2,@cmd_out) = &remove_locked_errors(@cmd_out); } # print any errors for locked attribute if ($rc2 != 0) { # reset error code if ($#cmd_out <0) { $rc = 0;} printEMsg("EMsgrmcondrespAssocLocked",$condition,$responses[$i]); $errmcli_rc = ERRM_CLI_USER_ERROR; } # show any errors if there was a bad rc if ($rc != 0) { process_api_error($DELIMITERO,$rc,@cmd_out); } # if rmrsrc command failed due to RMC CLI user error 73620 # set ERRM CLI user error and go to next condition/response if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } else { # if rmrsrc command failed, print RMC error message and exit if ($rc != 0) { printCEMsg("EMsgERRMcliUnExpectRMCrc",$rc); exit(ERRM_CLI_RMC_ERROR); } } } else { # not found in Association # if rmrsrc command failed due to RMC CLI user error 73620 # set ERRM CLI user error and go to next condition/response if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } else { if (!$Quiet_req) { printEMsg("EMsgrmcondrespCondRespNotFound",$condition,$responses[$i]); $errmcli_rc = ERRM_CLI_USER_ERROR; } } $rc = 0; } } } } # end of there are responses else { # there aren't any responses # check Association for this condition handle $rc = find_resource_handle($cond_handle,"c",$locator); if ($rc == 0) { # found in an Association # get rid of quotes in handle $cond_handle =~ s/"//g; # set CT_MANAGEMENT_SCOPE to original setting, in case it was used set_orig_rmc_scope; # if the destination node was not specified, delete the local definition. # Make sure rmc scope is set to local scope. if ($locator eq "") { $ENV{CT_MANAGEMENT_SCOPE} = $RMC_LOCAL_SCOPE; } # a locator was specified, use it for NodeNameList else { $node_select = " && NodeNameList |< {\\\"$locator\\\"}"; # use DM/SR/Local scope if scope not set and there's a locator check_set_cluster_scope; } # delete the association by condition handle if ($Verbose) { printIMsg("IMsgrmcondrespStartNoResp",$condition);} if ($Trace) { print STDERR "$PROGNAME: calling rmrsrc-api\n";} # `$CTBINDIR/$RMRSRC $passopts -s "ConditionHandle==\\\"$cond_handle\\\" $node_select" $RSCASSC`; @cmd_out=`$CTBINDIR/rmrsrc-api -I $DELIMITERI -D $DELIMITERO -s ${RSCASSC}${DELIMITERI}"ConditionHandle==\\\"$cond_handle\\\"${node_select}" 2>&1`; $rc = $?; $rc = process_exit_code($rc); if ($Trace) { print STDERR "rmrsrc-api results:\n"; print STDERR "@cmd_out";} if ($Trace) { print STDERR "$PROGNAME: rmrsrc-api returned $rc\n";} # show any locked errors if there was a bad rc if ($rc != 0) { ($rc2,@cmd_out) = &remove_locked_errors(@cmd_out); } # print any errors for locked attribute if ($rc2 != 0) { # reset error code if ($#cmd_out <0) { $rc = 0;} # have condition name. need response(s) name # get response handles @resp_handles = &get_locked_list ($locator, "ConditionHandle==\"$cond_handle\"",EventResponseHandle); # get names for the response handles @resp_names = &find_names_from_rhs($locator,@resp_handles); # print the error messages for ($k=0; $k <= $#resp_names; $k++){ printEMsg("EMsgrmcondrespAssocLocked",$condition,$resp_names[$k]); } $errmcli_rc = ERRM_CLI_USER_ERROR; } # show any errors if there was a bad rc if ($rc != 0) { process_api_error($DELIMITERO,$rc,@cmd_out); } # if rmrsrc command failed due to RMC CLI user error 73620 # set ERRM CLI user error and go to next condition/response if ($rc == $RMC_CLI_USER_ERROR) { $errmcli_rc = ERRM_CLI_USER_ERROR; } # if rmrsrc command failed, print RMC error message and exit else { if ($rc != 0) { printCEMsg("EMsgERRMcliUnExpectRMCrc",$rc); exit(ERRM_CLI_RMC_ERROR); } } } else { # not found in Association # if RMC CLI user error if ($rc == $RMC_CLI_USER_ERROR) { exit(ERRM_CLI_USER_ERROR); } $rc = 0; if (!$Quiet_req) { printEMsg("EMsgrmcondrespConditionNotFound",$condition); exit(ERRM_CLI_USER_ERROR); } } } # end of there aren't any responses } } if ($Verbose) { printIMsg("IMsgrmcondrespEnd");} if ($errmcli_rc == 0) { exit($rc);} else { exit($errmcli_rc);} #--------------------------------------------------------------------# # End Main Code # #--------------------------------------------------------------------# #--------------------------------------------------------------------# # parse_cmd_line - Parse the command line for options and operands. # # Set appropriate global variables as outlined below, make sure we # # have a valid combination of arguments / options. # # # # Return: # # $rc 0 Command line parsed fine, no problem. # # ERRM_CLI_BAD_FLAG Command line contained a bad flag. # # $resource Name of resource to be removed. # # # # Global Variables Modified: # # $Verbose output True (-V) turn Verbose mode on. # # $Trace output True (-T) turn Trace mode on. # # $Quiet_req output True (-q) turn quiet mode on. # # $Responses_only output True (-r) for only response names. # # $Opt_Lock output True (-U) lock specified # # $Opt_Unlock output True (-U) unlock specified # #--------------------------------------------------------------------# sub parse_cmd_line { my(@original_argv) = @ARGV; my $condition_name = ""; # condition names my @response_names = (); # response names my %opts = (); my $lock_flag = ""; # for invalid flag message my $lock_flag2 = ""; # for invalid flag message # Process the command line... if (!GetOptions(\%opts, 'h' , 'q' , 'r' , 'U' , 'L' , 'V' , 'T')) { # Gather options; # if errors &print_usage; # display proper usage return ERRM_CLI_BAD_FLAG; # return bad rc - bad flag } # process h flag if (defined $opts{h}) { # -h, help request &print_usage; # print usage statement exit(0); # all done with good return! } # process q flag if (defined $opts{q}) { # -q, quiet request $Quiet_req = $TRUE; # set quiet flag } if (defined $opts{T}) { # -T turn trace on $Trace = $TRUE; } if (defined $opts{V}) { # -V turn verbose mode on $Verbose = $TRUE; } # process r flag if (defined $opts{r}) { # -r, response names only $Responses_only = $TRUE; # set response flag } # Get the arguments... # Operands: Condition Response [Response ...] if ($#ARGV >= 0) { # must have at least 1 # first one is Condition name if (!$Responses_only) { $condition_name = shift @ARGV; } # the rest are responses @response_names = @ARGV; } else { # not enough operands printCEMsg("EMsgERRMcliInvalidNumberOfOperands"); &print_usage; return ERRM_CLI_BAD_OPERAND; } # check for lock/unlock flags if ((defined $opts{L}) || (defined $opts{U})) { # -U,-L for unlock,lock # set global flag if ( defined $opts{L} ) { $Opt_Lock = $TRUE; $lock_flag = "L"; } if ( defined $opts{U} ) { $Opt_Unlock = $TRUE; $lock_flag = "U"; } # these flags are not allowed together or with the other flags (qr) if ( $Opt_Lock && $Opt_Unlock ) { $lock_flag = "L"; $lock_flag2 = "U"; } if (defined $opts{q}) { $lock_flag2 = "q";} if (defined $opts{r}) { $lock_flag2 = "r";} if ( $lock_flag2 ne "" ) { printCEMsg("EMsgERRMcliImproperUsageCombination",$lock_flag,$lock_flag2); &print_usage; return ERRM_CLI_BAD_FLAG; } # must have 1 condition and 1 response if ( ($condition_name eq "") || ($#response_names != 0) ) { printCEMsg("EMsgERRMcliInvalidNumberOfOperands"); &print_usage; return ERRM_CLI_BAD_OPERAND; } } return(0, $condition_name, @response_names); # success } # end parse_cmd_line #--------------------------------------------------------------------# # print_usage : print the usage statement (syntax) to stdout. # #--------------------------------------------------------------------# sub print_usage { &printIMsg("IMsgrmcondrespUsage52B"); } # end print_usage #--------------------------------------------------------------------# # remove_locked_errors - Scans the input varaible for the resource # # locked error messages. If one is found, the function returns # # true and the new error array has this error removed. # # The c-api command errors are found by searching each output line # # for "ERROR" at the beginning of the line. Locked is flagged by # # the 65551 error code. # # # # Parameters: # # @command_output The output from the command. # # # # Returns: # # $rc 0 if no locked errors found. # # 1 if locked errors found. # # @errorless_output The original @command_output array contents # # with the errors removed. # # # # Global Variables: # #--------------------------------------------------------------------# sub remove_locked_errors { my @command_output = @_; # command output to scan my @errorless_output = (); # errors removed my $line = ""; # part of an array my $rc = 0; # none found yet # scan each line for ERROR foreach $line (@command_output) { # does it start with ERROR? if (!($line =~ /^ERROR.*/)) { # put it in the errorless array push @errorless_output, $line; } else { # check for the 65551 return code if (!($line =~ /${DELIMITERO}65551${DELIMITERO}/)) { # put it in the errorless array push @errorless_output, $line; } else { # it had it $rc = 1; } } } return ($rc, @errorless_output); } # end of remove_api_error #--------------------------------------------------------------------# # get_locked_list - finds either the list of locked responses for # # a condition or the list of locked conditions for a response. # # # # Parameters: # # $locator where the condition/response is # # $select_str the selection string for either condition or # # response # # $attr_name either ConditionHandle or EventResponseHandle # # # # Returns: # # $resp_names list of condition/response handles # # # # Global Variables: # # $main::Trace in case trace is on # # $main::PROGNAME for trace message # # $CTBINDIR where list command resides # # $RSCASSC Association class # #--------------------------------------------------------------------# sub get_locked_list { my $locator = shift(@_); # locator my $select_str = shift(@_); # locked select string my $attr_name = shift(@_); # attribute (cond/resp) to get my $rc = 0; # return code my @handles = (); # resource handles my $i = 0; # counter # get the list of conditions/responses that are locked for this response/condition. # re-establish original CT_MANAGEMENT_SCOPE set_orig_rmc_scope; # if no locator, use local scope. if ($locator eq "") { # set CT_MANAGEMENT_SCOPE to local for query $ENV{CT_MANAGEMENT_SCOPE} = $RMC_LOCAL_SCOPE; } # use DM/SR/Local scope if scope not set and there's a locator else { check_set_cluster_scope; } $main::Trace && print STDERR "$main::PROGNAME: calling lsrsrc-api\n"; $main::Trace && ($trace_opt = " -T "); # escape quotes in the selection string $select_str =~ s/\"/\\\"/g; # find the condition or response handles. @handles=`$CTBINDIR/lsrsrc-api -I $DELIMITERI -D $DELIMITERO -a $attr_name -s ${RSCASSC}${DELIMITERI}"$select_str" && Locked==1 2>&1`; $rc = $?; $rc = &process_exit_code($rc); $main::Trace && print STDERR "lsrsrc-api results:\n"; $main::Trace && print STDERR "@handles"; $main::Trace && print STDERR "$main::PROGNAME: lsrsrc-api returned $rc\n"; # show any errors if ($rc != 0) { &process_api_error($DELIMITERO,$rc,@handles); } # output from lsrsrc-api is list of condition RHs or event response RHs # get rid of crlf for ($i=0; $i<=$#handles; $i++) { chomp $handles[$i]; } # return the array return (@handles); } # end of get_locked_list #--------------------------------------------------------------------# # find_names_from_rhs - finds the names of the resources specified # # by their resource handles. # # # # Parameters: # # $locator where the condition/response is # @rh_array array of resource handles. # # # # Returns: # # @names array of the names found. # # # # Global Variables: # # $main::Trace in case trace is on # # $main::PROGNAME for trace message # # $CTBINDIR where list command resides # # $LSRSRC RMC CLI list command # # $RSCASSC Association class # #--------------------------------------------------------------------# sub find_names_from_rhs { my $locator = shift(@_); # locator my @rh_array = @_; # resource handle input array my @names = (); # names of the resources my $name = ""; # name of the resource my @listout = (); # lsrsrc-api output my $rh = ""; # resource handle my $cmd_rhs = ""; # handles for lsrsrc-api my $i = 0; # counter # build the command to give to lsrsrc-api. foreach $rh (@rh_array) { chomp($rh); # make sure we know where the quotes are $rh =~ s/"//g; # build lsrsrc-api command using -r format for resource handle. # handle is unique is cluster so locator is not needed. $cmd_rhs = $cmd_rhs . " -r \"$rh\""; } # re-establish original CT_MANAGEMENT_SCOPE set_orig_rmc_scope; # if no locator, use local scope. if ($locator eq "") { # set CT_MANAGEMENT_SCOPE to local for query $ENV{CT_MANAGEMENT_SCOPE} = $RMC_LOCAL_SCOPE; } # use DM/SR/Local scope if scope not set and there's a locator else { check_set_cluster_scope; } $main::Trace && print STDERR "$main::PROGNAME: calling lsrsrc-api\n"; $main::Trace && ($trace_opt = " -T "); # find the condition and response names. @listout = `$CTBINDIR/lsrsrc-api -I $DELIMITERI -D $DELIMITERO -a Name $cmd_rhs 2>&1`; $rc = $?; $rc = &process_exit_code($rc); $main::Trace && print STDERR "lsrsrc-api results:\n"; $main::Trace && print STDERR "@listout"; $main::Trace && print STDERR "$main::PROGNAME: lsrsrc-api returned $rc\n"; # show any errors if ($rc != 0) { &process_api_error($DELIMITERO,$rc,@listout); } # output from lsrsrc-api is name # get names for ($i=0; $i <= $#listout; $i++) { $name = $listout[$i]; chomp($name); push @names, $name; } # return the names return (@names); } # end of find_names_from_rhs