# IASm11g.def: Collects Oracle Application Server 11g Information (All Instances)
# $Id: IASm11g.def,v 1.18 2008/02/08 14:55:19 mschenke Exp $
# ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/IASm11g.def,v 1.18 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

IASm11g - Collects Oracle Application Server 11g Information (All Instances)

=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 multiple Oracle instances.

=head1 REPORTS

=cut

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

# Initialization
import $APACHE_TOP,$ORACLE_HOME
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 $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.
"
}

# Define the internal counter, table of content array, and duplicate file hash
var ($CNT,@TOC,%DUP) = (0)

# Define the file sorting macro
macro sort_results
{var ($ins,$lvl,$lgt,$pre,$pat,@fil) = @arg
 import $CNT,$TOP,@TOC,%DUP
 keep $CNT,$TOP,@TOC,%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
   if $ins
    var @TOC = (@TOC,concat($ins,'::',$lvl,':',replace($grp,$pre,$pat),' '))
   else
   toc $lvl,':',replace($grp,$pre,$pat),' '
  }

  # 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()
  {if $ins
    var @TOC = (@TOC,concat($ins,'::',\
                            $det,':[[',$rpt,'][rda_report][',$nam,']]'))
   else
    toc $det,':[[',$rpt,'][rda_report][',$nam,']]'
  }
 }
}

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

 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 INSTANCE')
    var $ins = $dat
   elsif compare('eq',$cmd,'BEGIN SECTION')
   {incr $lvl
    call clearData()
    if $flg
     pretoc $dat
    else
     var @TOC = (@TOC,join(':','',$lvl,$dat))
   }
   elsif compare('eq',$cmd,'BEGIN TITLE')
   {var $lvl = 0
    if $flg
     toc $dat
    else
     var @TOC = (@TOC,join(':','','',$dat))
   }
   elsif compare('eq',$cmd,'END FILE')
   {if !length($dat)
     var $dat = '?'  
    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
     if $flg
      toc $det,':[[',getFile(),'][rda_report][',$lnk,']]'
     else
      var @TOC = (@TOC,concat($ins,'::',\
                              $det,':[[',getFile(),'][rda_report][',$lnk,']]'))
    }
   }
   elsif compare('eq',$cmd,'END SECTION')
   {if $dat
     call sort_results($ins,$dat,0,$out,undef,getDataKeys())
    call clearData()
    if $lvl
    {if $flg
      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 (All Instances)'

# Validate the user inputs
var $mas = false
var $shl = concat(catCommand($ORACLE_HOME,'bin','asctl')," script ")
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')

# Check the user
var $uid   = getOwner(getToc(true))
var ($pgm) = grepDir(catDir($ORACLE_HOME,'bin'),'^asctl(\.(exe|bat))?$','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/Topology

Collects the group and instances information, the configuration, and the 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

if $mas
{debug '  Inside IASm11g module, gathering MAS related config and log files'
 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,true)
 call unlinkTemp('job')
 call unlinkTemp('out')

=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 IASm11g module, gathering MAS group information'
 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,true)
 call unlinkTemp('job')
 call unlinkTemp('out')

=head3 Instances

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

=cut

 debug '  Inside IASm11g module, gathering MAS instances information'
 var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 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 '---# RDA:END REPORT:4|Diagnostic Incidents|list_incidents_' + ins
 " 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:Instances\n'
 "tb_top = ls(long=1)
 "top = tb_top.get("ChildTopoNodes")
 "for i in range(0, len(top)):
 " if top[i].get("TopoNodeType") == 'ASInstance':
 "  extractMasIns(top[i].get("TopoNodeName"),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',$cod)
 call writeTemp('job','exit()')
 call closeTemp('job')
 call command(concat($shl,quote($job,'x')," >",quote($out,'x')))
 call write_report($out,true)
 call unlinkTemp('job')
 call unlinkTemp('out')
}

=head3 dumpMetrics

Collects dumpMetrics, providing a starting point for analyzing performance
issues.

=cut

echo tput('bold'),' Gathering dumpMetrics Information ...',tput('off')
if $NOT_OWNER
{report dump_metrics
 write '---+ dumpMetrics'
 write $NOT_OWNER_STATEMENT
 toc '2:[[',getFile(),'][rda_report][dumpMetrics]]'
}
elsif $mas
{debug '  Inside IASm11g module, gathering dumpMetrics'
 var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {print '\n---# RDA:BEGIN'
 "dumpMetrics()
 "print '\n---# RDA:END REPORT:2|dumpMetrics|dump_metrics'
 }
 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,true)
 call unlinkTemp('job')
 call unlinkTemp('out')
}
unpretoc 2

=head2 Install and Configuration

Gathers the Oracle Application Server configuration and installation files.

=cut

debug '  Inside IASm11g module, gathering install and config information'
pretoc '%SPLIT%'
pretoc '1+:Oracle Home'
pretoc '2:Install and Configuration'
call sort_results('',3,$TAIL,$OH,'$OH',\
                  grepDir($IAS_INSTALL,'\.(ini|log)','dir'))
unpretoc

=head2 MAS Agent

Gathers MAS agent configuration and log files.

=cut

echo tput('bold'),' Gathering MAS Agent Information ...',tput('off')
if $mas
{debug '  Inside IASm11g module, gathering MAS agent related config and \
          log files'
 var @TOC = (@TOC,':1:1++:MAS Agent')
 var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {def extractAgentFiles(ins,lgt):
 " cd(ins)
 " print '\n---# RDA:BEGIN INSTANCE:' + ins + '\n'
 " 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:2: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:3\n'
 "   print '\n---# RDA:BEGIN SECTION:2: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:3|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:3|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:2: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:3\n'
 "   print '\n---# RDA:BEGIN'
 "   dumpMetrics()
 "   print '\n---# RDA:END REPORT:2|dumpMetrics|dump_metrics_' + \
           ins + '_' + agt
 "   cd('..')
 " cd('..')
 "
 "tb_top = ls(long=1)
 "top = tb_top.get("ChildTopoNodes")
 "for i in range(0, len(top)):
 " if top[i].get("TopoNodeType") == 'ASInstance':
 "  extractAgentFiles(top[i].get("TopoNodeName"),TAIL)
 "
 }
 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,false,'',1)
 call unlinkTemp('job')
 call unlinkTemp('out')
}

=head2 Oracle HTTP Server

Gathers Oracle HTTP server information.

=cut

echo tput('bold'),' Gathering Oracle HTTP Server Information ...',tput('off')

debug '  Inside IASm11g module, listing Oracle HTTP Server executables'
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'),']]'
}

if $mas
{debug '  Inside IASm11g module, getting Oracle HTTP Server config and log \
          files'
 var @TOC = (@TOC,':1:1++:Oracle HTTP Server')
 var $job = getTemp('job','.py')
 var $out = getTemp('out','.txt')
 set $cod
 {def extractHttpFiles(ins,lgt):
 " cd(ins)
 " print '\n---# RDA:BEGIN INSTANCE:' + ins + '\n'
 " 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:2:'" + ohs + "' Component\n"
 "   tb_doc = listDocNames()
 "   print '\n---# RDA:BEGIN SECTION:3: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: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 + '_' + 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:4|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: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 + '_' + ohs
 "   print '\n---# RDA:END SECTION\n'
 "   cd('..')
 " cd('..')
 "
 "tb_top = ls(long=1)
 "top = tb_top.get("ChildTopoNodes")
 "for i in range(0, len(top)):
 " if top[i].get("TopoNodeType") == 'ASInstance':
 "  extractHttpFiles(top[i].get("TopoNodeName"),TAIL)
 "
 }
 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,false,'',1)
 call unlinkTemp('job')
 call unlinkTemp('out')
}
unpretoc

=head2 JAVACACHE

Gathers Java Object Cache information.

=cut

if testDir('d',$JAVACACHE_HOME)
{echo tput('bold'),' Gathering JAVACACHE Information ...',tput('off')
 pretoc '1++:JAVACACHE'
 debug '  Inside IASm11g module, gathering JAVACACHE information'
 call sort_results('',2,$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 IASm11g 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 '2:[[',getFile(),'][rda_report][Java Cache]]'
  }
  call unlinkTemp('javacache')
 }
 unpretoc
}

=head2 LDAP

Gathers LDAP information.

=cut

if testDir('d',$LDAP_HOME)
{echo tput('bold'),' Gathering LDAP Information ...',tput('off')
 pretoc '1++:LDAP'
 debug '  Inside IASm11g module, gathering LDAP information'
 var $dir = catDir($LDAP_HOME,'bin')
 if testDir('d',$dir)
 {report ldap_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'),']]'
  }
 }
 unpretoc
}

=head2 SYSMAN

Gathers SYSMAN information.

=cut

echo tput('bold'),' Gathering SYSMAN Information ...',tput('off')
pretoc '1++:SYSMAN'
debug '  Inside IASm11g module, gathering SYSMAN information'
call sort_results('',2,$TAIL,$OH,'$OH',\
                  grepDir($SYSMAN_HOME,'\.(properties|xml)$','dir'))
unpretoc

# Complete the table of content
call unlinkTemp('wallet')
unpretoc 2
if @TOC
{# Get the instance list
 loop $lin (@TOC)
 {if field(':',0,$lin)
   var $ins{last} = 1
 }

 # Generate the instance contributions
 loop $ref (keys(%ins))
 {# Add the instance contribution
  var $toc = 1
  toc "%SPLIT%"
  toc "1+:'",$ref,"' Instance"
  loop $lin (@TOC)
  {var ($ins,$lvl,$txt) = split(':',$lin,3)
   if compare('eq',$ins,$ref)
    toc $txt
   elsif !length($ins)
   {if $lvl
    {while expr('>',$toc,$lvl)
     {unpretoc
      decr $toc
     }
     if length($txt)
     {while expr('>=',$lvl,$toc)
      {pretoc $txt
       incr $toc
      }
     }
    }
    else
     toc $txt
   }
  }

  # Close any pending level
  for $cur ($toc,0,-1)
  {unpretoc
   decr $toc
  }
 }
}

=begin credits

=over 10

=item RDA 4.9:  Greg Cook, Albert Girona.

=item RDA 4.10:  Greg Cook, Albert Girona.

=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
