# TLem.def: Diagnoses Oracle Enterprise Manager # $Id: TLem.def,v 1.9 2008/02/08 15:07:18 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/TLem.def,v 1.9 2008/02/08 15:07:18 mschenke Exp $ # # Change History # 20080207 DEM Check for DB connection and diagkit existance. =head1 NAME TLem - Executes Enterprise Manager Diagkit Tests. =head1 DESCRIPTION This tool executes one or more tests from an Enterprise Manager Diagkit module. When specified, the test module attempts to fix problems. =head1 REQUIREMENTS IMPORTANT: The system must have Enterprise Manager Diagkit installed in the repository to use this module. =head1 USAGE -T em Can select the tests interactively. [-e EM_SID=] -T em:::: [-e EM_SID=] -T em::: [-e EM_SID=] -T em:: [-e EM_SID=] -T em: Can specify the parameter at the command line. Problems are fixed automatically only if C is specified explicitly as the value for the latest argument. No attempt will be made otherwise. Level 1 is assumed by default. All tests of the module are performed unless a test identifier is specified. The C setting can provide the default repository database identifier. When the setting is not defined, the C and C environment variables are successively considered. The C user is used by default for executing the tests. An alternative user can be specified through the C setting. =cut echo tput('bold'),'Processing EM tests ...',tput('off') # Initialisation var $LOGIN = uc(getSetting('EM_LOGIN','SYSMAN')) var $VIOLATION_AGE = getSetting('EM_VIOLATION_AGE',15) var $TOC = '%TOC%' var $TOP = '[[#Top][Back to top]]' call setAbbr('EM') # Validate the age if !isNumber($VIOLATION_AGE) var $VIOLATION_AGE = 15 # Define the SQL logins loop $key (grepSetting('^SQL_PASSWORD_')) {if match($key,'^SQL_PASSWORD__([\+\w]+)__(.*)$') {var ($sid,$usr) = (last) var $sid = replace($sid,'plus','+',true) } else var ($usr,$sid) = (substr($key,13)) call setSqlLogin($usr,unpack('u',getSetting($key)),$sid) } loop $key (grepSetting('^SQL_PASS_\d+$')) {var ($usr,$sid) = split('\@',getSetting(replace($key,'_PASS_','_USER_')),2) call setSqlLogin($usr,unpack('u',getSetting($key)),$sid) } # Determine the database context if length(getSetting('EM_SID')) var $sid = getSetting('EM_SID') else {if getEnv('TWO_TASK') var $sid = last elsif getEnv('ORACLE_SID') var $sid = last if !getSetting('TST_ARGS') {call setTempSetting('EM_SID',$sid) call setTempSetting('EM_SETUP_PHASE','db') call requestSetting('TLem') var $sid = getSetting('EM_SID') } if !length($sid) {echo 'Missing information to connect to the remote database.' return } } # Determine the user password if hasSqlPassword($LOGIN,$sid) var $pwd = undef else var $pwd = askPassword(concat('Enter ',$LOGIN,'@',$sid,' user password:')) # Change the current user var $old = setSqlLogin($LOGIN,$pwd,$sid) # Check the database connection if testSql() {echo '**Repository database connection disabled**%BR%',getSqlMessage() call setSqlLogin($old) return } #Check for existence of EMdiag kit var ($hdr,$col) = getSqlColumns('RDA','','SYSMAN.MGMT$DIAG_INFO',\ 'CATEGORY','INFO') call clearSqlColumns('RDA') if !$col {echo 'The EMDIAG kit is not installed' call setSqlLogin($old) return } # Command line arguments if getSetting('TST_ARGS') {debug ' Inside EM tool, validating input' var ($mod,$tst,$lvl,$fix) = split(':',last) if $mod {if match($mod,'\W') {echo 'Invalid module name' call setSqlLogin($old) return } set $sql {SELECT 'X' " FROM sysman.mgmt_rep_diag " WHERE enabled = 1 " AND mgmt_diag.RepType = NVL(reptype,mgmt_diag.RepType) " AND mgmt_diag.RepVersion BETWEEN NVL(min_version,mgmt_diag.RepVersion) " AND NVL(max_version,mgmt_diag.RepVersion) " AND module = ':1'; } if !grepSql(bindSql($sql,$mod),'X','f') {call setSqlLogin($old) die 'Module ',$mod,' not found in the diagkit to analyze' } # Determine the test identifier if $tst {if match($tst,'\D') {echo 'The test identifier ',$tst,' must be an integer number' call setSqlLogin($old) return } if $tst {set $sql {SELECT 'X' " FROM sysman.mgmt_rep_diag " WHERE enabled = 1 " AND mgmt_diag.RepType = NVL(reptype,mgmt_diag.RepType) " AND mgmt_diag.RepVersion BETWEEN NVL(min_version,mgmt_diag.RepVersion) " AND NVL(max_version,mgmt_diag.RepVersion) " AND module = ':1' " AND id = :2; } if !grepSql(bindSql($sql,$mod,$tst),'X','f') {call setSqlLogin($old) die 'No test ',$tst,' found in the ',$mod,' module' } } else var $tst = 0 } else var $tst = 0 # Determine the test level if defined($lvl) {if !and(match($lvl,'^\d+$'),expr('>=',$lvl,0),expr('<=',$lvl,9)) {echo 'The test level should be an integer from 0 to 9.' call setSqlLogin($old) return } } else var $lvl = 1 # Determine the fix flag var $fix = compare('eq',lc($fix),'fix') } } else {# Define a macro to generate menu items macro mk_menu {var ($sql,%tbl) = @arg var $cnt = 0 loop $lin (grepSql($sql,'^\d*=')) {incr $cnt if key($lin) var $key = last else var $key = $cnt var $tbl{$key} = value($lin) } return join('|',%tbl) } # Determine the module set $sql {SELECT DISTINCT '=' || module " FROM sysman.mgmt_rep_diag " WHERE enabled = 1 " AND mgmt_diag.RepType = NVL(reptype,mgmt_diag.RepType) " AND mgmt_diag.RepVersion BETWEEN NVL(min_version,mgmt_diag.RepVersion) " AND NVL(max_version,mgmt_diag.RepVersion); } if !mk_menu($sql) {echo 'No module has been found. Please check Diagkit installation.' call setSqlLogin($old) return } call setTempSetting('EM_MENU',last) call setTempSetting('EM_SETUP_PHASE','module') call requestSetting('TLem') var $mod = getSetting('EM_MODULE') # Get other test elements set $sql {SELECT id || '=' || label " FROM sysman.mgmt_rep_diag " WHERE enabled = 1 " AND mgmt_diag.RepType = NVL(reptype,mgmt_diag.RepType) " AND mgmt_diag.RepVersion BETWEEN NVL(min_version,mgmt_diag.RepVersion) " AND NVL(max_version,mgmt_diag.RepVersion) " AND module = ':1' " ORDER BY id ASC; } call mk_menu(bindSql($sql,$mod),0,'All tests') call setTempSetting('EM_MENU',last) call setTempSetting('EM_SETUP_PHASE','test') call requestSetting('TLem') var $tst = getSetting('EM_TEST') var $lvl = getSetting('EM_LEVEL') var $fix = getSetting('EM_FIX') } echo 'Module: ',$mod echo 'Test: ',cond($tst,$tst,'All') echo 'Level: ',$lvl echo 'Autofix: ',cond($fix,'Yes','No') echo # Execute the tests set $sql {SET serveroutput on "BEGIN " sysman.mgmt_diag.VerifyModule(':1',:2,:3,:4); "END; "/ } if !loadSql(bindSql($sql,$mod,$tst,$lvl,cond($fix,'true','false'))) echo "Problem when executing Diagkit tests:\012",getSqlMessage() elsif getSqlLines() {loop $lin (last) echo $lin } else echo 'No problem reported' =begin credits =over 10 =item RDA 4.7: Werner De Gruyter. =back =end credits =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