Showing posts with label cut. Show all posts
Showing posts with label cut. Show all posts

Sunday, December 21, 2014

JMS MessageBridgeRuntime monitoring

We were in the developing a orchestration application platform which requires multiple JMS Messaging bridges. We have configured near 10 Bridges to different external systems. When maanaged servers each one host a bridge it will be doubles the count that we cannot monitor on single screen in the  admin console. On the Weblogic Admin Console we can monitor the Bridge status using Bridges -> Monitoring tab.For testing we had started single managed server and checked the Bridge monitoring status.

 It could be either 'Forwarding Messages' or 'Fail to connect Source' or 'Fail to connect to Target'. The actual tragedy starts when it comes to production environment, where we have multiple managedservers in the cluster. Usually Bridges status matters when it connects to third party messaging providers such as MQ Series or something else. Assume that, there are 10 Bridges deployed to 10 managed servers on the WebLogic Console becomes very slow when you use 'Monitoring' tab to show 100 result rows from the JMX. Alternative is we must develop a Python script or something else. Searched in search engines but no luck, OTN forums have same discussions but using python there is no output or MessagingBridgeRuntime is not there on the MBean tree. This is due to bug in WebLogic 9.2 ver to WebLogic 10.3.6. It is fixed in WebLogic 12c. So previous version need to update the patch. Alternative to patch you can use weblogic.Admin utility. The following scripting trick works well to show below output.

Fetching RUNNING managed server list

The weblogic.Admin command can give you the CLUSTERSTATE which will give the all the managed servers status(such as RUNNING, SHUTDOWN, UNKNOWN, ADMIN, FAILED etc.,) in that cluster. To give more robustness to the script, extract the that running list of managed servers. So that we can get all live server bridges status. using our 'awk' seizer we can pick the managed server names which 'grep' RUNNING state.

managdserver=`java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd  CLUSTERSTATE | grep managed |grep RUNN|awk -F'-' '{print $1}'`
Now the script

#!/bin/ksh
#================================================
# This is MessageBridge Monitoring script
# Updated by: Pavan Devarakonda
#================================================
admpasswd=Secret
admURL= hostname.company.com
domain=mydomain

echo "Starting at:"
date # For trace the time spending for this monitoring script
managdservers=`java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd  CLUSTERSTATE | grep managed |grep RUNN|awk -F'-' '{print $1}'`

for mserver in managdservers
do
 echo "Managed Server :" $mserver
 for bridge in `grep MessagingBridge mydomain.properties| cut -d'=' -f2`
 do
  echo " "
  java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd GET -pretty -type MessagingBridgeRuntime -mbean $domain:ServerRuntime=$mserver,Name=$bridge,Type=MessagingBridgeRuntime,Location=$mserver -property Description -property Name -property State | grep -v MBeanName
  
 done
done
echo "Bridge Status completed "
date
You must create a properties from your domain as follows:
mydomain.properties
#===================
srvr_target1=ms1_mydomain
srvr_target2=ms2_mydomain
srvr_target3=ms3_mydomain

bridge1=MQMessagingBridge1
bridge2=JMSMessagingBridge2

How to execute this script?

To execute this script you must have weblogic.jar in the CLASSPATH and java must be in the PATH that is JAVA_HOME/bin must be appended in your PATH environment variable. To execute the above Kron shell script
$ ./bridgeMonitor.ksh

To know more on Bridges and how to configure with simple python script. you can find on WLSTbyExample blog link




Technorati claim code QK7QN6U9ZST6

Tuesday, June 5, 2012

Check URL using shell script


We had an issue on production environment. Suddenly one of the webserver got crashed that no one aware of it. That was happen in the Weekend there were no users accessing at that time. When the business hour started Monday morning customer reported to service desk that one of the URL is not working for them. We middleware support team check the URL and identified that the HTTP server not working. Next action items as you know taking the logs backup and starting the HTTP server done.
As part of issue management preventive action to this there could be a monitoring of the URLs. All the web servers hosted application, load balancer that is serving the application or Application server that hosted the web application must be checked randomly or every day before business hours starts.
To do this monitoring team started working on listing out all loadbalancer URL, primary, secondary webserver URLs and also Application server hosted URL lists and checking on the browser each URL. Here is the pain-area doing this in manually there could be
Human errors, Re-testing same URL 
Each URL checking takes almost 1 min
Business have 10 domains then each domain have load balancer URL, primary, secondary webserver URL approx 30 min
Thought of the day! Why don’t we automate this task using UNIX shell scripting. My friend Pubba Praveen came up with idea using wget command.  Started brainstorming searching on internet for a scripts that could monitor the URL. Many forums, blogs, most of them are using curl command whereas Solaris box is not having this command.
Alternate to curl command we have powerful wget command on Solaris.
Challenges
1. While using wget it is downloading junk
2. We have URL list some of them are SSO enabled
The first challenge, can be fix with –spider option will avoid the downloading anything from the website.
The second challenge overcome by using --no-check-certificate option
Redirect output of command into a variable
Test the test url from the command line, that is giving output from HTTP header of that URL. From that we need only single line that shows HTTP status. The grep command will do this, but it cannot be applied directly to that command. Because the wget execution is unable to sending the response to STDOUT, rather it will send to STDERR. To fix this, redirect the STDERR to STDOUT and do this in background ( 2> &1).  You can do this by storing that into a file, but it is not optimum solution. To store it into a variable, So that grep command will be enabled to find the pattern ‘HTTP’.
Create a file with desired URL list - urls.txt
Prepared a bash script that will work as web crawler for your business to check the URL and tells you it’s host is OK or not.
Effective automation script made the script as follows:

#!/bin/bash
#=========================================================
# This script will check for the appliction url working or not
# Author: Pavan Devarakonda
# Date  : 5/29/2012
#=========================================================

# Function that check the URL returns HTTP Status Code
checkURL()
{
       # keep below 2 lines in one
       s=`(/usr/sfw/bin/wget -t 0 --spider --no-check-certificate $1) 2>&1 \
       grep HTTP| tail -1|cut -c 41-43`
       echo $s
}

#========== = = = main script = = = ===========
clear
for url in `cat urls.txt`
do
         HTTPCode=$(checkURL $url) # function call
         if [ $HTTPCode -ge 500 ]
         then
             status="DOWN"
             # mail if this have issue
         else
             status="UP"
         fi
         TIME=`date +%d-%m-%Y_%H.%M.%S`
         echo At $TIME the URL $url $HTTPCode $status
done

This script can be associated with schedule job
 1. crontab old way
2. autosys job scheduler
3. at command for trials
 
Now concern is when my webserver is down the script hangs..
Looking for help now... any comments are invited

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6