Script to check Datasource connections -Weblogic WLST scripting


Script to check DataSource Connections using WLST scripting:

The connection status can be checked using Python script.
Ensure the indents are correct.
Url of datasource , port number can be found out at config.xml file

Export the following:
export ANT_HOME=/app/oracle/Middleware/mw6/modules/org.apache.ant_1.7.1
export CLASSPATH=$ANT_HOME/lib:$ANT_HOME/bin
export CLASSPATH=$ANT_CONTRIB/lib:$CLASSPATH
export ANT_CONTRIB=$MW_HOME/modules/net.sf.contrib_1.1.0.0_1-0b2
export CLASSPATH=$ANT_CONTRIB/lib:$CLASSPATH
. /app/oracle/Middleware/mw6/wlserver_10.3/server/bin/setWLSEnv.sh

Save the below as *.PY

connect('weblogic','<weblogicpassowrd>', 't3://<url of datasource>')
serverRuntime()
dsMBeans = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
dsName="<datasource name>"
for ds in dsMBeans:
        if (dsName == ds.getName()):
                  print 'DS name is: '+ds.getName()
                  print 'State is ' +ds.getState()
                  print '-----------Connection Details-----------'
          activeConnectionsCurrentCount=ds.getActiveConnectionsCurrentCount()
          print 'ActiveConnectionsCurrentCount:', activeConnectionsCurrentCount
          numberAvailable=ds.getNumAvailable;
          print 'NumberofConnectionsAvailable :', numberAvailable
          print '----------------------------------------'


TO Run the above Python script:
java weblogic.WLST  <Location of above script>/<name>.py

Fully automate the above script based on available connection:
Save the below as *.sh
Below cnt variable is saved from the checks exported from txt file.


export ANT_HOME=/app/oracle/Middleware/mw6/modules/org.apache.ant_1.7.1
export CLASSPATH=$ANT_HOME/lib:$ANT_HOME/bin
export CLASSPATH=$ANT_CONTRIB/lib:$CLASSPATH
export ANT_CONTRIB=$MW_HOME/modules/net.sf.contrib_1.1.0.0_1-0b2
export CLASSPATH=$ANT_CONTRIB/lib:$CLASSPATH
. /app/oracle/Middleware/mw6/wlserver_10.3/server/bin/setWLSEnv.sh
rm <file loc>/DS_Check.txt
java weblogic.WLST  <Location of above script>/<name>.py >> DS_Check.txt
cnt=$(grep -o 'Available.$*' DS_Check.txt|cut -c13-) 
if [$cnt != 0]; then
--Do Something--
else
exit
fi
                   


Comments

Popular posts from this blog

Troubleshoot OEM 12c Cloud Control Agent and Target

Troubleshoot OEM 12c Cloud Control Metric Alerts