Check Composite State of Oracle SOA Suite by Command Line
Posted by Dirk Nachbar on Thursday, July 27, 2017
I was currently fighting a bit with the monitoring of Oracle SOA Suite 12c Composites.
The goal was to check the state of deployed Composites on an Oracle SOA Suite 12c with following requirements/dependencies:
Property File domain.properties
Python Script check_composite_state.py
Wrapper Shell Script check_composite_state.sh
In line 13 of the Script, align the Variable OracleHome to your Oracle Home Location
In line 66 of the Script, align the directory location were to find the check_composite_state.py Python Script
Under the directory logs you will find an outfile with naming convention CompositeName.log with the Status of your Composite
Happy Composite State Checking ... :-)
The goal was to check the state of deployed Composites on an Oracle SOA Suite 12c with following requirements/dependencies:
- No Oracle Cloud Control
- Capture only Active Composites and not Retired Composites
- one main Pythin Script, called check_composite_state.py which is checking the State of a non retired given Composite Name for a given Partition|Folder and a given Managed Server
- one property file called domain.properties which will be used by the Python Script in order to build the required connect string to the Admin Server of the SOA Suite
- one wrapper Shell Script, which takes the required 3 Arguments (Name of Managed Server, Composite Name and Partition|Folder Name)
Property File domain.properties
# Replace the below given values with your settings admin.url=wlssoa1:7001 admin.userName=weblogic admin.password=Oracle12c
Python Script check_composite_state.py
# ============================================================
#
# Script: check_composite_state.py
#
# Author: Dirk Nachbar, http://dirknachbar.blogpost.com
#
# Purpose: Checks the state of a given Composite
#          for Oracle SOA Suite 12c
#
# ============================================================
import sys;
from java.util import Date
from java.text import SimpleDateFormat
from java.io import File
from java.io import FileOutputStream
from java.io import FileInputStream
# Load the WLS Connection Credential and establish the connection
propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)
adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")
managedServer=sys.argv[1]
compositeName=sys.argv[2]
partitionName=sys.argv[3]
# Initialization of Logfile
f = File('logs/' + compositeName + '.log')
fos = FileOutputStream(f)
theInterpreter.setOut(fos)
# Perform the Connect to the AdminServer of the SOA Suite
connect(adminUserName,adminPassword,adminURL)
domainRuntime()
for n in mbs.queryNames(ObjectName('oracle.soa.config:Location=' + managedServer + ',partition=' + partitionName + ',j2eeType=SCAComposite,name="' + compositeName + '",*'), None):
    RetiredFlag = mbs.getAttribute(n,'Mode')
    if RetiredFlag != 'retired':
        print 'Name: ' + mbs.getAttribute(n, 'Name')
        print 'Mode: ' + mbs.getAttribute(n,'Mode')
        print 'State: ' + mbs.getAttribute(n,'State')
Wrapper Shell Script check_composite_state.sh
In line 13 of the Script, align the Variable OracleHome to your Oracle Home Location
In line 66 of the Script, align the directory location were to find the check_composite_state.py Python Script
#!/bin/bash
# ============================================================
#
# Script: check_composite_state.sh
#
# Author: Dirk Nachbar, http://dirknachbar.blogspot.com
#
# Purpose: Wrapper Script to check the state of a given Composite
#          for Oracle SOA Suite 12c
#
# ============================================================
OracleHome=/data/oracle/product/fmw-soa-12.2.1.2.0
#---------------------------------------------------------------------
Usage()
#
# PURPOSE: Displays the Usage of the script
#---------------------------------------------------------------------
{
cat << EOF
Usage: check_composite_state.sh -s <ManagedServer> -c <CompositeName> -p <Partition|Folder>
       Monitoring script for SOA Suite Composite
Parameters:
   -s: Name of the Managed SOA Server
   -c: Name of Composite to be checked
   -p: Name of Parition | Folder
e.g. check_composite_state.sh -s soa_server1 -c PayPal -p default
EOF
exit 1
}
#---------------------------------------------------------------------
CheckParams()
#
# PURPOSE: Checks the input Parmeter
#---------------------------------------------------------------------
{
    if [ "${ManagedServer}" = "" ] ; then
        echo "ERR: Missing parameter(s), the flags -s must be used."
        Usage
    fi
    if [ "${CompositeName}" = "" ] ; then
        echo "ERR: Missing parameter(s), the flags -c must be used."
        Usage
    fi
    if [ "${Partition}" = "" ] ; then
        echo "ERR: Missing parameter(s), the flags -p must be used."
        Usage
    fi
}
#---------------------------------------------------------------------
CallCheckCompositeState()
#
# PURPOSE: Calls the check_composite_state.py Script
#---------------------------------------------------------------------
{
${OracleHome}/oracle_common/common/bin/wlst.sh /home/oracle/check_composite_state.py ${ManagedServer} ${CompositeName} ${Partition}
}
#---------------------------------------------------------------------
# MAIN
#---------------------------------------------------------------------
ManagedServer=''
CompositeName=''
Partition=''
while getopts s:c:p:h: CurOpt; do
    case ${CurOpt} in
        s) ManagedServer="${OPTARG}" ;;
        c) CompositeName="${OPTARG}" ;;
        p) Partition="${OPTARG}"     ;;
        h) Usage           exit 1    ;;
        ?) Usage           exit 1    ;;
    esac
done
shift $((${OPTIND}-1))
if [ $# -ne 0 ]; then
    Usage
fi
# Check Input Parameters
CheckParams
# Start the Check State of Composite
CallCheckCompositeState
Create the 3 above provided files in one location, align the said Variables and/or directory location and create a subdirectory called "logs" in the directory. Than call the Wrapper Shell Script with following options:# # ./check_composite_state.sh -s <Name of Managed Server> -c <Composite Name> -p <Partition|Folder> # for example: ./check_composite_state.sh -s soa_server1 -c PayPal -p default
Under the directory logs you will find an outfile with naming convention CompositeName.log with the Status of your Composite
cd logs
cat PayPal.log
Connecting to t3://wlssoa1:7001 with userid weblogic ...
Successfully connected to Admin Server "DEVAdminServer" that belongs to domain "dev_domain".
Warning: An insecure protocol was used to connect to the server.
To ensure on-the-wire security, the SSL port or Admin port should be used instead.
Location changed to domainRuntime tree. This is a read-only tree
with DomainMBean as the root MBean.
For more help, use help('domainRuntime')
Name: PayPal [1.0]
Mode: active
State: on
Happy Composite State Checking ... :-)
Categories: Oracle WebLogic Server 12c, SOA 12c
 
 
