     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Blog" href="https://sebthom.de/de/category/blog/feed/" />
     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Jython" href="https://sebthom.de/de/category/it/development/jython/feed/" />
     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: WebSphere Application Server" href="https://sebthom.de/de/category/it/websphere_application_server/feed/" />
{"id":157,"date":"2014-06-12T22:37:56","date_gmt":"2014-06-12T21:37:56","guid":{"rendered":"http:\/\/sebthom.de\/?p=157"},"modified":"2022-12-25T22:38:28","modified_gmt":"2022-12-25T21:38:28","slug":"logging-wsadmin-calls","status":"publish","type":"post","link":"https:\/\/sebthom.de\/de\/157-logging-wsadmin-calls\/","title":{"rendered":"Logging WebSphere API calls in wsadmin scripts"},"content":{"rendered":"<p>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 &#8211; 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) &#8211; have a look at the following solution. <\/p>\n<p>Save the code listing below into a file called <strong>wslogging.py<\/strong>.<\/p>\n<pre name=\"code\" class=\"python\">\r\nfrom __future__ import nested_scopes\r\n\r\ndef __wrapMethod(methodToWrap, objectName):\r\n    def __inner(*args):\r\n        # YOUR LOGGING CODE GOES HERE\r\n        print \"wsadmin: %s.%s%s\" % (objectName, methodToWrap.__name__, args[1:])\r\n        return methodToWrap(*args)\r\n    return __inner\r\n\r\n# calls to the listed methods of these admin modules will not be logged\r\n__methodCallsToIgnore = {\r\n    \"AdminConfig\" : [ \"attributes\", \"defaults\", \"getid\", \"list\", \"listTemplates\", \"show\", \"showall\", \"showdump\", \"types\" ],\r\n    \"AdminControl\" : [ \"queryNames\" ]\r\n}\r\n\r\ndef __logwsadmin(adminClass, adminObjectName):\r\n    # iterate over all features of the given admin class\r\n    for (featureName, featureInstance) in adminClass.__dict__.items():\r\n        # ignore class features that are no methods, e.g. properties\r\n        if not callable(featureInstance): continue\r\n        # ignore internal methods\r\n        if featureName.startswith(\"_\"): continue\r\n        # ignore toString() method\r\n        if featureName == \"toString\": continue\r\n\r\n        # ignore methods from logging blacklist\r\n        if __methodCallsToIgnore.has_key(adminObjectName) and featureName in __methodCallsToIgnore[adminObjectName]: continue\r\n\r\n        # replace methods with logging delegates\r\n        adminClass.__dict__[featureName] = __wrapMethod(featureInstance, adminObjectName)\r\n\r\n# iterate over all loaded modules and enhance modules whose name starts with Admin\r\nfor (varName, varInstance) in locals().items():\r\n    if varName.startswith(\"Admin\"):\r\n         __logwsadmin(varInstance.__class__, varName)\r\n<\/pre>\n<p>You can now transparently enable logging of calls to WebSphere admin objects in your custom Jython scripts using this launch pattern:<\/p>\n<pre>\r\nwsadmin.sh -lang jython -profile wslogging.py -f [FILENAME_OF_YOUR_SCRIPT]\r\n<\/pre>\n<p><b>Example:<\/b><\/p>\n<pre name=\"code\" class=\"python\">\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,63,98],"tags":[],"class_list":["post-157","post","type-post","status-publish","format-standard","hentry","category-blog","category-jython","category-websphere_application_server"],"_links":{"self":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":0,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"wp:attachment":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}