# WLSlib.ctl: Defines Common Macros for Oracle WebLogic Server # $Id: WLSlib.ctl,v 1.13 2015/10/28 16:47:23 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/OFM/WLSlib.ctl,v 1.13 2015/10/28 16:47:23 RDA Exp $ # # Change History # 20151028 KRA Add filtering capabilities in get_config. =head1 NAME OFM:WLSlib - Defines Common Macros for Oracle WebLogic Server =head1 DESCRIPTION This persistent submodule regroups macros that are common to several Oracle WebLogic Server related-modules. The following macros are available: =cut use Buffer # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('dsp_manifest','get_config','MBean',\ 'write_list','write_tables') =head2 S This macro looks in the specified directory tree for all C<*.ear>, C<*.jar>, and C<*.war> files that contain the C word in the path and extracts the MANIFEST information from them. It requires the availability of F command. =head2 S This macro extracts the MANIFEST information from a fixed set of files passed as an array reference. =cut macro dsp_manifest {define ($lvl,$arg,$shr) = @arg import $TOP keep $TOP # Check for unzip availability var $cmd = findCommand('unzip') if !length($cmd) return # Filter the file list if ref($arg) {loop $fil (@{$arg}) var $fil{dirname($fil),basename($fil)} = $fil } else {var $pat = '(apache|com\.bea\.cie\.|com\.bea\.core\.apache\.|\ com\.oracle\.cie\.|help|javax\.|\bjdk|org\.apache\.ant)' loop $sub (findDir($arg,'^(\.+|help|jdk)$','vn')) {loop $fil (grepDir(catDir($arg,$sub),'\.([ejw]ar)$','ir')) {next !match($fil,'\bmodules\b') next match($fil,$pat,true) var $fil{dirname($fil),basename($fil)} = $fil } } } # Generate the reports and related index links loop $grp (keys(%fil)) {# Start a new directory debug ' Inside dsp_manifest, searching ',$grp output F,manifest_info title '---+!! Manifest Information from ',encode($grp),' Directory' title '%TOC3-2%' # Gather the manifest information associated with the files loop $nam (keys($fil{$grp})) {var $fil = $fil{$grp,$nam} prefix {write '---++ ',encode($nam) call statFile('b',$fil) } call writeCommand(concat($cmd,' -p ',quote($fil),\ ' META-INF/MANIFEST.MF 2>/dev/null')) if hasOutput(true) write $TOP } # Add relevant report to the table of content if isCreated(true) {toc $lvl,':[[',getFile(),'][rda_report][',\ $txt = concat('From ',encode(addSymbol($grp))),']]' if $shr share $shr,$txt } } } =head2 S This macro returns the configuration files. It skips top entries matching the pattern specified. Unless the flag is set, it captures the C<.property> and C<.xml> files only. =cut macro get_config {define (\@tbl,$dir,$pat,$flg,$flt) = @arg import %FLT # Determine filtering action if !?$flt var $flt = {} var $act = $flt->{$dir} # Analyze the directory loop $fil (grepDir($dir,'^\.+$','vn')) {next match($fil,$pat,true) var $pth = catFile($dir,$fil) if ?testDir('d',$pth) call push(@sub,$pth) elsif $flg {call push(@tbl,$pth) if ?$act var $FLT{$pth} = $act } elsif match($pth,'\.(properties|xml)$',true) {call push(@tbl,$pth) if ?$act var $FLT{$pth} = $act } } # Treat the subdirectories loop $sub (@sub) call get_config(\@tbl,$sub,'^servers$',$flg,$flt) } =head2 S This macro returns the WLST output in a table format. =cut macro MBean {define ($buf,$dat) = @arg import $TOC,$TOP var ($det,$lnk,$ttl,$loc,$rep,$com) = split('\|',$dat,6) var ($nxt,$sct,$skp,$str) = (false,false,false) report nvl(replace($rep,'[\/\\]','r',true),$lnk) prefix {write '---+!! ',$ttl if $loc write '---## Location: ',encode($loc) write $TOC } debug ' - Inside MBean, treating ',$lnk while ?$buf->get_line {var ($prv,$str) = ($str,last) if match($str,'^\-+$') {if $nxt {write ' |' var $nxt = false } if $skp var $skp = false elsif $sct {write $TOP var $sct = false } } elsif match($str,'^d[rwx\-]+\s+') {if !isCreated() write '---++ Overview' if !$sct {write '---+++ Child Beans' write '|*Property*|*Name*|' } write '|',replace(replace($str,'\*','*',true),'\s+',' |',true),' |' var $sct = true } elsif match($str,'^\-[rw\-]{2}x',true) {if !isCreated() write '---++ Overview' if !$sct {write '---+++ Operations' write '|*Property*|*Name*|*Value*|' } var ($mod,$tmp) = split('\s{3,}',$str,2) var ($nam,$val) = split('\s+',$tmp,2) write '|',$mod,' |',$nam,' |',replace(replace($val,'\*','*',true),\ '\|','|',true),' |' var $sct = true } elsif match($str,'^\-') {if !isCreated() write '---++ Overview' if !$sct {write '---+++ Attributes' write '|*Property*|*Name*|*Value*|' } var ($mod,$tmp) = split('\s{3,}',$str,2) var ($nam,$val) = split('\s+',$tmp,2) if match($val,'^(WebLogic Server Temporary Patch|\)') {write '|',$mod,' |',$nam,' |',replace(replace($val,'\*','*',true),\ '\|','|',true),'\' var $nxt = true } else write '|',$mod,' |',$nam,' |',replace(replace($val,'\*','*',true),\ '\|','|',true),' |' var $sct = true } elsif match($str,'^Attribute Names and Values$') {write '---++ ',$str write '|*Name*|*Value*|' var ($sct,$skp) = (true,true) } elsif match($str,'^Operations on this MBean$') {write '---++ ',$str write '|*Operation*|' var ($sct,$skp) = (true,true) } elsif match($str,'^(ThreadStackDump|\ WeblogicVersion\s+WebLogic Server Temporary Patch)') {write '|',\ replace(replace($str,'\*','*',true),'\s{3,}',' |',true),'\' var $nxt = true } elsif $nxt {if match($str,'^(OSVersion|Parent|TotalHeap)') {write ' |' write '|',replace(replace(\ $str,'\*','*',true),'\s{3,}',' |',true),' |' var $nxt = false } elsif match($str,'^(WebLogic Server\s+\d|\<\/statistics\>)') {write '%BR%',$str,' |' var $nxt = false } else write '%BR%',$str,'\' } elsif $com {if match($str,'^Domain Properties$') {write '---++ ',$str write '|*Property*|*Value*|' var $sct = true } elsif match($str,'^\w+$') {write '---++ ',$str var $dft = '|*Property*|*Value*|' var $sct = true } elsif match($str,'^.*?\s+\|.*?\s+\|.*?\s*$') {var $hdr = '|*Name*|*Status*| *Priority*|' write $hdr } elsif match($str,'^\s*$') {if isCreated() write $TOP var $sct = false } elsif $hdr {var ($nam,$sta,$pri) = split('\s{1,}',replace($str,'\*','*',true),3) write '|',$nam,' |',$sta,' | ',$pri,'|' } else {if $dft {write $dft var $dft = undef } var ($prp,$val) = split('\s{1,}',replace($str,'\*','*',true),2) write '|',$prp,' |',$val,' |' } } elsif match($str,'^\s*$') {if and($sct,not(match($prv,'^\-+$'))) {write $TOP var $sct = false } } else write '|',\ replace(replace($str,'\*','*',true),'\s{3,}',' |',true),' |' } if $sct write $TOP if isCreated(true) toc $det,':[[',getFile(),'][rda_report][',$lnk,']]' } =head2 S This macro returns the WLST output in a list format. =cut macro write_list {define ($buf,$dat) = @arg var ($det,$lnk,$ttl,$loc,$rpt) = split('\|',$dat,5) output F,$rpt prefix {write '---+ ',$ttl write '---## ',$loc write ' * Links point to files that have been collected in their \ original format. Opening them directly in your browser \ can present risks. To prevent them, access the file \ outside the browser or use the link to save them and use \ an adequate viewer.' write '|*File Name*|' } while ?$lin = $buf->get_line write '|',$lin,'|' if isCreated(true) toc $det,':[[',getFile(),'][rda_report][',$lnk,']]' } =head2 S This macro returns the WLST output in a raw table format. =cut macro write_tables {define ($buf,$dat) = @arg var ($det,$lnk,$rep) = split('\|',$dat,3) report nvl(replace($rep,'[\/\\]','r',true),$lnk) debug ' - Inside write_tables, treating ',$lnk while ?$lin = $buf->get_line {if match($lin,'^(\||-{3}\+|\%TOC\%|\[{2}\#Top)') write $lin } if isCreated(true) toc $det,':[[',getFile(),'][rda_report][',$lnk,']]' } =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut