Sunday 29 May 2016

blogger

[WLS 12.2.1.0.0]Script to get the email notification in case current or pending messages on distributed queues are greater than zero on any of the JMS server.

Hello Viewer,

I wanted to get the notification in case current or pending messages on distributed queues are greater than zero on any of the JMS server.
One easy way for this is to create watches and Notification under WLDF. But since i am using weblogic version 12.2.1.0.0, it is not easy to create policy for this task as rule expression tab is not present in 12.2.1.0.0 when policy type is "collected metric".

So i thought of creating the script which can constantly monitor the set of queues and will send an email notification having html content with proper cosmetics :)
Below are the steps to be followed:

1) Create a file QueueReport.sh with below content:

----------------------------------------------------------------------------------------------------------
#!/bin/sh
# set up WL_HOME, the root directory of your WebLogic installation
WL_HOME="wl_home"
cd /MyLocation/QueueReport
rm QueueReport.txt
umask 027
   echo "CHECKING QUEUE STATUS " > finalStatus3.out
    while read LINE; do
      date >> QueueReport.txt
      queue=$(echo "$LINE" | awk -F, '{ print $1 }');

    sh ${WL_HOME}/common/bin/wlst.sh /MyLocation/QueueReport/QueueReport.py $queue >> QueueReport.txt
    done < QueueList.txt
cat QueueReport.txt | grep "queue/topic" >> finalStatus3.out
grep -v "is 0 and 0" finalStatus3.out > temp.txt
mv temp.txt finalStatus3.out
echo "CHECKED QUEUE STATUS " >> finalStatus3.out
----------------------------------------------------------------------------------------------------------

2) Create a file QueueReport.py with below content:


Note: I am assuming there are two Managed server and two JMS server targeted to each managed server respectively.
 Change the below values according to your ennvironment.

jms_module name: JMS_TST_MODULE
jms server name :  JMS_TST_SERVER1,  JMS_TST_SERVER2
managed server name:  SOA_MS1,  SOA_MS2

-----------------------------------------------------------------------------------------------------------
import ConfigParser

def connectToServer():
        USERNAME = 'username'
        PASSWORD = 'password'
        URL='t3://Adminhost:Adminport'
        #Connect to the Administration Server
        print 'starting the script ....'
        connect(USERNAME,PASSWORD,URL)

def disconnectFromServer():
    print "Disconnecting from the Admin Server"
    disconnect()
    print "Exiting from the Admin Server"
    exit()
    print "Mission Accomplished"

def readConfigurationFile(myDestinationName):
    try:
          cd('ServerRuntimes/SOA_MS1/JMSRuntime/SOA_MS1.jms/JMSServers/JMS_TST_SERVER1/Destinations/JMS_TST_MODULE!JMS_TST_SERVER1@'+myDestinationName)
        current1=str(cmo.getMessagesCurrentCount());
        pending1=str(cmo.getMessagesPendingCount());
      cd('ServerRuntimes/SOA_MS2/JMSRuntime/SOA_MS2.jms/JMSServers/JMS_TST_SERVER2/Destinations/JMS_TST_MODULE!JMS_TST_SERVER2@'+myDestinationName)
        current2=str(cmo.getMessagesCurrentCount());
        pending2=str(cmo.getMessagesPendingCount());
        totalcurrent = int(current1) + int(current2)
        totalpending = int(pending1) + int(pending2)

        print 'The number of current/pending  messages on JMSServer in the queue/topic '+myDestinationName+' is '+str(totalcurrent)+' and '+str(totalpending)
    except :
        print 'Unable to find admin server...'
        exit()

    print 'Command executed successfully'

###############     Main Script   #####################################
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport
print('This will enable you to give report for JMS Queues')
connectToServer()
readConfigurationFile(sys.argv[1])
####################################
----------------------------------------------------------------------------------------------------------------

3) Create a file QueueList.txt having the name of the queues that needs to be monitored.

----------------------------------------------------------------------------------------------------------------
queuename1
queuename2
queuename3
----------------------------------------------------------------------------------------------------------------

4) Create a file QueueMessageReport.sh with below content:

-----------------------------------------------------------------------------------------------------------------
#!/bin/bash
MAILTO=abc@gmail.com
MAILCC=abc@gmail.com
MAILFROM=abc@gmail.com
OUTPUT=/MyLocation/QueueReport/finalStatus.html

# Start the processes in parallel...
cd /MyLocation/QueueReport
sh QueueReport.sh

echo '<html>' > $OUTPUT
echo "<br /><b style='color:#ff0000'>Queue Status for SOA TESTR2</b> <br /><br />" >> $OUTPUT
COUNT=0
while read LINE ; do
    if [ "${LINE}" = "CHECKING QUEUE STATUS" ]; then
        echo "<table border=2 cellpadding=10 cellspacing=0>" >> $OUTPUT
        echo "<tr style='background-color:#787878;color:white;font-weight:bold'><td>Queue Name</td><td>JMS Server</td><td>Pending Message</td><td>Current Message</td></tr>" >> $OUTPUT
    elif [ "${LINE}" = "CHECKED QUEUE STATUS" ]; then
        echo "</table><br/><br/>" >> $OUTPUT
    else
       echo "<tr style='background-color:white;font-weight:bold'>" >> $OUTPUT
       echo "<td>" >> $OUTPUT
       echo "$LINE" | awk -F " " '{print $11}' >> $OUTPUT
       echo "</td>" >> $OUTPUT
       echo "<td>" >> $OUTPUT
       echo "$LINE" | awk -F " " '{print $7}' >> $OUTPUT
       echo "</td>" >> $OUTPUT
       echo "<td>" >> $OUTPUT
       echo "$LINE" | awk -F " " '{print $15}' >> $OUTPUT
       echo "</td>" >> $OUTPUT
       echo "<td>" >> $OUTPUT
       echo "$LINE" | awk -F " " '{print $13}' >> $OUTPUT
       echo "</td>" >> $OUTPUT
       echo "</tr>" >> $OUTPUT
    fi
done < finalStatus3.out
grep -v "CHECKING QUEUE STATUS" finalStatus3.out > tempfile.txt
mv tempfile.txt finalStatus3.out
grep -v "CHECKED QUEUE STATUS" finalStatus3.out > tempfile1.txt
mv tempfile1.txt finalStatus3.out
if [[ -s finalStatus3.out ]] ; then
(
 #                       echo "From: $MAILFROM"; \
                        echo "To: abc@gmail.com"; \
                     #   echo "Cc: $MAILCC"; \
                        echo "Content-Type: text/html";\
                        echo "Subject: QueueReport"; \
                        echo ""; \
                       cat $OUTPUT; \
                ) | /usr/lib/sendmail -t
else
echo "FILE is empty."
fi ;
-----------------------------------------------------------------------------------------------------------------

How to Run:

Execute the below command:
sh QueueMessageReport.sh

Thanks a lot for your patience!!!

Regards
-Ashish

No comments:

Post a Comment