# IASs11g.def: Collects Oracle Application Server 11g Information (Single Instance)
# $Id: IASs11g.def,v 1.20 2008/02/08 14:55:19 mschenke Exp $
# ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/IASs11g.def,v 1.20 2008/02/08 14:55:19 mschenke Exp $
#
# Change History
# 20080206  KRA  Change umask for wallet creation.
#                Use asctl shell with -backGround true option.

=head1 NAME

IASs11g - Collects Oracle Application Server 11g Information (Single Instance)

=head1 DESCRIPTION

This module collects Oracle Application Server 11g-related information (such as
MAS Agent, MAS, dumpMetrics, Oracle HTTP Server, JAVACACHE, LDAP, and SYSMAN)
for a single Oracle instance.

=head1 REPORTS

=cut

echo tput('bold'),'Processing Oracle Application Server 11g module ...',\
     tput('off')

# Initialization
import $APACHE_TOP,$ORACLE_HOME
var $ORACLE_INSTANCE = getSetting('AS11G_OI','')
var $AS_TYPE         = getSetting('AS11G_TYPE')
var $TAIL            = getSetting('RDA_TAIL',1000)

var $IAS_INSTALL    = catDir($ORACLE_HOME,'install')
var $JAVACACHE_HOME = catDir($ORACLE_HOME,'javacache')
var $LDAP_HOME      = catDir($ORACLE_HOME,'ldap')
var $SYSMAN_HOME    = catDir($ORACLE_HOME,'sysman')

var $OH  = quote($ORACLE_HOME)
var $OH1 = concat('^',$OH,'[\\\/]')
var $OH2 = concat('^',$OH,'\b')

var $OI  = quote($ORACLE_INSTANCE)
var $OI1 = concat('^',$OI,'[\\\/]')
var $OI2 = concat('^',$OI,'\b')

var $TOC = '%TOC%'
var $TOP = '[[#Top][Back to top]]'

set $NOT_OWNER_STATEMENT
{**Please note:**
"
"The RDA was executed with an operating system user which is different from
"the operating system user who installed the Oracle Application Server 11g.
"
"Therefore, no information are available in this section.
"
}

# Instance variables
var $bas = basename($ORACLE_INSTANCE)

# Load the common variable and macro
var %HTTPDCONF
run IAS()

# Define the internal counter and duplicate file hash
var ($CNT,%DUP) = (0)

# Define the file sorting macro
macro sort_results
{var ($lvl,$lgt,$pre,$pat,@fil) = @arg
 import $CNT,$TOP,%DUP
 keep $CNT,$TOP,%DUP

 # Filter the file list
 loop $fil (@fil)
 {if $pat
   next !testFile('frT',$fil)
  next match($fil,'\.(bmp|exe|gif|jar|jpe?g|wav|wbmp)$',true)
  var $fil{join("\001",dirname($fil),basename($fil))} = $fil
 }

 # Generate the reports and related index links
 var $lst = ''
 var $det = $lvl
 incr $det
 loop $fil (keys(%fil))
 {var $fil = $fil{$fil}

  # Check for a new section
  var $grp = dirname($fil)
  if compare('ne',$grp,$lst)
  {var $lst = $grp
   toc $lvl,':',cond($pat,replace($grp,$pre,$pat),$grp),' '
  }

  # Create the report associated with the file
  debug '  Inside sort_results, getting ',$fil
  var $nam = basename($fil)
  if missing($DUP{$fil})
  {incr $CNT
   report concat('log',$CNT,'_',$nam)
   if !$pat
   {prefix
    {write '---+ Display of ',$nam,' File'
     write '---## Information Taken from ',$fil
    }
    var ($min,$max) = getDataValue($fil)
    call writeLines($pre,$min,$max)
    if hasOutput()
     write $TOP
   }
   elsif match($nam,'^USData.xml$',true)
   {write '---+ Display of ',$nam,' File'
    write '---## Information Taken from ',$fil
    call statFile('b',$fil)
    write '**File was not collected, because of the file size.**%BR%'
   }
   elsif match($fil,'(logs?[\/\\]|log$)',true)
   {if exists($LOG{$fil})
     var $cnt = $LOG{$fil}
    else
     var $cnt = $lgt
    if $cnt
     write '---+ Last ',$cnt,' Lines of ',$nam,' File'
    else
     write '---+ Display of ',$nam,' File'
    write '---## Information Taken from ',$fil
    call statFile('b',$fil)
    if $cnt
     call writeTail($fil,$cnt)
    else
     call writeFile($fil)
    write $TOP
   }
   else
   {write '---+ Display of ',$nam,' File'
    write '---## Information Taken from ',$fil
    call statFile('b',$fil)
    call writeFile($fil)
    write $TOP
   }
   var $rpt = getFile()
   if $pat
    var $DUP{$fil} = $rpt
  }
  if isCreated(true)
   toc $det,':[[',$rpt,'][rda_report][',$nam,']]'
 }
}

# Parse the output from asctl to the report
macro write_report
{var ($out) = @arg
 var $lvl = nvl($arg[1],0)
 import $TOP
 keep $TOP

 if createBuffer('OUT','R',$out)
 {loop $lin (grepBuffer('OUT','^\-{3}#\s+RDA:(BEGIN|END)','n'))
  {var ($num,undef,$cmd,$dat) = split(':',$lin,4)
   if compare('eq',$cmd,'BEGIN')
    var $beg = $num
   elsif compare('eq',$cmd,'BEGIN SECTION')
   {incr $lvl
    call clearData()
    pretoc $dat
   }
   elsif compare('eq',$cmd,'BEGIN TITLE')
   {var $lvl = 0
    toc $dat
   }
   elsif compare('eq',$cmd,'END FILE')
   {incr $beg
    decr $num
    if expr('>=',$num,$beg)
    {call addDataValue($dat,$beg)
     call addDataValue($dat,$num)
    }
   }
   elsif compare('eq',$cmd,'END REPORT')
   {var ($det,$lnk,$rep) = split('\|',$dat,3)
    report nvl(replace($rep,'[\/\\]','r',true),$lnk)
    prefix
     write '---+!! Display of ',$lnk
    incr $beg
    decr $num
    call writeLines($out,$beg,$num)
    if isCreated(true)
    {write $TOP
     toc $det,':[[',getFile(),'][rda_report][',$lnk,']]'
    }
   }
   elsif compare('eq',$cmd,'END SECTION')
   {if $dat
     call sort_results($dat,0,$out,false,getDataKeys())
    call clearData()
    if $lvl
    {unpretoc
     decr $lvl
    }
   }
  }
  call deleteBuffer('OUT')
 }
}

=head2 Oracle Application Server 11g

Gathers all general Oracle Application Server 11g information.

=cut

echo tput('bold'),' Gathering Oracle Application Server 11g Information ...',\
     tput('off')

toc '1:Oracle Application Server 11g (Single Instance)'

# Check the connection to the MAS
var $mas = false
var $shl = concat(catCommand($ORACLE_HOME,'bin','asctl')," script ")
if !compare('eq',$AS_TYPE,'DIS')
{# Validate the user inputs
 var $url = concat(getSetting('AS11G_SERVER'),':',\
                   getSetting('AS11G_PORT',9999))
 var $usr = getSetting('AS11G_USER')
 if !match($url,'^[\w\-\.\:]+$')
 {echo 'Invalid MAS connection'
  return
 }
 if !match($usr,'^\w+$')
 {echo 'Invalid MAS user'
  return
 }
 if getSetting('SQL_PASSWORD_ASCTL_USER')
  var ($pwd) = unpack('u',last)
 elsif getSetting('AS11G_PWD')
  var $pwd = last
 else
 {var $pwd = askPassword(concat('Enter ',$usr,' user password:'))
  call setTempSetting('AS11G_PWD',nvl($pwd,'?'))
 }

 # Create a wallet to store the password of MAS user
 var $msk = umask('0077')
 var $wlt = getTemp('wallet')
 var $out = getTemp('out')
 output P,concat(catCommand($ORACLE_HOME,'bin','asctl'),\
                 " -backGround true shell >",quote($out,'x'))
 write 'manageCommandWallet -location "',$wlt,\
       '" -name oracle.mas.password -user "',$usr,'" -set true'
 write $pwd
 write 'exit'
 close
 call unlinkTemp('out')
 call umask($msk)

 # Check the connection to the MAS
 var $job = getTemp('job','.py')
 var $out = getTemp('out')
 var $err = getTemp('err')
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x'),\
                                          " 2>",quote($err,'x')))
 if testFile('s',$err)
 {echo 'Error encountered when connecting to the MAS'
  report mas_error
  write '** Error encountered when connecting to the MAS **'
  write
  call writeFile($err)
  toc '2:[[',getFile(),'][rda_report][MAS Connection Error]]'
 }
 else
  var $mas = true
 call unlinkTemp('job')
 call unlinkTemp('out')
 call unlinkTemp('err')
}

=head2 Install and Configuration

Gathers the Oracle Application Server configuration and installation files.

=cut

debug '  Inside IASs11g module, gathering install and config information'
pretoc '2:Install and Configuration'
pretoc '3:Oracle Home'
call sort_results(4,$TAIL,$OH,'$OH',\
                  grepDir($IAS_INSTALL,'\.(ini|log)','dir'))
unpretoc
pretoc '3:Oracle Instance'
var (@cfg,@tbl) = ()
loop $cfg (grepDir(catDir($ORACLE_INSTANCE,'config'),\
                   '^(\.+|(OHS|OC4J)Component|AdminAgent)$','vp'))
{if testDir('d',$cfg)
  var @tbl = (@tbl,grepDir($cfg,'\.(properties|xml)$','dir'))
 elsif match($cfg,'\.(properties|xml)$')
  var @tbl = (@tbl,$cfg)
}
call sort_results(4,$TAIL,$OI,'$OI',@tbl)
unpretoc 2

debug '  Inside IASs11g module, gathering Oracle Application Server 11g \
         information'
pretoc '2:Oracle Application Server Information'
pretoc '3:Oracle Instance'
var (@cfg,@tbl) = ()
var @cfg = grepDir(catDir($ORACLE_INSTANCE,'diagnostics'),\
                   '^([\.]+|logs)$','vp')
loop $cfg (@cfg)
{if testDir('d',$cfg)
  var @tbl = (@tbl,grepDir($cfg,\
                           '(\.(conf|ini|xml|properties|err)$|\~|\.log)',\
                           'dir'))
 elsif match($cfg,'(\.(conf|ini|xml|properties|err)$|\~|\.log)')
  var @tbl = (@tbl,$cfg)
}
call sort_results(4,$TAIL,$OI,'$OI',@tbl)
unpretoc 2

# Check the user
var $uid   = getOwner(getToc(true))
var ($pgm) = grepDir(catDir($ORACLE_HOME,'bin'),'^asctl(\.(bat|exe))?$','fip')
var $own   = getOwner($pgm)
if compare('eq',$uid,$own)
 var $NOT_OWNER = false
else
{var $NOT_OWNER = true
 echo tput('reverse'),'Warning:'
 echo '========'
 echo 'The RDA is started as userid: ',$uid
 echo 'The Oracle Application Server 11g was installed on your system using \
       userid: ',nvl($own,'[not found]')
 echo 'The RDA script will continue, but it will skip some Oracle Application \
       Server 11g RDA steps.',tput('off')
}

=head2 MAS Agent

Gathers MAS agent configuration and log files.

=cut

echo tput('bold'),' Gathering MAS Agent Information ...',tput('off')

pretoc '%SPLIT%'
pretoc '1+:MAS Agent'

debug '  Inside IASs11g module, gathering MAS agent related config and log \
         files'
var $job = getTemp('job','.py')
var $out = getTemp('out','.txt')
if $mas
{pretoc '2:Oracle Instance'
 set $cod
 {def extractAgentFiles(ins,lgt):
 " cd(ins)
 " tb_com = listTopologyAttributes()
 " for i in range(0, len(tb_com)):
 "  com = tb_com[i]
 "  for j in range(0, len(com)):
 "   if com[j] == 'Directory':
 "    dir = com[j+2]
 " tb_com = ls(long=1)
 " com = tb_com.get("ChildTopoNodes")
 " for i in range(0, len(com)):
 "  if com[i].get("TopoNodeType") == 'AdminAgent':
 "   agt = com[i].get("TopoNodeName")
 "   cd(agt)
 "   tb_doc = listDocNames()
 "   print '\n---# RDA:BEGIN SECTION:3:Configuration Files\n'
 "   for doc in tb_doc:
 "    det = getDocAttributes(doc)
 "    loc = det.get("instanceHomeLocation")
 "    if len(loc):
 "     loc = re.sub(dir,"$OI",str(loc),1)
 "    else:
 "     loc = doc
 "    print '\n---# RDA:BEGIN'
 "    getDoc(name=doc)
 "    print '---# RDA:END FILE:' + loc + '\n'
 "   print '\n---# RDA:END SECTION:4\n'
 "   print '\n---# RDA:BEGIN SECTION:3:Log Queries\n'
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(last=1, timeUnit="d", \
                 groupBy=['TN_PATH', 'COMPONENT_ID', 'MODULE_ID', 'MSG_TYPE'])
 "   print '---# RDA:END REPORT:4|Activities over last 24 Hours|odl_24h_' + \
           ins + '_' + agt + '\n'
 "   tb_cid = displayLogs(last=1, timeUnit="d", groupBy="COMPONENT_ID", \
                          returnData=1)
 "   for cid in tb_cid.keys():
 "    try:
 "     qry = 'COMPONENT_ID eq ' + cid + \
             ' and MSG_TYPE eq ERROR or MSG_TYPE eq WARNING'
 "     print '\n---# RDA:BEGIN'
 "     displayLogs(tail=lgt, query=str(qry))
 "     print '---# RDA:END REPORT:4|Last Warnings and Errors for ' + cid + \
             '|odl_com_' + ins + '_' + agt + '_' + cid + '\n'
 "    except:
 "     pass
 "   print '\n---# RDA:END SECTION\n'
 "   tb_log = listLogs()
 "   print '\n---# RDA:BEGIN SECTION:3:Log Files\n'
 "   for log in tb_log:
 "    tb_fil = log.get("logFiles")
 "    for fil in tb_fil:
 "     pth = fil.get("canonicalPath")
 "     print '\n---# RDA:BEGIN'
 "     displayLogs(log=pth, tail=lgt, disconnected=1)
 "     print '---# RDA:END FILE:' + re.sub(dir,"$OI",pth,1) + '\n'
 "   print '\n---# RDA:END SECTION:4\n'
 "   print '\n---# RDA:BEGIN'
 "   dumpMetrics()
 "   print '\n---# RDA:END REPORT:3|dumpMetrics|dump_metrics_' + \
           ins + '_' + agt
 "   cd('..')
 " cd('..')
 "
 "extractAgentFiles(ins,TAIL)
 "
 }
 call writeTemp('job','import re')
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job','ins="',$bas,'"')
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out,1)
 unpretoc
}
else
{pretoc '2:Oracle Instance'
 if testDir('d',catDir($ORACLE_INSTANCE,'config','AdminAgent','AdminAgent'))
 {pretoc '3:Configuration Files'
  call sort_results(4,$TAIL,$OI,'$OI',\
                    grepDir(lastDir(),'\.(properties|xml)$','dir'))
  unpretoc
 }
 set $cod
 {print '\n---# RDA:BEGIN SECTION:3:Log Files\n'
 "tb_log = listLogs(oracleinstance=dir, disconnected=1)
 "for log in tb_log:
 " tb_fil = log.get("logFiles")
 " for fil in tb_fil:
 "  pth = fil.get("canonicalPath")
 "  if re.search('agent',pth):
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(oracleinstance=dir, log=pth, tail=TAIL, disconnected=1)
 "   print '---# RDA:END FILE:' + re.sub(dir,"$OI",pth,1) + '\n'
 "
 "print '\n---# RDA:END SECTION:4\n'
 "
 }
 call writeTemp('job','import re')
 call writeTemp('job','dir="',$ORACLE_INSTANCE,'"')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out,2)
 unpretoc
}
call unlinkTemp('job')
call unlinkTemp('out')
unpretoc 2

=head2 MAS/Topology

Collects the group and instances information, and the configuration and log
files of the Middleware Administration Server repository.

=cut

echo tput('bold'),' Gathering MAS Information ...',tput('off')
pretoc '%SPLIT%'
pretoc '1+:MAS/Topology'

=head3 MAS Configuration and Log Files

Collects Middleware Administration Server configuration and log files.

=cut

debug '  Inside IASs11g module, gathering MAS related config and log files'

if $mas
{var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {cd("/AdminServer")
 "print '\n---# RDA:BEGIN SECTION:2:MAS\n'
 "print '\n---# RDA:BEGIN SECTION:3:Configuration Files\n'
 "tb_doc = listDocNames()
 "for doc in tb_doc:
 " print '\n---# RDA:BEGIN'
 " getDoc(name=doc)
 " print '---# RDA:END REPORT:4|' + doc + '|' + doc + '\n'
 "
 "print '\n---# RDA:END SECTION\n'
 "print '\n---# RDA:BEGIN SECTION:3:Log Files\n'
 "tb_log = listLogs()
 "for log in tb_log:
 " tb_fil = log.get("logFiles")
 " for fil in tb_fil:
 "  pth = fil.get("canonicalPath")
 "  if re.search('(diagnostic\.log|log\.xml)$',pth):
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(log=pth, tail=TAIL, disconnected=1)
 "   print '---# RDA:END FILE:' + pth + '\n'
 "
 "print '\n---# RDA:END SECTION:4\n'
 "print '\n---# RDA:BEGIN SECTION:3:Service Configuration\n'
 "tb_svc = listServices()
 "for i in range(0, len(tb_svc)):
 " svc = tb_svc[i]
 " try:
 "  tb_doc = listDocNames(service=svc)
 "  for j in range(0, len(tb_doc)):
 "   doc = tb_doc[j]
 "   print '\n---# RDA:BEGIN'
 "   getDoc(name=doc, service=svc)
 "   print '---# RDA:END REPORT:4|'+ doc + '|' + doc + '\n'
 " except:
 "  pass
 "
 "print '\n---# RDA:END SECTION\n'
 "print '\n---# RDA:END SECTION\n'
 "
 }
 call writeTemp('job','import re')
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out,1)
 call unlinkTemp('job')
 call unlinkTemp('out')
}
elsif testDir('d',catDir($ORACLE_INSTANCE,'diagnostics','logs','MAS','server'))
{pretoc '2:Oracle Instance'
 pretoc '3:Log Files'
 call sort_results(4,$TAIL,$OI,'$OI',\
                   grepDir(lastDir(),'(diagnostic\.log|log\.xml)$','dir'))
 unpretoc 2
}

=head3 Group

Collects MAS group information. For each instance on which groups are found,
RDA gathers information about the components and applications.

=cut

debug '  Inside IASs11g module, gathering MAS group information'
if $mas
{var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {def extractMasGroup(grp):
 " cd(grp)
 " print "\n---# RDA:BEGIN SECTION:3:'" + grp + "' Group\n"
 " print '\n---# RDA:BEGIN'
 " status()
 " print '\n---# RDA:END REPORT:4|Status|grp_sta_' + grp + '\n'
 " print '\n---# RDA:BEGIN\n'
 " tb_mmb = ls(long=1)
 " print '\n---# RDA:END REPORT:4|Members|grp_mmb_' + grp + '\n'
 " mmb = tb_mmb.get("ChildTopoNodes")
 " for i in range(0, len(mmb)):
 "  if mmb[i].get("TopoNodeType") == 'OC4JComponent':
 "   nam = mmb[i].get("TopoNodeName")
 "   cd(nam)
 "   print '\n---# RDA:BEGIN\n'
 "   tb_com = ls(long=1)
 "   listTopologyAttributes()
 "   print "\n---# RDA:END REPORT:4|'" + nam + "' Component|g_" + \
           grp + '_' + nam + '\n'
 "   com = tb_com.get("ChildTopoNodes")
 "   for i in range(0, len(com)):
 "    if com[i].get("TopoNodeType") == 'OC4JApplication':
 "     app = com[i].get("TopoNodeName")
 "     cd(app)
 "     print '\n---# RDA:BEGIN\n'
 "     ls(long=1)
 "     listTopologyAttributes()
 "     print "---# RDA:END REPORT:5|'" + app + "' Application|g_" + \
             grp + '_' + nam + '_' + app + '\n'
 "     cd('..')
 "   cd('..')
 " print '\n---# RDA:END SECTION\n'
 " cd('..')
 "
 "print '\n---# RDA:BEGIN SECTION:2:Groups\n'
 "tb_top = ls(long=1)
 "top = tb_top.get("ChildTopoNodes")
 "for i in range(0, len(top)):
 " if top[i].get("TopoNodeType") == 'Group':
 "  extractMasGroup(top[i].get("TopoNodeName"))
 "
 "print '\n---# RDA:END SECTION\n'
 "
 }
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out,1)
 call unlinkTemp('job')
 call unlinkTemp('out')
}

=head3 Instance

Collects MAS information for the instances that are part of the farm. RDA
gathers information that includes the components and applications.

=cut

debug '  Inside IASs11g module, gathering MAS instances information'
var $job = getTemp('job','.py')
var $out = getTemp('out','.txt')
if $mas
{set $cod
 {def extractMasIns(ins,lgt):
 " cd(ins)
 " print "\n---# RDA:BEGIN SECTION:3:'" + ins + "' Instance\n"
 " print '\n---# RDA:BEGIN'
 " tree()
 " print '---# RDA:END REPORT:4|Instance Tree|ins_tree_' + ins + '\n'
 " print '\n---# RDA:BEGIN'
 " listTopologyAttributes()
 " print '---# RDA:END REPORT:4|Topology Attributes|ins_attr_' + ins + '\n'
 " print '\n---# RDA:BEGIN'
 " status()
 " print '---# RDA:END REPORT:4|Status|ins_sta_' + ins + '\n'
 " print '\n---# RDA:BEGIN SECTION:4:Log Queries\n'
 " print '\n---# RDA:BEGIN'
 " displayLogs(last=1, timeUnit="d", \
               groupBy=['TN_PATH', 'COMPONENT_ID', 'MODULE_ID', 'MSG_TYPE'])
 " print '---# RDA:END REPORT:5|Activities over last 24 Hours|odl_24h_i_' + \
         ins + '\n'
 " tb_cid = displayLogs(last=1, timeUnit="d", groupBy="COMPONENT_ID", \
                        returnData=1)
 " for cid in tb_cid.keys():
 "  try:
 "   qry = 'COMPONENT_ID eq ' + cid + \
           ' and MSG_TYPE eq ERROR or MSG_TYPE eq WARNING'
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(tail=lgt, query=str(qry))
 "   print '---# RDA:END REPORT:5|Last Warnings and Errors for ' + cid + \
           '|odl_com_i_' + ins + '_' + cid + '\n'
 "  except:
 "   pass
 " print '\n---# RDA:END SECTION\n'
 " print '\n---# RDA:BEGIN'
 " listIncidents()
 " print '\n---# RDA:END REPORT:4|Diagnostic Incidents|list_incidents'
 " tb_mmb = ls(long=1)
 " mmb = tb_mmb.get("ChildTopoNodes")
 " for i in range(0, len(mmb)):
 "  if mmb[i].get("TopoNodeType") == 'OC4JComponent':
 "   nam = mmb[i].get("TopoNodeName")
 "   cd(nam)
 "   print '\n---# RDA:BEGIN\n'
 "   tb_com = ls(long=1)
 "   listTopologyAttributes()
 "   print "\n---# RDA:END REPORT:4|'" + nam + "' Component|i_" + ins + '_' + \
           nam + '\n'
 "   com = tb_com.get("ChildTopoNodes")
 "   for i in range(0, len(com)):
 "    if com[i].get("TopoNodeType") == 'OC4JApplication':
 "     app = com[i].get("TopoNodeName")
 "     cd(app)
 "     print '\n---# RDA:BEGIN\n'
 "     ls(long=1)
 "     listTopologyAttributes()
 "     print "\n---# RDA:END REPORT:5|'" + app + "' Application|i_" + \
             ins + '_' + nam + '_' + app + '\n'
 "     cd('..')
 "   cd('..')
 " cd('..')
 " print '\n---# RDA:END SECTION\n'
 "
 "print '\n---# RDA:BEGIN SECTION:2:Instance\n'
 "extractMasIns(ins,TAIL)
 "print '\n---# RDA:END SECTION\n'
 "
 }
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job','ins="',$bas,'"')
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out)
}
else
{pretoc '2:Oracle Instance'
 set $cod
 {print '\n---# RDA:BEGIN'
 "status(oracleinstance=dir, disconnected=1)
 "print '\n---# RDA:END REPORT:3|Status|mas_sta\n'
 "print '\n---# RDA:BEGIN SECTION:3:Log Queries\n'
 "print '\n---# RDA:BEGIN'
 "displayLogs(oracleinstance=dir, disconnected=1, last=1, timeUnit="d", \
              groupBy=['TN_PATH', 'COMPONENT_ID', 'MODULE_ID', 'MSG_TYPE'])
 "print '\n---# RDA:END REPORT:4|Activities over last 24 Hours|odl_24h_i_\n'
 "tb_cid = displayLogs(oracleinstance=dir, disconnected=1, last=1, \
                       timeUnit="d", groupBy="COMPONENT_ID", \
                       returnData=1)
 "for cid in tb_cid.keys():
 " try:
 "  qry = 'COMPONENT_ID eq ' + cid + \
          ' and MSG_TYPE eq ERROR or MSG_TYPE eq WARNING'
 "  print '\n---# RDA:BEGIN'
 "  displayLogs(oracleinstance=dir, disconnected=1, tail=TAIL, query=str(qry))
 "  print '---# RDA:END REPORT:4|Last Warnings and Errors for ' + cid + \
          '|odl_comp_i_' + cid + '\n'
 " except:
 "  pass
 "
 "print '\n---# RDA:END SECTION\n'
 "print '\n---# RDA:BEGIN'
 "listIncidents(oracleInstance=dir)
 "print '\n---# RDA:END REPORT:3|Diagnostic Incidents|list_incidents\n'
 "
 }
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job','dir="',$ORACLE_INSTANCE,'"')
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out)
 unpretoc
}
call unlinkTemp('job')
call unlinkTemp('out')
unpretoc 2

=head2 dumpMetrics

Collects dumpMetrics and provides a starting point for analyzing performance
issues.

=cut

echo tput('bold'),' Gathering dumpMetrics Information ...',tput('off')
pretoc '%SPLIT%'
pretoc '1+:dumpMetrics'

debug '  Inside IASs11g module, gathering dumpMetrics'
if $NOT_OWNER
{report dump_metrics
 write '---+ dumpMetrics'
 write $NOT_OWNER_STATEMENT
 toc '2:[[',getFile(),'][rda_report][dumpMetrics]]'
}
elsif $mas
{var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {print '\n---# BEGIN dumpMetrics|dump_metrics'
 "dumpMetrics()
 "print '\n---# END'
 }
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out)
 call unlinkTemp('job')
 call unlinkTemp('out')
}
unpretoc 2

=head2 Oracle HTTP Server

Gathers Oracle HTTP server information.

=cut

echo tput('bold'),' Gathering Oracle HTTP Server Information ...',tput('off')
pretoc '%SPLIT%'
pretoc '1+:Oracle HTTP Server'

report ohs_bin
var $dir = catDir($APACHE_TOP,'bin')
prefix
 write '---+ List of Files in ',$dir
call statDir('an',$dir)
if isCreated(true)
{toc '2:Generic'
 toc '3:[[',getFile(),'][rda_report][',replace($dir,$OH2,'$OH'),']]'
}

debug '  Inside IASs11g module, getting Oracle HTTP Server related config and \
         log files'
var $job = getTemp('job','.py')
var $out = getTemp('out','.txt')
if $mas
{pretoc '2:Oracle Instance'
 set $cod
 {def extractHttpFiles(ins,lgt):
 " cd(ins)
 " tb_com = listTopologyAttributes()
 " for i in range(0, len(tb_com)):
 "  com = tb_com[i]
 "  for j in range(0, len(com)):
 "   if com[j] == 'Directory':
 "    dir = com[j+2]
 " tb_com = ls(long=1)
 " com = tb_com.get("ChildTopoNodes")
 " for i in range(0, len(com)):
 "  if com[i].get("TopoNodeType") == 'OHSComponent':
 "   ohs = com[i].get("TopoNodeName")
 "   cd(ohs)
 "   print "\n---# RDA:BEGIN SECTION:3:'" + ohs + "' Component\n"
 "   tb_doc = listDocNames()
 "   print '\n---# RDA:BEGIN SECTION:4:Configuration Files\n'
 "   for doc in tb_doc:
 "    if not re.search('(magic|jar|types|sso|txt|log)$',doc):
 "     det = getDocAttributes(doc)
 "     loc = det.get("instanceHomeLocation")
 "     if len(loc):
 "      loc = re.sub(dir,"$OI",str(loc),1)
 "     else:
 "      loc = doc
 "     print '\n---# RDA:BEGIN'
 "     getDoc(name=doc)
 "     print '---# RDA:END FILE:' + loc + '\n'
 "   print '\n---# RDA:END SECTION:5\n'
 "   print '\n---# RDA:BEGIN SECTION:4:Log Queries\n'
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(last=1, timeUnit="d", \
                 groupBy=['TN_PATH', 'COMPONENT_ID', 'MODULE_ID', 'MSG_TYPE'])
 "   print '---# RDA:END REPORT:5|Activities over last 24 Hours|odl_24h_' + \
           ins + '_' + ohs + '\n'
 "   tb_cid = displayLogs(last=1, timeUnit="d", groupBy="COMPONENT_ID", \
                          returnData=1)
 "   for cid in tb_cid.keys():
 "    try:
 "     qry = 'COMPONENT_ID eq ' + cid + \
             ' and MSG_TYPE eq ERROR or MSG_TYPE eq WARNING'
 "     print '\n---# RDA:BEGIN'
 "     displayLogs(tail=lgt, query=str(qry))
 "     print '---# RDA:END REPORT:5|Last Warnings and Errors for ' + cid + \
             '|odl_com_' + ins + '_' + ohs + '_' + cid + '\n'
 "    except:
 "     pass
 "   print '\n---# RDA:END SECTION\n'
 "   tb_log = listLogs()
 "   print '\n---# RDA:BEGIN SECTION:4:Log Files\n'
 "   for log in tb_log:
 "    tb_fil = log.get("logFiles")
 "    for fil in tb_fil:
 "     pth = fil.get("canonicalPath")
 "     print '\n---# RDA:BEGIN'
 "     displayLogs(log=pth, tail=lgt, disconnected=1)
 "     print '---# RDA:END FILE:' + re.sub(dir,"$OI",pth,1) + '\n'
 "   print '\n---# RDA:END SECTION:5\n'
 "   print '\n---# RDA:BEGIN'
 "   dumpMetrics()
 "   print '\n---# RDA:END REPORT:4|dumpMetrics|dump_metrics_' + \
           ins + '_' + ohs
 "   print '\n---# RDA:END SECTION\n'
 "   cd('..')
 " cd('..')
 "
 "extractHttpFiles(ins,TAIL)
 "
 }
 call writeTemp('job','import re')
 call writeTemp('job','connect(user="',$usr,'", walletLocation="',$wlt,\
                      '", masServer="',$url,'")')
 call writeTemp('job','ins="',$bas,'"')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out)
 unpretoc
}
else
{pretoc '2:Oracle Instance'
 loop $fil (grepDir(catDir($ORACLE_INSTANCE,'config','OHSComponent'),\
                    '^httpd(s)?\.conf$',\
                    'dir'))
 {call setSetting('HTTPD_CONF_LOCATION',$fil)
  call httpServer_getListenerConf(true)
 }
 pretoc '3:Listener Configuration'
 loop $fil (keys(%HTTPDCONF))
 {var $nam = replace($fil,$OI1)
  report concat('lc_',$nam)
  prefix
   write '---+ Content Taken from File ',$nam
  call writeFile($fil)
  var $txt = replace($fil,$OI,'$OI')
  if isCreated()
   toc '4:[[',getFile(),'][rda_report][',$txt,']]'
 }
 unpretoc
 set $cod
 {print '\n---# RDA:BEGIN SECTION:3:Log Files\n'
 "tb_log = listLogs(oracleinstance=dir, disconnected=1)
 "for log in tb_log:
 " tb_fil = log.get("logFiles")
 " for fil in tb_fil:
 "  pth = fil.get("canonicalPath")
 "  if re.search('OHSComponent',pth):
 "   print '\n---# RDA:BEGIN'
 "   displayLogs(oracleinstance=dir, log=pth, tail=TAIL, disconnected=1)
 "   print '---# RDA:END FILE:' + re.sub(dir,"$OI",pth,1) + '\n'
 "
 "print '\n---# RDA:END SECTION:4\n'
 "
 }
 call writeTemp('job','import re')
 call writeTemp('job','dir="',$ORACLE_INSTANCE,'"')
 call writeTemp('job','TAIL=',$TAIL)
 call writeTemp('job',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out)
 unpretoc
}
call unlinkTemp('job')
call unlinkTemp('out')

debug '  Inside IASs11g module, getting start scripts'
call httpServer_getStartScripts()
unpretoc 2

=head2 JAVACACHE

Gathers Java Object Cache information.

=cut

if testDir('d',$JAVACACHE_HOME)
{echo tput('bold'),' Gathering JAVACACHE Information ...',tput('off')
 pretoc '%SPLIT%'
 pretoc '1+:JAVACACHE'

 debug '  Inside IASs11g module, gathering JAVACACHE information'
 pretoc '2:Oracle Home'
 call sort_results(3,$TAIL,$OH,'$OH',\
                   grepDir($JAVACACHE_HOME,'\.log$','inr'),\
                   grepDir($JAVACACHE_HOME,'\.xml$','inr'))

=head2 javacache - Java Cache

Gathers Java Cache command information.

=cut

 var $fil = catFile($JAVACACHE_HOME,'lib','cache.jar')
 if testFile('f',$fil)
 {debug '  Inside IASs11g module, gathering JAVACACHE command information'
  var $tmp = createTemp('javacache')
  call writeTemp('javacache','lc')
  call writeTemp('javacache','lo')
  call closeTemp('javacache')
  var $cmd = concat(catCommand($ORACLE_HOME,'jdk','bin','java'),\
                    " -jar ",quote($fil,'x')," watch <",quote($tmp,'x'))
  report javacache
  prefix
  {write '---+!! Java Cache Command Execution'
   write '---## Using: cache.jar lc and lo commands'
  }
  call writeCommand($cmd)
  if isCreated(true)
  {write $TOP
   toc '3:[[',getFile(),'][rda_report][Java Cache]]'
  }
  call unlinkTemp('javacache')
 }
 unpretoc 3
}

=head2 LDAP

Gathers LDAP information.

=cut

if testDir('d',$LDAP_HOME)
{echo tput('bold'),' Gathering LDAP Information ...',tput('off')
 pretoc '%SPLIT%'
 pretoc '1+:LDAP'

 debug '  Inside IASs11g module, gathering LDAP information'
 var $dir = catDir($LDAP_HOME,'bin')
 if testDir('d',$dir)
 {pretoc '2:Oracle Home'
  report ldap_bin
  prefix
   write '---+ List of Files in ',$dir
  call statDir('an',$dir)
  if isCreated(true)
  {toc '3:Generic'
   toc '4:[[',getFile(),'][rda_report][',replace($dir,$OH2,'$OH'),']]'
  }
  unpretoc
 }
 unpretoc 2
}

=head2 SYSMAN

Gathers SYSMAN information.

=cut

echo tput('bold'),' Gathering SYSMAN Information ...',tput('off')
pretoc '%SPLIT%'
pretoc '1+:SYSMAN'

debug '  Inside IASs11g module, gathering SYSMAN information'
pretoc '2:Oracle Home'
call sort_results(3,$TAIL,$OH,'$OH',\
                  grepDir($SYSMAN_HOME,'\.(properties|xml)$','dir'))
unpretoc
pretoc '2:Oracle Instance'
if testDir('d',catDir($ORACLE_INSTANCE,'sysman'))
{var $dir = lastDir()
 call sort_results(3,$TAIL,$OI,'$OI',\
                   grepDir($dir,'\.(xml|log)$','dir'),\
                   grepDir(catDir($dir,'log'),'^[^\.]','pn'))
}
call unlinkTemp('wallet')
unpretoc 3

=head1 SEE ALSO

See also L<IAS.def|modules::IAS>.

=begin credits

=over 10

=item RDA 4.9:  Greg Cook, Albert Girona.

=item RDA 4.10:  Greg Cook, Albert Girona, Daniel Mortimer.

=item RDA 4.11:  Greg Cook, Andrew Salt.

=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
