Sei sulla pagina 1di 5

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:
01 admin.username=weblogic 02 admin.password=weblogic 03 04 total.number.of.servers=3 05 06 server.name.1=AdminServer 07 server.url.1=t3://10.10.10.10:7001 08 09 server.name.2=MS-1 10 server.url.2=t3://10.10.10.10:7003 11 12 server.name.3=MS-2 13 server.url.3=t3://10.10.10.10:7005 14 # Check Server State At following interval in Seconds to check the State of the Server 16 check.interval=10 15

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:
0 ########################################################################### 1 ## 0 # 2 # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. 04 # 03 0 ########################################################################### 5 ## 0 from java.util import Date 6 07 from java.io import FileInputStream 08 import java.lang 09 import os 10 import string

11 12 propInputStream = FileInputStream("domain.properties") 13 configProps = Properties() 14 configProps.load(propInputStream) 15 16 adminUser = configProps.get("admin.username") 17 adminPassword = configProps.get("admin.password") 18 checkInterval = configProps.get("check.interval") 19 totalServersToMonitor = configProps.get("total.number.of.servers") 20 checkingIntervalSeconds = int(checkInterval) 21 22 ############# This method would send the Alert Email ################# 23 def sendMailString(): os.system('/bin/mailx -s "ALERT: Check Server May Not Be RUNNING !!! 24 Please check..." admin@company.com < serverState_file') print '********* ***********' 26 print '' 25 27 28 ############# Infinite Loop to check the Status of Server in Mentioned Interval ################# ALERT MAIL HAS BEEN SENT FOR SERVER STATE

29 while true: 30 print 'Checking All Servers State Details' 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 except: serverState if serverState != "RUNNING": today = Date() serverState + ' stateMessage = 'The ' + serverName + ' is In State ' + At Time: ' + today.toString() cmd = "echo " + stateMessage +" >> serverState_file" os.system(cmd) 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: ',

49 50 51

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: 52 ' + today.toString() 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ####################################################################### print 'Sleeping for ', int(checkingIntervalSeconds) , ' Seconds...' print '' interval=int(checkingIntervalSeconds) Thread.sleep(interval*1000) sendMailString() cmd = "rm -f serverState_file" os.system(cmd) cmd = "echo " + stateMessage +" >> serverState_file" os.system(cmd) i = i +1

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:
1 java weblogic.WLST serverStateChecker.py

You will see the following kind of results in the command prompt
01 Initializing WebLogic Scripting Tool (WLST) ... 02 $ java weblogic.WLST serverStateChecker.py 03 04 Initializing WebLogic Scripting Tool (WLST) ... 05 06 Welcome to WebLogic Server Administration Scripting Shell 07 08 Type help() for help on available commands 09 10 Checking All Servers State Details

11 12 You will need to be connected to a running server to execute this command 13 14 Connecting to t3://10.65.193.88:7001 with userid weblogic ... 15 This Exception occurred at Thu Feb 24 19:03:25 IST 2011. javax.naming.CommunicationException [Root exception is 16 java.net.ConnectException: t3://10.65.193.88:7001: Destination unreachable; nested exception is: 1 java.net.ConnectException: Connection refused; No available router to 7 destination] at 1 weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTrans 8 lator.java:40) at 1 weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialCon 9 textFactoryDelegate.java:783) at 2 weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialCon 0 textFactoryDelegate.java:365) 21 22 23 . 24 . 25 . 26 . 27 Sorry !!! Unable to Connect to Server 28 29 You will need to be connected to a running server to execute this command 30 31 Connecting to t3://10.65.193.88:7003 with userid weblogic ... Successfully connected to managed Server 'MS-1' that belongs to domain 32 'Test_Domain'. 33 34 Warning: An insecure protocol was used to connect to the 35 server. To ensure on-the-wire security, the SSL port or 36 Admin port should be used instead. 37 38 Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root. AdminServer at weblogic.jndi.Environment.getContext(Environment.java:315) at weblogic.jndi.Environment.getContext(Environment.java:285)

39 For more help, use help(serverRuntime) 40 41 ----------------- MS-1 is in State: RUNNING 42 Disconnected from weblogic server: MS-1 43 Connecting to t3://10.10.10.10:7005 with userid weblogic ...

44 45

Successfully connected to managed Server 'MS-2' that belongs to domain 'Test_Domain'.

46 Warning: An insecure protocol was used to connect to the 47 server. To ensure on-the-wire security, the SSL port or 48 Admin port should be used instead. 49 50 ----------------- MS-2 is in State: 52 53 Sleeping for 10 Seconds... ADMIN

51 ********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********

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.

Potrebbero piacerti anche