czwartek, 8 grudnia 2016

Script Inventorying Web Application Transaction Monitors' settings

    With the extensive usage of Web Application Transaction Monitors you might face a challenge of inventorying settings in order to keep them in one clear file in human readable format. I tried to approach the problem with both Operations Manager Shell and T-SQL query on the operations Manager DB, but seems like none of the information I was interested in was available in there. Therefore I came up with an idea of parsing .xml file created by export of Management Pack containing the Web Application Transaction Monitor objects. The script collects the following settings from the .xml file:

Name - containing the name of the Web Application Transaction Monitor displayed in SCOM
GUID - containing the GUID of the Web Application Transaction Monitor object
AuthenticationScheme - containing information about the way Watcher Nodes authenticate against the URL (eg. None, NTLM, Negotiate and so on)
WatcherNodesList - containing the list of FQDNs of watcher nodes (each watcher node has it's own entry under this parent property)
URLsList - containing the list of FQDNs of monitored URLs (each URL has it's own entry under this parent property)

    This data is published in the output .xml file. It looks as follows:


Web Application Transaction Monitor .xml parser output


Usage:
   
    Save the code below into the .ps1 file. You have to provide the location of the Management Pack file exported in .xml format in this line:
$MPXMLLocation = "C:\Temp\xxx.xml"
     You also need to provide the file name and the location of the output file here:
 $OutputXMLLocation = "C:\Temp\xxxReport.xml"
    Additional field to modify in the script is the one below, where you need to provide the search expresssion, if you would like to scope the report only to the applications matching it:
$ApplicationNames = $QoSMP.ManagementPack.Monitoring.Discoveries.Discovery | ?{$_.DataSource.DisplayName -match "*XXXXX*"}
    Otherwise you can modify the line to the following one:
$ApplicationNames = $QoSMP.ManagementPack.Monitoring.Discoveries.Discovery | ?{$_.DataSource.DisplayName -match "*"}


Additional Notes:
    The script can be easily modified in order to add any other properties that are of one's interest. It would require the addition of more lines in the section including Add-Member cmdlets

Code:
$MPXMLLocation = "C:\Temp\xxx.xml"
$OutputXMLLocation = "C:\Temp\xxxReport.xml"


[xml]$QoSMP = Get-Content $MPXMLLocation
$WebApplications = @()

$ApplicationNames = $QoSMP.ManagementPack.Monitoring.Discoveries.Discovery | ?{$_.DataSource.DisplayName -match "*XXXXX*"}

foreach ($ApplicationName in $ApplicationNames) {
    $object = New-Object -TypeName PSObject
    $Object | Add-Member -Name "Name" -MemberType Noteproperty -Value $ApplicationName.DataSource.DisplayName
    $Object | Add-Member -Name "GUID" -MemberType Noteproperty -Value $ApplicationName.ID.Substring(0,$ApplicationName.ID.IndexOf("."))
    $Object | Add-Member -Name "AuthenticationScheme" -MemberType Noteproperty -Value ""
    $Object | Add-Member -Name "WatcherNodesList" -MemberType Noteproperty -Value ($ApplicationName.DataSource.WatcherComputersList -replace '[()]','' -split "\|")
    $Object | Add-Member -Name "URLsList" -MemberType Noteproperty -Value ""
    $WebApplications += $object
}

foreach ($DataSourceModuleType in $QoSMP.ManagementPack.TypeDefinitions.ModuleTypes.DataSourceModuleType){
    foreach ($Application in $WebApplications){
        IF ($Application.GUID -match $DataSourceModuleType.ID.Substring(0,$DataSourceModuleType.ID.IndexOf("."))){
            $Application.AuthenticationScheme = $DataSourceModuleType.ModuleImplementation.Composite.MemberModules.ProbeAction.AuthenticationScheme
            foreach ($Request in $DataSourceModuleType.ModuleImplementation.Composite.MemberModules.ProbeAction.Requests.Request){
            $Application.URLsList += $Request.URL + "|"
        }
            $Application.URLsList = $Application.URLsList.SubString(0,$Application.URLsList.Length-1)
            $Application.URLsList = $Application.URLsList -split "\|"
        }
    }
}

($WebApplications | ConvertTo-XML -NoTypeInformation).Save($OutputXMLLocation)

Brak komentarzy:

Prześlij komentarz