Hi,
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:
- 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
- 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.
- AdminServer Independent: AdminServer Need not be running to get the Server State using thei Script.
- 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.
.
.
Regards,
Jay SenSharma
April 17th, 2011 on 4:52 am
Hi Jay,
Have used this Script in our UAT environment with the following changes.
1) Executed the script as a Cron, removed the check interval logic u have added.
2) Changed the Number of Managed Server, their port and URL’s
3)Changed the State to be Monitored as SHUTDOWN and FAILED
But received alerts when server was in RUNNING State as SHUTDOWN.
Thanks
Sathya
April 17th, 2011 on 9:58 am
Hi Sathya,
Mostly people make mistake using WLST scripts because they do not use the proper indentation space (The WLST/Python Loops and If else opening and closing is determined by the indentation) So be careful with that.
You might have edited the WLST wrong….Because until the “If” block condition is not correct you won’t get desird result.
if serverState != “RUNNING”:
When the block should execute and when NOT…..This is simple Logic….and i hope you will find the answer yourself.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 8th, 2011 on 6:15 pm
Hi Jay,
I used the above script for monitoring my environment. I had 3 servers went down and i got the alert as expected. But that email alert have all three servers mentioned as continueous line. How can i put each server message in a separate line.
Current mail content:
====================
The Server1 May Be DOWN. At Time: Sun May 08 06:49:26 CDT 2011 The Server2 May Be DOWN. At Time: Sun May 08 06:49:26 CDT 2011
Desired content:
================
The Server1 May Be DOWN. At Time: Sun May 08 06:49:26 CDT 2011
The Server2 May Be DOWN. At Time: Sun May 08 06:49:26 CDT 2011
Please help me.
May 9th, 2011 on 11:31 am
Hi mpkbang,
Looks like you have changed some thing inside the script …because if you will see the screenshot attached with the article then you will also find that Each Server State is mentioned in a New line:
http://middlewaremagic.com/weblogic/wp-content/uploads/2011/02/Email-Alert-Server-State.jpg
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 12th, 2011 on 4:59 am
I am using weblogic on windows and i created a new Folder WLST on c drive and created 2 files: domain.properties, serverStateChecker.py. Now i connected to WLST and ran setWLSEnv.cmd to set the environment(dont know if it worked or no). So, when i shut down my server manually from the admin console I did not receive an alert ….Please help!!!
I ran the script by opening the WLST tool and wehn i tried to shur down the managed server it did not send an email alert and I am not sure why…here is the output(below) what i see on my WLST screen
Admin port should be used instead.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
Checking All Servers State Details
Disconnected from weblogic server: MS2
Connecting to t3://servername:7001 with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘bas
e_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.
—————– AdminServer is in State: RUNNING
Disconnected from weblogic server: AdminServer
Connecting to t3://servername:5001 with userid weblogic …
Successfully connected to managed Server ‘MS1′ that belongs to domain ‘base_doma
in’.
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.
—————– MS1 is in State: RUNNING
Disconnected from weblogic server: MS1
Connecting to t3://servername:6001 with userid weblogic …
Successfully connected to managed Server ‘MS2′ that belongs to domain ‘base_doma
in’.
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.
—————– MS2 is in State: RUNNING
The system cannot find the file specified.
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
‘rm’ is not recognized as an internal or external command,
operable program or batch file.
Sleeping for 10 Seconds…
C:WLST>
May 12th, 2011 on 5:02 am
in my previous post why doesnt it send email. do i need to configure a mail client for windows or something?
May 12th, 2011 on 12:27 pm
Hi Siddhans,
WINDOWS operating systems does not provides flexible utilities like “mailx” which is commonly offered by Unix Based Operating Systems. So the Above script will not work on WINDOWS for Sending E-Mail as Windows has certain limitations.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 15th, 2011 on 8:01 pm
hi Jay,
i am getting the out of memory error after some time ,if i run the script in background. even after adding the -Xms & -Xmx to 1GB.
thanks
ARun
May 15th, 2011 on 8:36 pm
Hi Mailarunkumars,
Please refer to the following Links:
1). OutOfMemory Causes and First Aid Steps?
2). Parts Of JVM And JVM Architecture Diagram?
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 16th, 2011 on 11:30 am
Hi Jay,
thanks for the info on out of memory.
But in my case, i ran the above serverStateChecker.py script in background with below memory args then after 1 day, i got the java.lang.OutOfMemoryError: java.lang.OutOfMemoryError: PermGen space
nohup java -Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m weblogic.WLST serverStateChecker.py &
May 16th, 2011 on 7:58 pm
Hi Mailarunkumars,
It looks like a Classloader leak…. May be some of the classes are not being unloaded from the permgen area of JVM . So please try to increase the -XX:MaxPermSize=512m as well as add the following JAVA_OPTIONS to trace the classloading and unloading to find out the root cause :
-XX:+TraceClassloading and -XX:+TraceClassUnloading
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 20th, 2011 on 5:01 am
This script is working very fine in my environment, but the problem is, Whenever i run this script, i am getting High memory usage alert for this single process id almost more than 6GB. Is there any reason for this to happen?
May 20th, 2011 on 12:40 pm
Hi Bharat,
Monitoring resources deployed on Server or monitor Server activities is a heavy weight operation. Still it should not consume 6 GB of memory …we are working on this script to make it more enhanced to see if it will help you out in resolving the issue. We will update a new Script soon.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 26th, 2011 on 4:23 am
Hi Jay,
How to run these scripts on unix (solaris) as a daemon or background process
May 26th, 2011 on 5:05 am
This script works great! but I keep getting emails every 10 secs…is there a way to just get one email and not get emails on and on? Or some other workaround to not get too many emails?
May 27th, 2011 on 1:42 am
Also, if you create a daemon process how do you kill it?
May 27th, 2011 on 8:30 am
Hi Siddhans,
Daemon process is also a Process which has a PID (Process ID) so if we grep the process id then we can kill it using kill -9 $PIC
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 31st, 2011 on 10:31 pm
Yes, I am aware about that but there are bunch of java processes running …two for managed server one for admin server. whats the command to get the process associated for this script
June 1st, 2011 on 12:31 am
HI Siddhans,
Please refer to the following article :
Topic: Using Jps.exe to distinguish WLS ProcessIDs
http://middlewaremagic.com/weblogic/?p=2291
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
June 3rd, 2011 on 4:15 am
Hi Jay,
Thanks! How do you break out of the loop and send email only once and not keep sending emails even if the server which went down is not stared again and hold sending emails until one more managed server goes down or admin server goes down?
To give an example lets say I have one admin server and 2 managed servers…. one managed server goes down so the script sends an email notification. Now i don’t want another email to be sent until the next managed server goes down. So how do i break out of the loop?
June 3rd, 2011 on 5:02 pm
Hi Siddhans,
Please replace the Mail Sending Function mentioned in above Script as following:
Please replace “——–” with 1-TAB Space and “—————-” with 2 TAB Spaces in the above Code snippet.
I did not get a chance to test it but i am 98% Sure that above Code replacement will workout in your case.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 13th, 2011 on 9:10 pm
Hello all! I just entered your site, I expect all of us will achieve lots of knowledge!
Please, can you give me a clue of where is my problem?
I try to monitor two managed servers, but the wladmin is only getting the its ownd adminserver state, and for the managed always return UNKNOWN state:
WL8PATH_>/bea/java/bin/java weblogic.Admin -adminurl t3://hostname:7001 -username username -password foo GETSTATE
Current state of “DemoDomainadmin” : RUNNING
WL8PATH_>/bea/java/bin/java weblogic.Admin -adminurl t3://hostname:7001 -username username -password foo GETSTATE buyerserver1
Current state of “buyerserver1” : UNKNOWN
it sleeps lots of seconds until the unknown response.. working from other wl8 boxes..
dns problem??
Many thanks in advance..have a great day.
July 14th, 2011 on 2:04 am
Hi Canyon,
Just to check if there is any FireWall restriction, You can try to Ping the “buyerserver1” from the AdminServer Box using following Command after running
. ./setWLSEnv.sh
java weblogic.Admin -url t3://buyserver1URL:port -username system -password buyerserver1 PING
Also try the following to GETSTATE of Managed Server:
java weblogic.Admin -url t3://buyerserver1:PORT -username username -password foo GETSTATE buyerserver1
NOTE : donot use “-adminurl” flag to get Managed Server STATE rather use “-url” And Specify the Managed Server URL (Not the Admin Server URL)
Example:
java weblogic.Admin -url t3://managedServerHost:port -username username -password foo GETSTATE ManagedServerName
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 14th, 2011 on 2:50 pm
Hi Jay, many thanks for the tips:
Yes, you are right, there is a firewall between the origin-monitor box and the admin&&server boxes.
With this scene I am able to monitor wl10MP1 processes(managed and Admin) in this way, but it seems that wl8sp4 doesn’t allows because of somehow restriction.
This is the reason for using -adminurl and pointing to its admin_url an not the managed ip/port, because if pointing managed I should need to open nearly 200 ip/ports in order to get my monitor scripts working.
I tried to monitor wl8 from wl10 libraries, but obviously appears the class version difference exception:
java.io.InvalidClassException: javax.management.ObjectName; local class incompatible: stream classdesc serialVersionUID
I’ll try to put a interface of the monitor box behind the fw, but I wonder the network guys will not be happy with this solution.
Sorry for the long post,
Many thanks!
July 25th, 2011 on 10:52 pm
Hi Jay,
My script works fine on one of the servers but on a different box when i try to run the script…
I get this :
—————– MS2 is in State: RUNNING
sh: serverState_file: cannot open
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
Can you please help?
November 3rd, 2011 on 1:16 pm
Hi Jay,
I would like to use the script but I would prefer to have a break in the loop. The loop should check the list of the servers in the domain properties and then stopping there. I have tried it already but then it ends up in an infinite
loop.
Any idea?
Brgds,
Loukas
November 3rd, 2011 on 11:28 pm
Hi Rouglas5,
You can just try to remove the line “29 —– while true:” from the above script and then try again.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 4th, 2011 on 5:08 pm
Thank you Jay.
It has worked!
Brgds,
Rouglas5
January 22nd, 2012 on 4:22 am
Hi Jay,
I am new to WLST.I was trying your script and getting below error.
Problem invoking WLST – Traceback (innermost last):
(no code object) at line 0
File “D:serverStateCheckerserverStateChecker.py”, line 2
from java.io import FileInputStream
^
SyntaxError: invalid syntax
Can you please advice.
Thanks in Advance.
May 8th, 2012 on 11:53 pm
Hi Jay,
I wanted to run above script from cronjob.As you suggested,i took out while true(line no. 29) but the script is not getting invoked.I have saved above script as test3.py and when i run it,i get:
bash-3.2$ java weblogic.WLST test3.py
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
bash-3.2$
I was thinking to have it in cron since our servers are schedule to reboot every month and running as while true may need to restart process manually after every reboot?
How can I avoid while true feature?
Thanks
August 2nd, 2012 on 7:57 pm
Hi Jay,
If we use the server state WLST script. If the server is down each and every 60 sec we have received the same alert mail from the Middleware server. But the requirment is we will receive only one alert mail for that shutdown managed server not repeated alert mail for the same managed server until the server goes to RUNNING state.
If we tried as you mentioned in the Siddhans comments but i am facing the below error.
weblogic@localhost:/var/tmp/wls1034/test> java weblogic.WLST serverStateChecker.py
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST – Traceback (innermost last):
(no code object) at line 0
File “/var/tmp/wls1034/test/serverStateChecker.py”, line 25
if shouldSendMail != “NO”:
^
SyntaxError: invalid syntax
Regards,
S.Vinoth Babu
August 3rd, 2012 on 12:57 pm
There seems nothing wrong with:
if shouldSendMail != “NO”:
except maybe the ” instead of “, orother unreadable characters are present in your script.
For example,
will lead to:
October 2nd, 2012 on 8:12 am
Hi,
When I run the script, and if the servers are in RUNNING state,the script executes fine but if one of the servers is in “WARNING” then the script hangs and its not sending mail. Can you please advice?
Cheers
Sridhar
October 7th, 2012 on 6:49 pm
You can add the proper ‘if’ statements to your script, for example,
if (state == ‘RUNNING’):
you can send your e-mail
if (state != ‘RUNNING’):
you can do something else
October 9th, 2012 on 12:26 pm
hi
am very new to scripting, I have tried the above given script on AIX environment. Am getting the below issue.
Please help me out:
Initializing WebLogic Scripting Tool (WLST) …
*sys-package-mgr*: skipping bad jar, ‘/usr/java6_64/jre/lib/ext/sunjce_provider.jar’
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST – Traceback (innermost last):
(no code object) at line 0
File “/appvolume/oracle11/weblogicapp/Middleware/wlserver_10.3/server/bin/serverStateChecker.py”, line 23
os.system(‘/bin/mail -s “ALERT: Check Server May Not Be RUNNING !!! Please check…” kameswara.kumar@hdfcergo.com < serverState_file')
^
SyntaxError: invalid syntax
October 9th, 2012 on 1:19 pm
Could try separating the command you are entering into os.system(command), for example,
[weblogic@middleware-magic ~]$ cd weblogic12.1.1/installation/wlserver_12.1/common/bin/
[weblogic@middleware-magic bin]$ ./wlst.sh
wls:/offline> command=”cat /etc/hosts”;
wls:/offline> os.system(command);
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.150 middleware-magic.com middleware-magic
wls:/offline> command=”ls -al”
wls:/offline> os.system(command);
total 116
drwxrwxr-x. 2 weblogic weblogic 4096 Sep 19 16:26 .
drwxrwxr-x. 9 weblogic weblogic 4096 Sep 19 16:26 ..
-rwxr-x—. 1 weblogic weblogic 24354 Sep 19 16:26 commEnv.sh
-rwxr-x—. 1 weblogic weblogic 2139 Sep 19 16:26 config_builder.sh
-rwxr-x—. 1 weblogic weblogic 2291 Sep 19 16:26 config.sh
-rwxr-x—. 1 weblogic weblogic 2596 Sep 19 16:26 pack.sh
-rwxr-x—. 1 weblogic weblogic 2150 Sep 19 16:26 setPatchEnv.sh
-rwxr-x—. 1 weblogic weblogic 4105 Sep 19 16:26 startManagedWebLogic.sh
-rwxr-x—. 1 weblogic weblogic 2104 Sep 19 16:26 unpack.sh
-rwxr-x—. 1 weblogic weblogic 3315 Sep 19 16:26 upgrade.sh
-rwxr-x—. 1 weblogic weblogic 31234 Sep 19 16:26 wlscontrol.sh
-rwxr-x—. 1 weblogic weblogic 13854 Sep 19 16:26 wlsifconfig.sh
-rwxr-x—. 1 weblogic weblogic 801 Sep 19 16:26 wlst.sh
Maybe first just try to use a simple command, such as the ones above, to see if that is working on AIX.
Note that the syntax error is usually caused by typos in your script, for example,
wls:/offline> os.system(command_;
Traceback (innermost last):
(no code object) at line 0
File “”, line 1
SyntaxError: invalid syntax
Note the ‘_’ instead of the ‘)’
October 9th, 2012 on 1:41 pm
hi
as said, i tried running the simple command as above given example. Its working on AIX.
so please tell me now how to proceed further.
Thanks
October 10th, 2012 on 6:28 pm
Debug your code line by line and see where it goes wrong.
October 10th, 2012 on 8:48 pm
HiRene,
Am nor familiar with any of the scripting, very new for all, as u suggested i may not able to debug properly, is there any other way if you can help , it would be greatful.
Please suggest me some steps in detail to check so that i can do the same & can see if its working.
October 10th, 2012 on 9:09 pm
You can open a wlst console, by running wlst.sh (located in the ${WL_HOME}/common/bin directory).
When the console is open, you can copy and paste your code (line-by-line) into the console and press enter such that the piece of code will be executed.
October 23rd, 2012 on 1:36 am
I have implemented the script.The problem is that we intermittently have one or more manged server Health shows as Blank and we used to restart these servers to clear this issue.
Check server state script trying to connect to one of these servers it keeps trying and but Not able to connect to the Server with Blank Health and never comeback. Can you please advice on how to overcome this !
Thank you.
February 18th, 2013 on 1:27 pm
Hey Guys,
I have 21 managed servers in a cluster running on same port. Please suggest the changes required to use this script in such case?
I tried it and it gives RUNNING for all the servers even if some of them are down.
Thanks,
Ajeet
February 26th, 2013 on 9:26 pm
Hi Rene,
I would like to receive an Email notification when any of the Managed servers,Admin server is down on Weblogic 10.2.3 . I have read articles which says to use the SMTP to receive notification when the Heap Free Percent meets some criteria. But in this case i need notification when any of the Managed servers is down.
Thanks in Advance.
February 27th, 2013 on 1:46 pm
You probably have to do it on the OS level.
On linux you can use mail to send e-mail notifications (http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/)
You also need some kind of polling mechanism that checks if the servers are still running.
You can use the ps command to check if the server is still up, for example, ps -ef|grep server-name. Based on what is returned
you can send an e-mail. To create bash scripts, you can use the following tutorials
– http://www.tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
– http://tldp.org/LDP/abs/html/
– http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
March 31st, 2016 on 6:22 pm
Hi ,
Issue#1: I didn’t find weblogic.WLST script, Plz help me to find the path for this script.
Issue#2 I executed “wlst.sh serverStateChecker.py” and getting java nullpointer exception. Please help to resolve the issue.
Regards,
Gangii
March 31st, 2016 on 6:55 pm
Hello Gangii,
Issue#1: I didn’t find weblogic.WLST script, Plz help me to find the path for this script.
>>> The “weblogic.WLST” is not a script rather a JAVA class which is responsibkle for starting the WLST command window. The “wlst.sh” Script itself uses the same class “weblogic.WLST”. So you can directly use the “wlst.sh” script. As you mentioned below. Both will do the same thing.
Issue#2 I executed “wlst.sh serverStateChecker.py” and getting java nullpointer exception. Please help to resolve the issue.
>>> Can you please share the complete stackTrace (output) that shows the NullPointerException that will help us in understanding the root cause.
Just some additional pointers what you should be checking.
1). Make sure to specify the absolute path of the script “/PATH/TO/serverStateChecker.py”
2). Also please make sure that the same directory should include the “/PATH/TO/domain.properties” file as well.
Regards
Jay SenSharma
March 31st, 2016 on 11:51 pm
Hi Jay,
Please find below details and help me to figure out this issue.
Step 1: WLST directory has been created.
Path: /srvrs/Oracle/Middleware/WLST
step 2:
Under WLST created domain.properties with below content
===================
dmin.username=weblogic
admin.password=Passw0rd
total.number.of.servers=1
server.name.1=AdminServer
server.url.1=t3://192.168.133.130: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:
Created serverStateChecker.py file with below content
=========================================================
from java.util import Date
from java.io import FileInputStream
import java.lang
import os
import string
propInputStream = FileInputStream(“/srvrs/Oracle/Middleware/WLST/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…” gangireddy.ch@gmail.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 > 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 3: Excecuted below command:
#/srvrs/Oracle/Middleware
./wlserver_10.3/common/bin/wlst.sh WLST/serverStateChecker.py
Result:
CLASSPATH=/srvrs/Oracle/Middleware/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/srvrs/Oracle/Middleware/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/usr/java/jdk1.8.0_73/lib/tools.jar:/srvrs/Oracle/Middleware/wlserver_10.3/server/lib/weblogic_sp.jar:/srvrs/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar:/srvrs/Oracle/Middleware/modules/features/weblogic.server.modules_10.3.6.0.jar:/srvrs/Oracle/Middleware/wlserver_10.3/server/lib/webservices.jar:/srvrs/Oracle/Middleware/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/srvrs/Oracle/Middleware/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar::/srvrs/Oracle/Middleware/utils/config/10.3/config-launch.jar::/srvrs/Oracle/Middleware/wlserver_10.3/common/derby/lib/derbynet.jar:/srvrs/Oracle/Middleware/wlserver_10.3/common/derby/lib/derbyclient.jar:/srvrs/Oracle/Middleware/wlserver_10.3/common/derby/lib/derbytools.jar::
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
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
This Exception occurred at Thu Mar 31 23:45:30 IST 2016.
java.lang.NullPointerException
Sorry !!! Unable to Connect to Server AdminServer
********* ALERT MAIL HAS BEEN SENT FOR SERVER STATE ***********
Sleeping for 10 Seconds…
April 1st, 2016 on 1:16 am
Hello Gangii,
Your code does not look complete. I do not see any where in your PY script the following code:
connect(adminUser,adminPassword,serverURL)
serverRuntime()
Without getting connected to the server how can it return the Server Runtime information ?
Also the [while i > serverState_file:] While loop does not seems to be looking correct here, I guess it should be [while i < = totalServers:] instead. I will suggest you to please carefully go through the http://middlewaremagic.com/weblogic/?p=5838 link once again to compare your code.
Regards
Jay SenSharma
March 16th, 2018 on 12:32 pm
Hi Jay,
shouldSendMail="YES"
^
SyntaxError: invalid syntax
Any idea why ?
August 8th, 2018 on 3:54 pm
Hi,
As this script is used to fetch the state of the servers, but how can we fetch the health of the running weblogic servers from WLST.
Thanks