Skip to content

sebthom.de

Menu
  • Home
  • About me
  • Imprint
    • Datenschutzerklärung
  • Guestbook
Menu

Logging WebSphere API calls in wsadmin scripts

Posted on Thursday June 12th, 2014Sunday December 25th, 2022 by sebthom

Deployment of enterprise applications and other administrative tasks in WebSphere Application Servers environments can be fully automated using Jython based scripts. Depending on the size of the environment and the level of automation these scripts may become rather big and complex. In case your management has the requirement that certain or all calls to the WebSphere API have be recorded into an audit log – e.g. calls that modify the environment configuration (e.g. installation of EARs, creation/deletion of data sources, etc.) or the runtime state of WebSphere processes (e.g. stop/start/restart of servers, applications, or listeners) – have a look at the following solution.

Save the code listing below into a file called wslogging.py.

from __future__ import nested_scopes

def __wrapMethod(methodToWrap, objectName):
    def __inner(*args):
        # YOUR LOGGING CODE GOES HERE
        print "wsadmin: %s.%s%s" % (objectName, methodToWrap.__name__, args[1:])
        return methodToWrap(*args)
    return __inner

# calls to the listed methods of these admin modules will not be logged
__methodCallsToIgnore = {
    "AdminConfig" : [ "attributes", "defaults", "getid", "list", "listTemplates", "show", "showall", "showdump", "types" ],
    "AdminControl" : [ "queryNames" ]
}

def __logwsadmin(adminClass, adminObjectName):
    # iterate over all features of the given admin class
    for (featureName, featureInstance) in adminClass.__dict__.items():
        # ignore class features that are no methods, e.g. properties
        if not callable(featureInstance): continue
        # ignore internal methods
        if featureName.startswith("_"): continue
        # ignore toString() method
        if featureName == "toString": continue

        # ignore methods from logging blacklist
        if __methodCallsToIgnore.has_key(adminObjectName) and featureName in __methodCallsToIgnore[adminObjectName]: continue

        # replace methods with logging delegates
        adminClass.__dict__[featureName] = __wrapMethod(featureInstance, adminObjectName)

# iterate over all loaded modules and enhance modules whose name starts with Admin
for (varName, varInstance) in locals().items():
    if varName.startswith("Admin"):
         __logwsadmin(varInstance.__class__, varName)

You can now transparently enable logging of calls to WebSphere admin objects in your custom Jython scripts using this launch pattern:

wsadmin.sh -lang jython -profile wslogging.py -f [FILENAME_OF_YOUR_SCRIPT]

Example:



			

Categories

  • Blog (1)
  • IT (21)
    • Development (16)
      • Java (7)
      • Jython (4)
      • Visual Basic (5)
    • Linux (3)
    • WebSphere Application Server (1)
    • WebSphere Portal (2)
    • Windows (1)
  • My Freeware (2)
  • My Music (3)

Recent Posts

  • Logging WebSphere API calls in wsadmin scripts
  • [Solved] Windows 7 “Safely Remove Hardware” pop-up menu horrendously slow
  • Bash: Capturing stderr in a variable while still printing to the console.
  • Configuring EMF Teneo with Hibernate, Commons DBCP, Spring Hibernate Transaction Manager, and the OpenSessionInViewFilter
  • Using EMF ECore model objects with Wicket components
  • Installing Tomcat 6 on Debian Squeeze
  • Leveraging PyDev’s auto-completion for indirectly created objects
  • OVal 1.40 released
  • Installing WebSphere Portal in a local network
  • Comparing version numbers in Jython / Python

Blogroll

  • E L S U A
  • elektrofever.de
  • OVal
  • Sweettt.com
  • Twins’ Running Blog

Recent Comments

  • Annibale on Visual Basic – Multiple Undos Class v2.04
  • Annibale on Visual Basic – Multiple Undos Class v2.04
  • koliko2k3 on Guestbook
  • hdkid on MyPad v1.1.6 – a PHP Editor
  • Luis Diego Villarreal on Excel – VBA Timer Example v1.0.1

Archives

  • June 2014
  • May 2012
  • January 2011
  • October 2010
  • September 2010
  • March 2010
  • February 2010
  • September 2009
  • July 2009
  • March 2009
  • February 2009
  • November 2008
  • September 2008
  • May 2008
  • September 2007
  • July 2007
  • July 2004
  • March 2003
  • August 2002
  • April 2002
  • January 2002
  • Deutsch (de)Deutsch
  • English (en)English
© 2025 sebthom.de | Powered by Minimalist Blog WordPress Theme