Find WebLogic MBeans with Ease
There was an old woman who lived in a shoe
She had so many MBeans she didn’t know what to do
– With apologies to Mother Goose
It’s hard to deny that MBeans are incredibly useful for accessing configuration and runtime data. But with so many MBeans in an application server, it’s also incredibly hard to find the needle in the haystack.
Whether you’re looking for an MBean type, a particular attribute, or the bean that goes along with a known value (domain name, for example), how do you quickly find it? I’ve already posted one trick I use for finding MBeans via the audit log. In this post, I’ll show you my bestest trick of all for finding WebLogic MBeans. I’d like to fancy myself as an Evil Genius(TM) but it’s actually quite obvious. Here we go…
The weblogic.Admin utility has several commands such as GET and QUERY. You can find MBeans by type, name, or name pattern which is useful if you already have an idea of what you want. The following command uses weblogic.Admin to print all MBeans and their attributes to the command console:
java weblogic.Admin -username weblogic -password weblogic -url t3://localhost:80 query -pretty -pattern *:*
Substitute your username, password, and URL and you’ll get a ton of output. Here’s a representative snippet:
MBeanName: "Security:Name=myrealmDefaultAuthenticator" ControlFlag: REQUIRED Description: WebLogic Authentication Provider EnableGroupMembershipLookupHierarchyCaching: false GroupHierarchyCacheTTL: 60 GroupMembershipSearching: unlimited MaxGroupHierarchiesInCache: 100 MaxGroupMembershipSearchLevel: 0 MinimumPasswordLength: 8 ProviderClassName: weblogic.security.providers. \ authentication.DefaultAuthenticationProviderImpl Realm: Security:Name=myrealm SupportedExportConstraints: users|groups SupportedExportFormats: DefaultAtn SupportedImportConstraints: SupportedImportFormats: DefaultAtn UseRetrievedUserNameAsPrincipal: false Version: 1.0
By the way, if you’ve never used weblogic.Admin before, you must first run the setEnv (or setDomainEnv) script in your domain directory to set up environment variables and paths.
Now, that output is all well and good but it might not make finding things any easier. Time for a little redirection, my friend:
java weblogic.Admin -username weblogic -password weblogic -url t3://localhost:80 query -pretty -pattern *:* > MBeans.txt
This time, the output goes into the MBeans.txt file. You can use this file to do automated searches. When you search, you’ll get MBean names, attribute names, and attribute values. Wanna search with RegEx? More power to you! <evil-genius>Muuwhaahaaaahaaa!</evil-genius>
Anyway, like I said, it’s fairly obvious but very useful. Mother Goose’s old woman would be proud of how we spanked those MBeans soundly and sent them to bed.
Epilogue
weblogic.Admin was deprecated in WebLogic 9. It’s still there and works, but it’s being phased out in favor of WLST. I don’t know of a quick way to use WLST to dump MBeans to a file. However, WLST is clearly powerful enough to write a script that does it. I haven’t pursued a solution in WLST because I cheat and use the deprecated weblogic.Admin to dump MBeans to a file. Please don’t tell…
If anyone knows how to use WLST to the same effect, please post a comment and share the solution with everyone. Thanks!
Using WLST: The code below will walk the entire tree, and you can then print out or save to a file all the MBeans names and the attributes for each MBean.
The cmo object will give you the type of the MBean, and you can use getMBeanInfo() for more data to write it out.
Alternatively you could use the poor mans version of the script and just type
find('')def walkTree(currentDir) :
cd (currentDir)
# currentAttributes = ls(currentDir, returnMap='true', returnType='a')
# print "There are [%d] attributes in the directory" % len(currentAttributes)
childDirs = ls(currentDir, returnMap='true', returnType='c')
print "Found [%d]" % len(childDirs)
if len(childDirs) < = 0 :
return
for child in childDirs :
childDirectory = currentDir + '/' + child
walkTree(childDirectory)
connect('qualityuser','qualityuser','t3://localhost:7301')
walkTree('/')
Comment by Andre Glauser — April 3, 2007 @ 5:37 pm
Thanks for the tips, Andre.
I need to study the script some more but the poor man’s version seems to do the trick. Very slowly, though.
Comment by Mike Fleming — April 4, 2007 @ 7:16 pm