Partager via


WMI and Host Integration Server…

Internally and externally we get customer inquiries wanting to know how to get configuration and status information from Host Integration Server without using the manager interface.

Well, this is fairly simple, but complicated if you are not familiar with using WMI. Most users are familiar with using snacfg.exe, which is documented fairly well. However, for many things, WMI is your friend.

Now, to be honest, I cheat. When we first added in WMI into the product, I was totally unfamiliar with it. I started playing, using wbemtest (which comes with the operating system), and looking at samples. Then, I discovered WMI Code Creator. This is a great tool for ‘simple’ things, and what I really like is it will create, besides VBScript code, C# and VB.NET code. Using this tool gave me a greater understanding in how to create queries to gather information I needed (in conjunction with using wbemtest).

So, one question that came across our internal alias recently was “I'm wondering if SNACFG.EXE is able to display all LUs assigned for each pool.” Well, yes, but not cleanly, and what if you needed a bit more information, like is the LU actually being used, etc?

Here is where WMI comes in handy.

Using WMI, the below query will display every LU in a pool:

    1: OPTION EXPLICIT
    2: Dim strDomainComputer, strPoolTargeted
    3: Dim WmiLocator, WmiNameSpace
    4: Dim objLuInThisPool
    5: Dim xLuInPool
    6: Dim objPool, xPool
    7:  
    8: Set WmiLocator = CreateObject("WbemScripting.SWbemLocator")
    9: strDomainComputer = "."
   10:  
   11: BigLoop()
   12:  
   13: Private Sub DoPool()
   14:        Wscript.Echo "Checking POOL " & xPool.Name
   15:        strPoolTargeted   = xPool.Name
   16:        Set objLuInThisPool = WmiNameSpace.ExecQuery("Select Name from MSSna_LuDisplay where PoolName='" & strPoolTargeted & "'")
   17:        if objLuInThisPool.Count > 0 then
   18:               for each xLuInPool in objLuInThisPool
   19:                      wscript.echo "     " & xLuInPool.Name
   20:               next
   21:        end if
   22:        Wscript.Echo "Total LU count for the pool " & strPoolTargeted & " is " & objLuInThisPool.Count
   23:        Wscript.Echo “”
   24: End Sub
   25:  
   26: Private Sub BigLoop()
   27:        Set WmiNameSpace = WmiLocator.ConnectServer(strDomainComputer,"root\MicrosoftHIS")
   28:        Set objPool = WmiNameSpace.ExecQuery("Select Name from MsSna_PoolDisplay")
   29:        For Each xPool In objPool
   30:               DoPool()
   31:        next
   32: End Sub

What this code does is 1st makes a query to get each pool defined on the machine, then makes a query based on the pool name to get the LUs using that pool.

But say you need a bit more? As in wanting to find out what sessions were actually in use?

Well, that can be done fairly easily as follows:

    1: rem - this will dump out all InSession or SSCP 3270 LUs
    2: rem - Also, the script will display as follows
    3: rem - Connection name 
    4: rem - 3270 LU name
    5: rem - Status the LU is in at the time (either SSCP or InSession)
    6: rem - User Account accessing the LU
    8: strComputer = "." 
    9: quote = chr(34)
    7:  
   10: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftHIS") 
   11: Set colItems = objWMIService.ExecQuery( "SELECT * FROM MsSnaStatus_Lu3270 WHERE StatusText = 'SSCP' OR StatusText = 'InSession'",,48) 
   12: Wscript.Echo "---------------------------------------------------------------------------------------------------------"
   13: For Each objItem in colItems
   14:       Messagestr = "ConnectionName: " & objItem.ConnectionName & vbtab 
   15:       Messagestr = Messagestr & "Name: " & objItem.Name & vbtab 
   16:       Messagestr = Messagestr & "StatusText: " & objItem.StatusText & vbtab
   17:     rem map the 'active' 3270 LU to the user account accessing it
   18:     qrystring = "references of {MsSnaStatus_Lu3270.Name=" & quote & objItem.Name & quote & "}"
   19:     set colitems1 = objWMIService.ExecQuery( qrystring,,48) 
   20:       For Each objItem1 in colitems1 
   21:       rem - strip out MsSnaStatus_ClientConnection.Name= from the item....
   22:             Messagestr = Messagestr & "User" & Mid (objItem1.PathToUser,34)
   23:       Next
   24:       Wscript.Echo Messagestr
   25: Wscript.Echo "---------------------------------------------------------------------------------------------------------"
   26: Next
   27: WScript.Echo ""

The output from this script would be similar to this:

    1: ---------------------------------------------------------------------------------------------------------
    2: ConnectionName: D3270   Name: D3270002  StatusText: SSCP        User: W2KS2/ Administrator"
    3: ConnectionName: D3270   Name: D3270003  StatusText: InSession   User: W2KS2/ Bob"
    4: ConnectionName: D3270   Name: D3270004  StatusText: SSCP        User: W2KS2/ Jane"
    5: ConnectionName: D3270   Name: D3270005  StatusText: SSCP        User: W2KS2/ Ted"
    6: ConnectionName: D3270   Name: D3270005  StatusText: InSession   User: W2KS2/ Alice"
    7: ---------------------------------------------------------------------------------------------------------

Please note this last query only queries against the local Host Integration Server. If you have multiple servers, things can be more complicated, as status information has to be queried against each Host Integration Server in the ‘HIS sub domain’.

I hope this is helpful to many of you out there. WMI can be most helpful when gathering information that is not as easily available in the manager interface.

Comments

  • Anonymous
    August 04, 2009
    Hi Charles,I have an doubt on WMI class property values.The WMI class MsSnaStatus_Connection has two propertiesStatus andStatusText Q1. Why the data type of StatusText is string even it is having numeric value as 0,1,2,3,4 and 5. What value this class will display for StatusText (0 to 5 or description value in string)Q2. What is the purpose of having Status field when we already have StatusText field. And how Status field is related with StatusText field.Please provide your valuable input asap.Regards,Vijay

  • Anonymous
    August 12, 2009
    Vijay,Sorry for the delay, just saw that you had left a comment.Take a look at the wmisnastatus.moffile in the %snaroot% directory.Status is defined as:

    [read, values {"", "Inactive", "Pending", "Stopping", "Active" }, Description("The current status of the connection--Inactive, Pending, Stopping, or Active.") ]uint32 Status;
    while StatusText is defined as:
    [read, values {"", "Inactive", "Pending", "Stopping", "Active",                  "Incoming", "OnDemand", "OnDemandIncoming"}, Description("One of the status values.") ] string StatusText;              // one of the Status values
    While they appear similar, there is a difference, as StatusText will indicate if this is an OnDemand Connection or not.Granted, there is some inconsistency here, but internally there is a bit of a difference in what is returned for each. To be honest, I've not used the connection status that often, other than to display the StatusText value that is returned when testing. For example:MsSnaStatus_Connection instanceInactiveState: 2Name: PRINTStatus: 1StatusText: OnDemandMsSnaStatus_Connection instanceInactiveState: 0Name: 3270DStatus: 4StatusText: ActiveOn the 1st (Print), looking at the MOF, the inactivestate = 2 matches with "OnDemand". The status (1) matches "Inactive", which is true, and the StatusText value indicates again "OnDemand".For the 2nd (3270D)Inactive = 0, which can really be ignored since the connection is actually active (this might be a bug, not sure). Status = 4, which is "Active" and matches the StatusText. It is possible for the connection to have a Status of 4 and a StatusText of "incoming', depending on timing of the query. Personally, I would use Status or StatusText alone, not both.Not sure if this helps, but hopefully.Charles