Alert

Sending Email Alert for Application Current State

Ravish Mody

Yesterday evening one of your subscriber middleware_guy using comment asked us how can he can get a regular update say every 1 hour get an email showing the current state of an applications which are not in prepared or failed states, hence we updated our previous script which was written by Jay called Getting Application States using WLST to get the above requirement.

We have just added the two logic in this script which are the email and condition loop which would make sure that only shoot an email when the applications are not in Active states, however you can still modify this to fulfill your requirement and regarding the check every 1 hour I would suggest to use the Cron-Job utility to call this script.

Update:

I have updated the script to show on which server is the applications are be targeted, as this script automatically gets all the application state which are been deployed on all the servers in that domain, without giving any details of the managed servers in domain.

Steps to Create an Email Alert For Application Current State

Step1) Create a Directory somewhere in your file system like : “C:WLST”

Step2) Write a Properties file “domains.properties” inside “C:WLST” like following:

admin.url=t3://localhost:7001
username=weblogic
password=weblogic

Step-3) Create a WLST Script somewhere in your file system with some name like “application_status.py” inside “C:WLST” contents will be something like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domains.properties")
configProps = Properties()
configProps.load(propInputStream)

ServerUrl = configProps.get("admin.url")
UserName = configProps.get("username")
Password = configProps.get("password")

#############  This method would send the Alert Email  #################
def sendMailString():
	os.system('/bin/mailx -s  "ALERT: Applications are currently NOT in ACTIVE state !!! " ABCD@comapny.com < currentAppState_file')
	print '*********  ALERT MAIL HAS BEEN SENT  ***********'

redirect('wlst.log','false')
connect(UserName,Password,ServerUrl)
cd ('AppDeployments')
myapps=cmo.getAppDeployments()
print '=============================================='
print 'Following Applications are not in STATE_ACTIVE'
print '=============================================='
for appName in myapps:
	domainConfig()
	cd ('/AppDeployments/'+appName.getName()+'/Targets')
	mytargets = ls(returnMap='true')
	domainRuntime()
	cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')
	for targetinst in mytargets:
		currentAppState=cmo.getCurrentState(appName.getName(),targetinst)
		if currentAppState != "STATE_ACTIVE":
			writeInFile ='Applicaiton = "'+ appName.getName() +'"   //    Targeted Server = "'+str(mytargets)+'"   //     Current STATE = "'+ currentAppState +'"'
			print '', writeInFile
			cmd = "echo " + writeInFile + " >> currentAppState_file"
			os.system(cmd)
print '=============================================='
print''
sendMailString()
cmd = "rm -f wlst.log currentAppState_file"
os.system(cmd)

Step-4) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492 Step-5) Now run the WLST Script in the same command prompt using the following command:

java   weblogic.WLST  application_status.py

You will see the following kind of results in the command prompt

$java weblogic.WLST application_status.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

==============================================
Following Applications are not in STATE_ACTIVE
==============================================
 Applicaiton = "Mysite"   //    Targeted Server = "[AdminServer]"   //     Current STATE = "STATE_PREPARED"
 Applicaiton = "SessionTest.war#VesionB"   //    Targeted Server = "[Cluster]"   //     Current STATE = "STATE_NEW"
 Applicaiton = "_appsdir_ClassLoaderTestEAR_ear"   //    Targeted Server = "[AdminServer]"   //     Current STATE = "STATE_PREPARED"
 Applicaiton = "MDB"   //    Targeted Server = "[MS-2]"   //     Current STATE = "STATE_NEW"
 Applicaiton = "FirstEARApplication"   //    Targeted Server = "[MS-1]"   //     Current STATE = "STATE_NEW"
 Applicaiton = "SecondEARApplication"   //    Targeted Server = "[MS-1]"   //     Current STATE = "STATE_NEW"
==============================================

*********  ALERT MAIL HAS BEEN SENT  ***********

NOTE: This script is using mailx (i.e. but Windows box does not have mailx utility) so please do check if your mailx is configured properly or else script would run properly but the mail would not be sent.


Regards,

Ravish Mody


Stuck Thread Alert using WebLogic SNMP Agent

Hi,
Jay SenSharma

Jay SenSharma

Based on a requirement of a  user named Shashi_sr on Oracle Forums we have created this post. Getting Alert is one of the most important  requirement in production environments. We can use many techinques to get alerts regarding the behaviour and scenario of WebLogic Server. WLST, JMX and WLDF are the most common techniques to monitor our WebLogic server resources and the health check of these resources.

Here we are going to see a very simple example of creating  a STUCK THREAD alert using SNMP Log Filters.  So that as soon as any thread will be declared by WebLogic  as STUCK we will immediately get an SNMP Alert.

You can also do the same thing using WLST script have a look at the post –  Sending Email Alert For Stuck Threads With Thread Dumps

Step1). Login to AdminConsole and then nevigate to “Diagnostics————> SNMP”

Step2). Now create an SNMP Agent like following:

Name: StuckThreadSNMPAgent
Enabled: true
Targeted Servers: AdminServer
UDP Port : 161
Community Prefix: public
Send Automatic Traps Enabled : true
Community Based Access Enabled : true
Inform Retry Interval : 10000
Maximum Inform Retry Count : 1
Credential Cache Invalidation Interval : 3600000
LogFilter_StuckThread_1

LogFilter_StuckThread_1

Step3). Now create a Log Filter  By clicking on

“Diagnostics—->SNMP—–>StuckThreadSNMPAgent—–>Configuration (Tab)—–>Log Filters”
like following:
Name: StuckThreadLogFilter
Enabled Servers: AdminServer
Severity Level: Error
Subsystem Names: WebLogicServer
Message IDs : 000337
Message Substring : [STUCK] ExecuteThread
Like following:
LogFilter_StuckThread_2

LogFilter_StuckThread_2

Step4). Now  Create a Trap Destination like following:

“Diagnostics—->SNMP—–>StuckThreadSNMPAgent—–>Configuration (Tab)—–>Trap Destinations”
Name: StuckThreadTrapDest
Community: public
Host: localhost
Port : 165
as following:
LogFilter_StuckThread_3

LogFilter_StuckThread_3

Step5). Now restart your Server  Just to make sure that every thing is OK.

Step6). Now open a command prompt and then run “setWLSEnv.cmd”/ setWLSEnv.sh  then start the

java weblogic.diagnostics.snmp.cmdline.Manager SnmpTrapMonitor -p 165

LogFilter_StuckThread_4

LogFilter_StuckThread_4

As soon as you will get any STUCK THREAD you will get an alert immediately as following:

LogFilter_StuckThread_5

LogFilter_StuckThread_5

.
.
Thank
Jay SenSharma

Sending Email Alert for WebLogic Servers Current State

Hi,

Jay SenSharma

Jay SenSharma

In every production environment we want to keep monitoring the State of our WebLogic Server, Like RUNNING, ADMIN, etc. Usually we face problem in getting the Status report, because most of the tools (Non-Operating System related) we know to accomplsh this task but those tools requires Admin Server to be UP and RUNNING to provide us the Current Status details of the Servers.

While running this WLST script you will get  “Caused by: java.rmi.ConnectException: Destination unreachable;”  which is Normal and expected if the Weblogic Server will not be running

So here we provide a simple WLST script which has the following features:

Features:

  1. Ready To Use: The Script do not require any kind of changes in the WLST Script, except the Administrators E-Mail address at line number: 24
  2. Standalone: You can use Check Server State At the mentioned “check.interval” interval by just changing the properties file. No need to use any Cron Job.
  3. AdminServer Independent: AdminServer Need not be running to get the Server State using thei Script.
  4. Reliable: Compared to the Cron Jobs which usually checks the Server Log and grep the Server State, This WLST script is more reliable.

Steps to Configure an Email Alert for Checking State Of Server

Step1) Create a Directory somewhere in your file system like :  “C:WLST”

Step2) Write a Properties file “domain.properties” inside “C:WLST” like following:

admin.username=weblogic
admin.password=weblogic

total.number.of.servers=3

server.name.1=AdminServer
server.url.1=t3://10.10.10.10:7001

server.name.2=MS-1
server.url.2=t3://10.10.10.10:7003

server.name.3=MS-2
server.url.3=t3://10.10.10.10:7005

# Check Server State At following interval in Seconds to check the State of the Server
check.interval=10

Step-3) Create a WLST Script somewhere in your file system with some name like “serverStateChecker.py” inside “C:WLST” contents will be something like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.util import Date
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

adminUser = configProps.get("admin.username")
adminPassword = configProps.get("admin.password")
checkInterval = configProps.get("check.interval")
totalServersToMonitor = configProps.get("total.number.of.servers")
checkingIntervalSeconds = int(checkInterval)

#############  This method would send the Alert Email  #################
def sendMailString():
	os.system('/bin/mailx -s  "ALERT: Check Server May Not Be RUNNING !!! Please check..." admin@company.com < serverState_file')
	print '*********  ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********'
	print ''

#############  Infinite Loop to check the Status of Server in Mentioned Interval  #################
while true:
	print 'Checking All Servers State Details'
	totalServers = int(totalServersToMonitor)
	i=1
	while i <= totalServers:
		disconnect()
		serverState=""
		serverName = configProps.get("server.name." + str(i))
		serverURL = configProps.get("server.url." + str(i))
		try:
			connect(adminUser,adminPassword,serverURL)
			serverRuntime()
			serverState=cmo.getState()
			print '-----------------', serverName , ' is in State: ', serverState
			if serverState != "RUNNING":
				today = Date()
				stateMessage = 'The ' + serverName + ' is In State ' + serverState + '  At Time: ' + today.toString()
				cmd = "echo " + stateMessage +" >> serverState_file"
				os.system(cmd)
		except:
			serverName=configProps.get("server.name." + str(i))
			print 'Sorry !!! Unable to Connect to Server ' , serverName
			today = Date()
			stateMessage = 'The ' + serverName + ' May Be DOWN.' + ' At Time: ' + today.toString()
			cmd = "echo " + stateMessage +" >> serverState_file"
			os.system(cmd)
		i =  i + 1

	sendMailString()
	cmd = "rm -f serverState_file"
	os.system(cmd)

	print 'Sleeping for ', int(checkingIntervalSeconds) , ' Seconds...'
	print ''
	interval=int(checkingIntervalSeconds)
	Thread.sleep(interval*1000)

#######################################################################

Step-4) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492

Step-5) Now run the WLST Script in the same command prompt using the following command:

java   weblogic.WLST  serverStateChecker.py

You will see the following kind of results in the command prompt

Initializing WebLogic Scripting Tool (WLST) ...
$ java weblogic.WLST serverStateChecker.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Checking All Servers State Details

You will need to be connected to a running server to execute this command

Connecting to t3://10.65.193.88:7001 with userid weblogic ...
This Exception occurred at Thu Feb 24 19:03:25 IST 2011.
javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://10.65.193.88:7001: Destination unreachable; nested exception is:
	java.net.ConnectException: Connection refused; No available router to destination]
	at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:40)
	at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:783)
	at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:365)
	at weblogic.jndi.Environment.getContext(Environment.java:315)
	at weblogic.jndi.Environment.getContext(Environment.java:285)
.
.
.
.
Sorry !!! Unable to Connect to Server  AdminServer

You will need to be connected to a running server to execute this command

Connecting to t3://10.65.193.88:7003 with userid weblogic ...
Successfully connected to managed Server 'MS-1' that belongs to domain 'Test_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 serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

----------------- MS-1  is in State:  RUNNING
Disconnected from weblogic server: MS-1
Connecting to t3://10.10.10.10:7005 with userid weblogic ...
Successfully connected to managed Server 'MS-2' that belongs to domain 'Test_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.

----------------- MS-2  is in State:  ADMIN
*********  ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********

Sleeping for  10  Seconds...

NOTE: This script is using mailx (i.e. but Windows box does not have mailx utility) so please do check if your mailx is configured properly or else script would run properly but the mail would not be sent.

Email Alert Server State

Email Alert Server State

.
.

Regards,
Jay SenSharma


Copyright © 2010-2012 Middleware Magic. All rights reserved. |