Search code examples
pythonwebspherejython

IBM WebSphere Application Server wsadmin returning only first result out of 6 in script


When attempting to get the status of applicaitons in WebSphere Application Server, I expect there to be multiple returned mbeans. However, WAS is only returning the first result and discarding the rest of them it seems.

[wasadmin@servername01 ~]$ Run_wsadmin.sh -f wsadmin_Check_App_Status.py
WASX7209I: Connected to process "dmgr" on node PRDDMGR using SOAP connector;  The type of process is: DeploymentManager
WASX7026W: String "type=Application,name=AMTApp,*" corresponds to 6 different MBeans; returning first one.

The script I'm running looks like this:

app_name = AppName
app_status = AdminControl.completeObjectName('type=Application,name=' + app_name + ',*').split('\n')

for status in app_status :
  print( status )
# end of For status in app_status

Is there some setting in WebSphere, or do I need to import some special library into my script?


Solution

  • According to the doc of AdminControl.completeObjectName()

    Use the completeObjectName command to create a string representation of a complete ObjectName value that is based on a fragment. This command does not communicate with the server to find a matching ObjectName value. If the system finds several MBeans that match the fragment, the command returns the first one.

    So that function is behaving as expected.

    Instead:
    In this situation, it sounds like you want to use AdminControl.queryNames(), which is built for returning a list of results that match your query.

    For example:

    app_name = AppName
    app_status = AdminControl.queryNames('type=Application,name=' + app_name + ',*').split('\n')
    
    for status in app_status :
      print( status )
    

    Source: Commands for the AdminControl object using wsadmin scripting