# PWdom.ctl: Defines Common Macros for Oracle WebLogic Server Connection # $Id: PWdom.ctl,v 1.1 2014/11/20 12:35:25 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/OFM/PWdom.ctl,v 1.1 2014/11/20 12:35:25 RDA Exp $ # # Change History # 20141119 KRA Initial version. =head1 NAME OFM:PWdom - Defines Common Macros for Oracle WebLogic Server Connection =head1 DESCRIPTION This persistent submodule regroups macros for checking the connection to domain targets. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('findDomains','testDomain') =head2 S This macro finds the Oracle WebLogic domains for testing Admin Server connection. =cut macro findDomains {var ($itm) = @arg var @req = () loop $req ($itm->grep('^I_DOMAIN$','rw')) {if match($req->get_first('T_DOM_FOCUS'),'\bWlstOn\b') call push(@req,$req) } return @req } =head2 S This macro tests the Oracle WebLogic Admin Server connection. Unless the flag is set, it performs the test once. =cut macro testDomain {var ($req,$tgt,$flg) = @arg import %LOGIN,%URL keep %LOGIN,%URL # Set the current target var $prv = setCurrent($cur = addTarget($tgt)) var ($ADMIN,$OVERRIDE_PORT,$hst,$prt,$ssl) = ('',0,'',undef,0) # Get the domain details var $dom = nvl(getDomain('nam'),'') var $dhp = catDir(getDomain('.')) # Get the host and port if ?testFile('fr',catFile($dhp,'config','config.xml')) {var $obj = xmlLoadFile(lastFile(),xmlDisable(xmlParser(),'BCDEPR')) if compare('EQ',$dom,xmlData(xmlFind($obj,'domain/name'))) {var $ADMIN = xmlData(xmlFind($obj,'domain/admin-server-name')) if match(xmlData(xmlFind($obj,\ 'domain/administration-port-enabled')),'true',true) {if xmlFind($obj,concat('domain/server|name *="^',verbatim($ADMIN),'$"')) {if xmlFind(last,'administration-port') var $OVERRIDE_PORT = xmlData(last) } if !$OVERRIDE_PORT var $OVERRIDE_PORT = xmlData(xmlFind($obj,'domain/administration-port')) } loop $xml (xmlFind($obj,'domain/server')) {if compare('eq',xmlData(xmlFind($xml,'name')),$ADMIN) {var $hst = xmlData(xmlFind($xml,'listen-address')) if !??$hst var $hst = 'localhost' var $prt = cond(\ $OVERRIDE_PORT,$OVERRIDE_PORT,xmlData(xmlFind($xml,'listen-port'))) if xmlFind($xml,'ssl') {var ($nod) = last if match(xmlData(xmlFind($nod,'enabled')),'true',true) {if $OVERRIDE_PORT var $ssl = $OVERRIDE_PORT elsif !??$ssl = xmlData(xmlFind($nod,'listen-port')) var $ssl = 7002 } } break } } } } # Still host and port not found while hasDomainAttr() {# Validate the configuration settings if !??$hst {var $hst = getDomainAttr('SERVER_HOST') if !??$hst {call setCurrent($prv) return "Missing host for a Oracle WebLogic Server connection under \ '${VAR.dom}' domain" } } if !match($hst,'^[\w\-\.]+$') {call setCurrent($prv) return "Invalid Oracle WebLogic Server host under '${VAR.dom}' domain" } if !match($prt,'^\d+$') {var $prt = getDomainAttr('SERVER_PORT') if !match($prt,'^\d+$') var $prt = 7001 } var $URL{$dhp} = [concat($hst,':',$prt)] if $ssl var $URL{$dhp} = [concat('t3s://',$hst,':',$ssl),@{$URL{$dhp}}] break } # Load known users and passwords var (@pwd,@usr,%pwd) = () if ??$usr = ${CUR.O_SETUP}->search(\ concat('WREQ_',substr($req->get_oid,5)))->get_first('T_USER') {if hasPassword('wls',$dom,$usr) {var $pwd{$usr} = true call push(@pwd,$usr) } else call push(@usr,$usr) } # Check for the "best" candidate var $dft = getDomainAttr('DOMAIN_USER') if exists($pwd{$dft}) var $LOGIN{$dhp} = $dft elsif @pwd var $LOGIN{$dhp} = $pwd[0] elsif @usr {call setPassword('wls',$dom,$usr[0],askPassword(\ concat("Enter '",$usr[0],"' user password for '",$dom,"' domain:"))) var $LOGIN{$dhp} = $usr[0] } elsif match($dft,'^\w+$') {call setPassword('wls',$dom,$dft,askPassword(\ concat("Enter '",$dft,"' user password for '",$dom,"' domain:"))) var $LOGIN{$dhp} = $dft } # Determine WLST if $cur->get_wlst(true) {var $WLST_DIR = catDir(last,'common') call setWasType('WLS',catCommand($WLST_DIR,'bin',${AS.CMD:'wlst'})) } else call setWasType('WLS') # Check the connection to the WLS var ($wls,$msg) = (false) if $URL{$dhp} {loop $url (@{last}) {call sharePassword('wls',$dom,'wls',$url) if setWasLogin($LOGIN{$dhp},undef,$url) {call setCurrent($prv) return 'Missing access to WLST' } var $out = newTemp('out') var $err = newTemp('err') call requestWas(undef,undef,$out,$err) if grepFile($out,'Successfully connected ','f') var $wls = true else {var $msg = "Error encountered when connecting to the Admin Server of \ '${VAR.dom}' domain using: ${VAR.url}" call loadFile($out) if grepLastFile('AuthenticationException ','f') var $msg = concat($msg,' - Invalid username/password') elsif grepLastFile('CommunicationException ','f') var $msg = concat($msg,' - Destination unreachable') } call unlinkTemp('out') call unlinkTemp('err') break $wls } } else {call setCurrent($prv) return 'No connection URLs identified' } call setCurrent($prv) if !$wls return $msg return '' } =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