# HCVEinfo.def: Defines Health Check/Validation Engine Macros # $Id: HCVEinfo.def,v 1.23 2008/02/25 17:32:54 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/HCVEinfo.def,v 1.23 2008/02/25 17:32:54 mschenke Exp $ # # Change History # 20080225 MSC Change the copyright notice. =head1 NAME HCVEinfo - Defines Health Check/Validation Engine Macros =head1 DESCRIPTION This persistent sub module regroups macros to perform health check rules within RDA. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('dsp_hcve_results','exe_hcve_rules','get_hcve_rules',\ 'val_hcve_rules','wrt_hcve_errors','wrt_hcve_man',\ 'wrt_hcve_results','fmt_hcve_act','fmt_hcve_str',\ 'fmt_hcve_val','rpl_hcve_ref') # Define HCVE variables keep $hc_err,$hc_hlt,$hc_ini,$hc_nam,%tb_rid,%tb_rul keep %tb_max,%tb_min,%tb_mod,%tb_msg,%tb_nam,%tb_res,%tb_tst,%tb_typ,%tb_val var ($hc_err,$hc_hlt,$hc_ini,$hc_nam,%tb_rid,%tb_rul,\ %tb_max,%tb_min,%tb_mod,%tb_msg,%tb_nam,%tb_res,%tb_tst,%tb_typ,%tb_val\ ) = (0,0) =head2 S This macro loads the validation rules. It returns 0 on successful completion, -1 for parsing errors at file load, or the rule index for a missing identifier. By default, the module is searched in the hcve directory. =cut macro get_hcve_rules {var ($fil) = @arg import $hc_err,$hc_hlt,$hc_ini,$hc_nam,%tb_rid,%tb_rul, var ($cnt,$hc_err,$hc_hlt,%tb_rid,%tb_rul) = (0,0,0,$nam) # Load the rules var $xml = xmlLoadFile($fil) if xmlError() return -1 # Validate the rules loop $rul (xmlFind($xml,'.../rule')) {# Validate the rule identifier var $rid = xmlValue($rul,'id') incr $cnt if !defined($rid) return $cnt var $ref = sprintf('%05d',$rid) var $tb_rul{$ref} = $rul var $tb_rid{$ref} = $rid } # Indicate a successful completion var ($top) = xmlFind($xml,'hcve') var $hc_ini = xmlValue($top,'init') var $hc_nam = xmlValue($top,'name') return 0 } =head2 S This macro validates the rules and returns a list of error messages. =cut macro val_hcve_rules {import %tb_rid,%tb_rul var @err = () loop $ref (keys(%tb_rul)) {var $rul = $tb_rul{$ref} var $rid = $tb_rid{$ref} var $str = uc(xmlValue($rul,'mode','?')) if !match($str,'^(LOG|RECORD|VERIFY(_ABORT)?)$') var @err = (@err,concat('Invalid mode ',$str,' in rule ',$rid)) var $str = uc(xmlValue($rul,'command_type','?')) if !match($str,'^(ATTACH|OS|PERL|PROMPT|SQL)$') var @err = (@err,concat('Invalid command type ',$str,' in rule ',$rid)) } # Return the error list return @err } =head2 S This macro executes the validation rules. =cut macro exe_hcve_rules {import $hc_err,$hc_hlt,$hc_ini,$hc_nam,%tb_rid,%tb_rul import %tb_max,%tb_min,%tb_mod,%tb_msg,%tb_nam,%tb_res,%tb_tst,%tb_typ,%tb_val var ($hc_err,$hc_hlt,%tb_max,%tb_min,%tb_msg) = (0,0) debug 'Executing the ',$hc_nam,' validation rules' call setHcveContext(nvl($hc_ini,'HCVEinit')) loop $ref (keys(%tb_rul)) {var $rul = $tb_rul{$ref} var $rid = $tb_rid{$ref} var $mod = uc(xmlValue($rul,'mode','?')) var $nam = xmlValue($rul,'name',$rid) var $tst = xmlValue($rul,'condition','') var $typ = uc(xmlValue($rul,'command_type','?')) # Get the value call setHcveRule($rid) var ($cmd,$val,$msg) = (rpl_hcve_ref(xmlData(xmlFind($rul,'command')))) if !$cmd var ($val,$msg) = ('NA','Cmd:Missing command') elsif compare('eq',$typ,'ATTACH') {if !testFile('rf',$cmd) var ($val,$msg) = ('NA',concat("Cmd:ATTACH ",$cmd,\ "\012Result: Cannot find or read the file")) else {var $val = basename($cmd) data concat('hcve_',$val) if !writeData($cmd) var ($val,$msg) = ('NA',concat("Cmd:ATTACH ",$cmd,\ "\012Result: Copy failed")) } var $mod = 'ATTACH' } elsif compare('eq',$typ,'OS') {var $val = trim(join("\012",command($cmd))) if status() var ($val,$msg) = ('NA',concat("Cmd:",$cmd,\ "\012Result:",$val,\ "\012Exit code:",last)) } elsif compare('eq',$typ,'PERL') {var $pgm = getSetting('RDA_PERL') if $pgm {var $cmd = replace($cmd,'"','\"',true) var $cmd = replace($cmd,'\$','\$',true) var $cmd = replace($cmd,"\012",' ',true) if loadCommand(concat($pgm,' -e "',$cmd,'"')) var $val = trim(join("\012",getLines())) else var ($val,$msg) = ('NA',concat("Cmd:",$cmd,\ "\012Result:",$val,\ "\012Exit code:",statCommand())) } else var ($val,$msg) = ('NA',concat("Cmd:",$cmd,\ "\012Result: Perl not available")) } elsif compare('eq',$typ,'RDA') {var $err = evalHcveAction($cmd) if $err var ($val,$msg) = ('NA',concat("Cmd:",$cmd,\ "\012Result:",$val,\ "\012Exit code:",$err)) else var $val = getHcveResult() } elsif compare('eq',$typ,'PROMPT') {call setTempSetting('HCVE_VARIABLE',$cmd) call setTempSetting('HCVE_DEFAULT',rpl_hcve_ref(xmlValue($rul,'minimum'))) call requestSetting('HCVEinfo') var $val = getSetting('HCVE_PROMPT') } elsif compare('eq',$typ,'SQL') {if !loadSql(join("\012","SET define on",$cmd)) var ($val,$msg) = ('NA',concat("cmd:",$cmd,\ "\012Result:",\ join("\012",grepLastSql('.')),\ "\012returncode:",getSqlMessage())) elsif grepLastSql('^(ORA|SP2)-\d+') var ($val,$msg) = ('NA',concat("cmd:",$cmd,\ "\012Result:",\ join("\012",grepLastSql('.')))) else var $val = trim(join("\012",grepLastSql('.?'))) } else var ($val,$msg) = ('NA',concat('Cmd:Invalid command type ',$typ)) # Perform the validation var $res = 'FAILED' if $msg {debug sprintf('Executing Rule: [%5d] %-20.20s - error encountered.',\ $rid,$nam) var $res = '-ERROR' var $tb_msg{$rid} = $msg incr $hc_err } else {debug sprintf('Executing Rule: [%5d] %-20.20s - completed.',\ $rid,$nam) if compare('eq',$mod,'ATTACH') var $res = 'ATTACH' elsif compare('eq',$mod,'LOG') var $res = 'LOGGED' elsif compare('eq',$mod,'RECORD') var $res = 'RECORD' elsif match($mod,'VERIFY(_ABORT)?',true) {var $flg = false var $min = rpl_hcve_ref(xmlValue($rul,'minimum')) var $tb_min{$rid} = $min if compare('eq',$tst,'=~') var $flg = match($val,$min) elsif and(isNumber($val),isNumber($min)) {if match($tst,'^([=!]=|[<>]=?)$') var $flg = expr($tst,$val,$min) elsif match($tst,'^B',true) {var $max = rpl_hcve_ref(xmlValue($rul,'maximum')) var $tb_max{$rid} = $max var $flg = and(expr('>=',$val,$min),expr('<=',$val,$max)) } } else {if match($tst,'^([=!]=|[<>]=?)$') var $flg = compare($tst,$val,$min) elsif match($tst,'^B',true) {var $max = rpl_hcve_ref(xmlValue($rul,'maximum')) var $tb_max{$rid} = $max var $flg = and(compare('ge',$val,$min),compare('le',$val,$max)) } } if $flg var $res = 'PASSED' } } # Store the rule result for further reference var $tb_mod{$rid} = $mod var $tb_nam{$rid} = $nam var $tb_res{$rid} = $res var $tb_tst{$rid} = $tst var $tb_typ{$rid} = $typ var $tb_val{$rid} = setHcveResult($val) # Check if the rule execution must be aborted if compare('eq',$mod,'VERIFY_ABORT') {if match($res,'(FAILED|-ERROR)') {var $hc_hlt = $rid break } } } } =head2 S This macro reports the test results on the screen. =cut macro dsp_hcve_results {import $hc_err,$hc_hlt,$hc_nam,%tb_rid,%tb_rul import %tb_mod,%tb_nam,%tb_res,%tb_val # Display the page header echo "\012Test \042",$hc_nam,"\042 executed at ",localtime() echo "\012Test Results\012~~~~~~~~~~~~\012" echo sprintf("%5s %-20s %-6s %-s","ID","NAME","RESULT","VALUE") echo "===== ==================== ====== ===================================\ =====" # Display a rule overview loop $ref (keys(%tb_rul)) {var $rid = $tb_rid{$ref} # Determine the value contribution if and(compare('eq',$tb_mod{$rid},'LOG'),\ compare('ne',$tb_res{$rid},'-ERROR')) var $val = 'See Log' else {var $val = replace($tb_val{$rid},"\012",' ',true) if expr('>',length($val),40) var $val = concat(substr($val,0,37),'..>') } # Display the rule result echo sprintf('%5d %-20.20s %-6s %s',\ $rid,$tb_nam{$rid},$tb_res{$rid},nvl($val,'')) # Check when if abort occurred if expr('==',$rid,$hc_hlt) {var $sep = repeat('-',getSetting('RDA_COLUMNS',78)) echo $sep if compare('eq',$tb_res{$rid},'-ERROR') echo "(ABORT) Execution of rule \042",$tb_nam{$rid},"\042 completed with \ errors." else echo "(ABORT) Execution of rule \042",$tb_nam{$rid},"\042 was FAILED." echo 'To be able to continue with remaing tests, this test has to be PASSED.' echo $sep break } } # Report execution errors if $hc_err echo "\012Execution of ",$hc_err," rule(s) completed with errors." } =head2 S This macro writes the test errors in the output file. =cut macro wrt_hcve_errors {var ($ttl) = @arg import $hc_nam,%tb_msg,%tb_rid # Report error details if $ttl {prefix {write $ttl write 'Tests "',$hc_nam,'" executed at ',gmtime('%d-%b-%Y %X') } } loop $ref (keys(%tb_rid)) {var $rid = $tb_rid{$ref} next missing($tb_msg{$rid}) write '---' write '(Error) Execution of rule ',$rid,' failed.' write '---' write replace($tb_msg{$rid},"\012",'%BR%',true) } unprefix } =head2 S This macro writes a complete description of the specified rule set. =cut macro wrt_hcve_man {var ($set) = @arg import $TOC,$TOP var %typ = ('A','Pre-Install','P','Post-Install') var %tst = ('==','',\ '!=','a result different from ',\ '<', 'a result less than ',\ '<=','a result less than or equal to ',\ '>', 'a result greater than ',\ '>=','a result greater than or equal to ',\ '=~','a result matching ') # Load the rule set var $xml = xmlLoadFile(getHcveFile($set)) if xmlError($xml) return -1 # Produce a rule description write '---+!! ',getHcveName($set) write 'This HCVE rule set performs the following tests:' write $TOC write '---+ Generalities' write '|*Rule Set Type*|``',$typ{getHcveType($set)},'`` |' write '|*Platform*|``',getHcvePlatform($set),'`` |' write $TOP # Produce a rule description loop $rul (xmlFind($xml,'.../rule')) {var $typ = xmlValue($rul,'command_type') write '---' write '---+ Rule ',xmlValue($rul,'id'),': ',\ fmt_hcve_str(xmlValue($rul,'name')) if compare('eq',$typ,'PROMPT') {write '|*Prompt*|',fmt_hcve_str(xmlData(xmlFind($rul,'command'))),' |' write '|*Default Value*|',fmt_hcve_str(xmlValue($rul,'minimum')),' |' } else {write fmt_hcve_str(xmlData(xmlFind($rul,'description'))),'%BR%%BR%' if compare('eq',$typ,'OS') write "''Run the following command from the Operating System command line \ and record the result:''" elsif compare('eq',$typ,'PERL') write "''Run the following Perl code and record the result:''" elsif compare('eq',$typ,'RDA') write "''Run the following RDA code and record the result:''" elsif compare('eq',$typ,'SQL') write "''Run the following command from a SQL command prompt \ and record the result:''" else write "''",$typ,"''" write '' write xmlData(xmlFind($rul,'command')) write '' var $mod = xmlValue($rul,"mode") if match($mod,'VERIFY(_ABORT)?',true) {write "%BR%''If the RDA code returns \134" var $tst = xmlValue($rul,'condition') if match($tst,'^B',true) write "a result between ",fmt_hcve_val(xmlValue($rul,'minimum'))," and ",\ fmt_hcve_val(xmlValue($rul,'maximum')),"\134" else write nvl($tst{$tst},$tst),\ fmt_hcve_val(xmlValue($rul,'minimum')),"\134" write ", then your environment passes this test.''%BR%" loop $act (xmlFind($rul,concat('action type="positive"'))) {next !xmlData($act) var $str = last if !compare('eq',xmlValue($act,'syntax'),'wiki') var $str = fmt_hcve_act($str) write $str write } prefix write "%BR%''What to do if your system fails the test: %BR%''" loop $act (xmlFind($rul,concat('action type="negative"'))) {next !xmlData($act) var $str = last if !compare('eq',xmlValue($act,'syntax'),'wiki') var $str = fmt_hcve_act($str) write $str write } unprefix } } write $TOP } return 0 } =head2 S This macro writes the test results in the output file. When the flag is set, it also reports the details. =cut macro wrt_hcve_results {var ($ttl,$flg) = @arg import $hc_err,$hc_hlt,$hc_nam,%tb_rid,%tb_rul,$TOC,$TOP import %tb_max,%tb_min,%tb_mod,%tb_msg,%tb_nam,%tb_res,%tb_tst,%tb_val if $ttl {write $ttl write 'Tests "',$hc_nam,'" executed at ',gmtime('%d-%b-%Y %X') write write $TOC } # Report the test results write '---+ Test Results' write '| *Rule*|*Name*|*Result*|*Value*|' loop $ref (keys(%tb_rul)) {var $rid = $tb_rid{$ref} # Determine the value contribution if and(compare('eq',$tb_mod{$rid},'LOG'),\ compare('ne',$tb_res{$rid},'-ERROR')) var $val = 'See Log' else var $val = replace($tb_val{$rid},"\012",'%BR%',true) # Display the rule result var $res = $tb_res{$rid} if and($flg,match($res,'(FAILED|LOGGED|PASSED)')) var $res = concat('[[#Rule',$rid,'][',$res,']]') write '| ',$rid,'|',fmt_hcve_str($tb_nam{$rid}),' |',$res,' |',\ fmt_hcve_str($val),' |' # Check when if abort occurred if expr('==',$rid,$hc_hlt) {write '---' if compare('eq',$tb_res{$rid},'-ERROR') write '(ABORT) Execution of rule "',$tb_nam{$rid},'" completed with errors.' else write '(ABORT) Execution of rule "',$tb_nam{$rid},'" was FAILED.' write 'To be able to continue with remaing tests, this test has to be \ PASSED.' write '---' break } } if $hc_err write 'Execution of ',$hc_err,' rule(s) completed with errors.%BR%' write $TOP # Failure lists prefix {write '---+ Failure Summary' write '| *Rule*|*Description*|*Result*|*Action*|' } loop $ref (keys(%tb_rul)) {# Only consider failed rules var $rid = $tb_rid{$ref} next !compare('eq',$tb_res{$rid},'FAILED') # Get the result components var %val = () var $val = $tb_val{$rid} if isNumber($val) var $val{xmlValue($rul,'name')} = 0 loop $val (split('[\|\012]',$tb_val{$rid})) var $val{replace($val,'\[.*?\]','...',true)} = 1 # Determine the action var $rul = $tb_rul{$ref} var @act = () loop $act (xmlFind($rul,concat('action type="negative"'))) {next !xmlData($act) var $str = rpl_hcve_ref(last) if compare('eq',xmlValue($act,'syntax'),'wiki') {loop $lin (split("\012",$str)) {if match($lin,'^\s*\|([^\|]+)\|(.*)\|\s*$') {var ($val,$act) = (last) if $val{trim($val)} var @act = (@act,fmt_hcve_str($act)) } elsif !match($lin,'^\s*\|.*\|\s*$') var @act = (@act,fmt_hcve_str($lin)) } } else var @act = (@act,fmt_hcve_act($str)) } # Print the rule details write '| ',$rid,'|',fmt_hcve_str(xmlData(xmlFind($rul,'description'))),' |',\ fmt_hcve_str(replace($tb_val{$rid},'[\[\]]','',true)),' |',\ join('%BR%',@act),' |' } if hasOutput(true) write $TOP # Report detailed results if $flg {var $TTL = '---+ Detailed Results' loop $ref (keys(%tb_rul)) {var $rul = $tb_rul{$ref} var $rid = $tb_rid{$ref} # Determine the action type if compare('eq',$tb_res{$rid},'PASSED') var $typ = 'positive' elsif compare('eq',$tb_res{$rid},'FAILED') var $typ = 'negative' else next # Print the actions prefix {write $TTL var $TTL = '---' write '#Rule',$rid,' ---## Rule ',$rid,': ',fmt_hcve_str($tb_nam{$rid}) write '---### Description' write fmt_hcve_str(xmlData(xmlFind($rul,'description'))) write '---### Test Result' write '**',$tb_res{$rid},'**%BR%' write fmt_hcve_str(join(' ',$tb_val{$rid},$tb_tst{$rid},$tb_min{$rid},\ $tb_max{$rid})) write '---### Action' } loop $act (xmlFind($rul,concat('action type="',$typ,'"'))) {next !xmlData($act) var $str = rpl_hcve_ref(last) var $str = cond(compare('eq',xmlValue($act,'syntax'),'wiki'),\ getHcveValues($str),\ fmt_hcve_act($str)) write $str write } if hasOutput(true) write $TOP } # Report logged results prefix write '---+ Logged Results' loop $ref (keys(%tb_rul)) {var $rid = $tb_rid{$ref} next compare('ne',$tb_res{$rid},'LOGGED') write '#Rule',$rid,' ---## Rule ',$rid,': ',fmt_hcve_str($tb_nam{$rid}) write '' write $tb_val{$rid} write '' } if hasOutput(true) write $TOP } } # --- Internal errors --------------------------------------------------------- # Define a macro to remove references macro rpl_hcve_ref {var ($str) = @arg # Reject missing or empty string if !$str return $str # Replace the references var $chr = "\224" import %tb_val while match($str,'(%+(.*?)%+)') {var ($ref,$rid) = (last) var $val = $tb_val{$rid} if match($val,'^NA') return 'NA:' if defined($val) var $str = replace($str,concat('%+',$rid,'%+'),$val,true) else {# Escape when not a reference var $ref = replace($ref,'%!','%') var $ref = replace($ref,'!%','%') var $ref = replace($ref,'%',$chr,true) var $str = replace($str,concat('%+',$rid,'%+'),$ref,true) } } return replace($str,$chr,'%',true) } # Format an action macro fmt_hcve_act {var $str = $arg[0] var $str = replace($str,'<[Pp][Rr][Ee]>','%PRE%',true) var $str = replace($str,'','%/PRE%',true) var $str = fmt_hcve_str($str) var $str = replace($str,'%PRE%','
',true)
 var $str = replace($str,'%/PRE%','
',true) return $str } # Format a string macro fmt_hcve_str {var $str = encode(getHcveValues($arg[0])) var $str = replace($str,'\|','|',true) var $str = replace($str,'\*','*',true) var $str = replace($str,"\012",'%BR%',true) return $str } # Format a value macro fmt_hcve_val {var $val = $arg[0] if isNumber($val) return $val return concat('"',$val,'"') } =head1 SEE ALSO See also L. =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut