I had to develop a simple script to send e-mail alert when the Managed Server goes down. From whatever time I had, I developed a script that does that, it can be enhanced further depending on the requirement.
I used mailx to send mails, you need to get in touch with your System Administrator if its not configured. You can also use the smtplib that comes with Python. However I found mailx simpler as it was preconfigured in my environment
import os
def sendMail(name, state):
string = name+” is in ” + state + ” state”
cmd = “echo ” + string + ” > tmpfile”
os.system(cmd)
os.system(‘/usr/bin/mailx -s ” SERVER STATE” [email protected] < tmpfile’)
def getServerNames():
domainConfig()
return cmo.getServers()
def serverStatus(server):
cd(‘/ServerLifeCycleRuntimes/’ +server)
return cmo.getState()
def sendAlert():
connect(‘weblogic’,’weblogic’,’t3://localhost:7001′)
serverNames= getServerNames()
domainRuntime()
for name in serverNames:
print name.getName()
serverState = serverStatus(name.getName())
print serverState
if serverState == “SHUTDOWN”:
sendMail(name.getName(), serverState)
if __name__== “main”:
sendAlert()
print ’sent!’
Hi Faisal,
I tried your script, and seems like iam missing something.
what i have done is i have incorporated your script with a shell script which looks like:
#!/bin/sh
# set up WL_HOME, the root directory of your WebLogic installation
WL_HOME=”/apps/bea/wl92/weblogic92″
# set up common environment
. “${WL_HOME}/server/bin/setWLSEnv.sh”
CLASSPATH=”${CLASSPATH}:${WL_HOME}/common/eval/pointbase/lib/pbembedded51.jar:${WL_HOME}/common/eval/pointbase/lib/pbtools51.jar:
${WL_HOME}/common/eval/pointbase/lib/pbclient51.jar”
echo
echo CLASSPATH=${CLASSPATH}
“${JAVA_HOME}/bin/java” weblogic.WLST $* test.py
when i Run the above script, it exits with error saying:
bash-3.00$ ./test.sh
CLASSPATH=/apps/bea/wl92/patch_weblogic923/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/apps/bea/wl92/jdk150_12/lib/tools.jar:/apps/bea/wl92/weblogic92/server/lib/weblogic_sp.jar:/apps/bea/wl92/weblogic92/server/lib/weblogic.jar:/apps/bea/wl92/weblogic92/server/lib/webservices.jar:
PATH=/apps/bea/wl92/weblogic92/server/bin:/apps/bea/wl92/jdk150_12/jre/bin:/apps/bea/wl92/jdk150_12/bin:/usr/bin:/apps/ibanker/dev/Feed/lib/poi-3.0.1.jar:/apps/ibanker/dev/Feed/lib/classes12.jar:/apps/apache/2.05/openssl/bin/openssl:/apps/cws/scripts:/usr/bin:/usr/sbin:/usr/local/bin:/export/home/cwsadm/TOOLS:/apps/ant/1.6.5/bin
Your environment has been set.
CLASSPATH=/apps/bea/wl92/patch_weblogic923/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/apps/bea/wl92/jdk150_12/lib/tools.jar:/apps/bea/wl92/weblogic92/server/lib/weblogic_sp.jar:/apps/bea/wl92/weblogic92/server/lib/weblogic.jar:/apps/bea/wl92/weblogic92/server/lib/webservices.jar::/apps/bea/wl92/weblogic92/common/eval/pointbase/lib/pbembedded51.jar:/apps/bea/wl92/weblogic92/common/eval/pointbase/lib/pbtools51.jar: /apps/bea/wl92/weblogic92/common/eval/pointbase/lib/pbclient51.jar
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 “/apps/bea/wl92/weblogic92/server/bin/test.py”, line 4
string = name+” is in ” + state + ” state”
^
SyntaxError: invalid syntax
Could you please help in figuring out the issue?
Thanks
how do you do this on windows server 2003? Do you use smtp server to send out emails? Do you need to cofigure it
Yes, in Windows environment we will have to use an SMTP Server.
Will try to write a post on it…
Cheers!
Faisal