One of the users Hong from Oracle Technology Network was having difficulty in chaining the log setting for n number of servers in a domain using Admin console. Now the same things has to be done on say n number of domains so say if one has 10 servers in a 1 domain and has total 10 Domains then in total he has to do the same changes for 100 servers which is very time consuming using Admin-consoles.
Thus came Middleware Magic Team to the rescue and we created a WLST script which would do the same using thing very easily and quickly without any tedious job. Just give the domain and there servers details in the domain.properties files and you are good to go.
Steps to Edit Server Log Configuration For Multiple Domains Using WLST
Step1). Create a Directory somewhere in your file system like : “C:WLST_log”
Step2). Write a Properties file “domain.properties“ inside “C:WLST_log” like following:
total.domain.count=2 ################### Logging Options ################### rotationType=bySize numberOfFilesLimited=no fileMinSize=3000 rotateLogOnStartup=no fileCount=5 ################### Domain-1 Details ################### domain.1.name=Domain_7001 domain.1.admin.url=t3://10.10.10.10:7001 domain.1.admin.username=weblogic domain.1.admin.password=weblogic total.domain.1.server.count=2 domain.1.server.1.name=AdminServer domain.1.server.2.name=MS-1 ################### Domain-2 Details ################### domain.2.name=Test_Domain domain.2.admin.url=t3://20.20.20.20:7001 domain.2.admin.username=weblogic domain.2.admin.password=weblogic total.domain.2.server.count=2 domain.2.server.1.name=AdminServer domain.2.server.2.name=MS-1
Step2). Now in the same directory write the following WLST Script “domainLogConfigurtionChange.py” like following:
Updated [03/10/2011]
Thanks to Vishal Mahajan who spotted few bugs in our previous script and helped us to fix them
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# from java.io import FileInputStream propInputStream = FileInputStream("domain.properties") configProps = Properties() configProps.load(propInputStream) totalNumbersofDomains=configProps.get("total.domain.count") rotationType=configProps.get("rotationType") numberOfFilesLimited=configProps.get("numberOfFilesLimited") fileMinSize=configProps.get("fileMinSize") rotateLogOnStartup=configProps.get("rotateLogOnStartup") fileCount=configProps.get("fileCount") def str2bool(v): return v.lower() in ("yes", "true", "t", "1") domainTmpCount=1 while (domainTmpCount <= int(totalNumbersofDomains)) : domainName = configProps.get("domain."+ str(domainTmpCount)+".name") domainAdminUrl = configProps.get("domain."+ str(domainTmpCount)+".admin.url") domainAdminUserName = configProps.get("domain."+ str(domainTmpCount)+".admin.username") domainAdminPassword = configProps.get("domain."+ str(domainTmpCount)+".admin.password") serverCount = configProps.get("total.domain."+ str(domainTmpCount)+".server.count") connect(domainAdminUserName, domainAdminPassword, domainAdminUrl) print '##################################################' print 'Changing Log Settings For Domain: ', domainName print '##################################################' serverTmpCount=1 edit() while (serverTmpCount <= int(serverCount)) : startEdit() currentServerName = configProps.get("domain."+ str(domainTmpCount)+".server."+ str(serverTmpCount)+".name") print '----------------------------------------------------' print 'Changing Log Setting for serverName: ' , currentServerName print '----------------------------------------------------' cd('/Servers/' + currentServerName + '/Log/' + currentServerName) cmo.setRotationType(rotationType) cmo.setNumberOfFilesLimited(str2bool(numberOfFilesLimited)) cmo.setFileMinSize(int(fileMinSize)) cmo.setRotateLogOnStartup(str2bool(rotateLogOnStartup)) cmo.setFileCount(int(fileCount)) cmo.setFileName('logs/' + currentServerName + '.log') activate() print '===> Log Setting for serverName: ' , currentServerName, ' has been changed Succeefully !!' print '' serverTmpCount = serverTmpCount +1 print '***** Log Settings For Domain: ', domainName ,' has been changed Succeefully !! *****' print '' domainTmpCount = domainTmpCount +1
Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh
Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.
Step4). Run the Above WLST Script like following:
java weblogic.WLST domainLogConfigurtionChange.py
Following would be the Output
java weblogic.WLST domainLogConfigurtionChange.py Initializing WebLogic Scripting Tool (WLST) ... Jython scans all the jar files it can find at first startup. Depending on the system, this process may take a few minutes to complete, and WLST may not return a prompt right away. Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Connecting to t3://localhost:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'. 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. ################################################## Changing Log Settings For Domain: Domain_7001 ################################################## Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help(edit) You already have an edit session in progress and hence WLST will continue with your edit session. Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ---------------------------------------------------- Changing Log Setting for serverName: AdminServer ---------------------------------------------------- Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed ===> Log Setting for serverName: AdminServer has been changed Succeefully !! Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ---------------------------------------------------- Changing Log Setting for serverName: MS-1 ---------------------------------------------------- Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=MS-1,Type=Log,Server=MS-1 Attributes changed : FileName Activation completed ===> Log Setting for serverName: MS-1 has been changed Succeefully !! ***** Log Settings For Domain: Domain_7001 has been changed Succeefully !! ***** Connecting to t3://10.65.193.88:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' 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. ################################################## Changing Log Settings For Domain: test_domain ################################################## You already have an edit session in progress and hence WLST will continue with your edit session. Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ---------------------------------------------------- Changing Log Setting for serverName: AdminServer ---------------------------------------------------- Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=AdminServer,Type=Log,Server=AdminServer Attributes changed : RotateLogOnStartup Activation completed ===> Log Setting for serverName: AdminServer has been changed Succeefully !! Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ---------------------------------------------------- Changing Log Setting for serverName: MS-1 ---------------------------------------------------- Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=MS-1,Type=Log,Server=MS-1 Attributes changed : RotateLogOnStartup Activation completed ===> Log Setting for serverName: MS-1 has been changed Succeefully !! ***** Log Settings For Domain: test_domain has been changed Succeefully !! *****
Regards,
Ravish Mody
April 26th, 2011 on 4:26 pm
Hi Ravish,
I have a requirement of logging the value of X-forwarded-for header from the LB to the access logs of weblogic9.2.
Please can you help me how can I achieve it.
Thanks in advance!
-Vinod Sharma
April 26th, 2011 on 4:48 pm
Hi Vinod,
To get the value of X-forwarded-for (i.e. The IP address of the client.) you just have to do the two following things from the console
Console Path:
# First
AdminConsole —> Servers —-> [Your_Server_Name] —> Configuration [Tab] —> General [Sub-Tab] —>
– Click on “Advanced” Link
– Check the CheckBox in this Page “WebLogic Plug-In Enabled”
“WL-Proxy-Client-IP”
#Second
Servers –> [YOUR_SERVER_NAME] —> Logging [Tab] —> HTTP [sub-tab]
– Click on Advanced Link at the bottom of the page
– In the “Extended Logging Format Fields:” Just add the c-ip at the beginning or at the end of the values and save it.
Suppose if you have given c-ip at the beginning then the output in the access.log would be something like this
Example:
10.10.10.10 – – [26/Apr/2011:16:36:14 +0530] “GET /SimpleWebApp/ HTTP/1.1” 200 119
10.10.10.10 – – [26/Apr/2011:16:36:14 +0530] “GET /favicon.ico HTTP/1.1” 404 1214
Where “10.10.10.10” is the client IP.
Regards,
Ravish Mody
April 26th, 2011 on 10:39 pm
Thanks very much Ravish.
Really appreciate your help 🙂
October 1st, 2011 on 12:26 pm
Hi All,
There was a issue in the comment above. Somehow some of the text was missed out. So I am re-commenting the bugs found and the solution script. Ravish, you may discard the comment above and keep this one:
Hi Ravish,
This script is really useful. But I found 3 bugs in this script. Here are the bugs and the fixes:
1) edit() should be used out of while loop. Otherwise it generates the following warning message:
Already in Edit Tree
2)The following Conditional construct is incorrect:
while (serverTmpCount Log Setting for serverName: AdminServer has been changed Succeefull
As of now I am not sure why the serverName variable value is getting changed after doing a cd, but here is the updated version of the script which fixes all these 3 bugs:
#############################################################################
#
# @author Copyright (c) 2010 – 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
propInputStream = FileInputStream(“domain.properties”)
configProps = Properties()
configProps.load(propInputStream)
totalNumbersofDomains=configProps.get(“total.domain.count”)
rotationType=configProps.get(“rotationType”)
numberOfFilesLimited=configProps.get(“numberOfFilesLimited”)
fileMinSize=configProps.get(“fileMinSize”)
rotateLogOnStartup=configProps.get(“rotateLogOnStartup”)
fileCount=configProps.get(“fileCount”)
def str2bool(v):
return v.lower() in (“yes”, “true”, “t”, “1”)
domainTmpCount=1
while (domainTmpCount <= int(totalNumbersofDomains)) :
domainName = configProps.get("domain."+ str(domainTmpCount)+".name")
domainAdminUrl = configProps.get("domain."+ str(domainTmpCount)+".admin.url")
domainAdminUserName = configProps.get("domain."+ str(domainTmpCount)+".admin.username")
domainAdminPassword = configProps.get("domain."+ str(domainTmpCount)+".admin.password")
serverCount = configProps.get("total.domain."+ str(domainTmpCount)+".server.count")
connect(domainAdminUserName, domainAdminPassword, domainAdminUrl)
print '##################################################'
print 'Changing Log Settings For Domain: ', domainName
print '##################################################'
serverTmpCount=1
edit()
while (serverTmpCount Log Setting for serverName: ‘ , cmo.getName(), ‘ has been changed Succeefully !!’
print ”
serverTmpCount = serverTmpCount +1
print ‘***** Log Settings For Domain: ‘, domainName ,’ has been changed Succeefully !! *****’
print ”
domainTmpCount = domainTmpCount +1
I hope it will help everybody!
October 1st, 2011 on 12:32 pm
It seems there is some limitation on the number of characters or something and the comments are not reflecting correctly. I will send a separate email for the same and may be then Ravish or Jay can include that.
Sorry for so many comments!
October 1st, 2011 on 1:54 pm
HI Vishal,
Thank you for pointing & enhancing the faults present in the WLST Script. We will wait for your updated script. at contact@middlewaremagic.com once it tested successfully we will update the script here.
Middleware Magic Team shares 20 Bonus Magic Points for finding bugs in the above WLST Script, which would be definitely helpful for many other subscribers.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
October 3rd, 2011 on 11:22 am
Hi Jay,
I already shared the script yesterday. Also i figured out the root cause for the incorrect server name being picked up by the script above.
Actually you are using a variable called serverName. This is actually a keyword in wlst. So when you were trying to use this variable, it was giving you the value of current server MBean.
So if you change the variable name to something other than serverName like currentServerName, then one of the bug will be resolved.
With regards,
Vishal Mahajan.
October 3rd, 2011 on 12:09 pm
Hi Vishal,
Thank you once again for finding out the root cause of the serverName issue and we have received your updated script, right now we are just doing some testing on it and once everything is fine we would be surely update the above script.
Middleware Magic Team shares 20 Bonus Magic Points for finding the solution of these bugs in the above WLST Script, which would be definitely helpful for many other subscribers.
Regards,
Ravish Mody