Forefront UAG trunks, applications, and repositories discovery

Microsoft.Forefront.UAG.TrunksDiscovery (Discovery)

A Forefront UAG trunk groups Forefront UAG applications for publishing with Forefront UAG repositories for authentication.
Discovery of Forefront UAG trunks, applications, and repositories happens only if the machine is discovered as a Forefront UAG server. For each configured trunk, application, and repository, an appropriate class is discovered. Information is extracted from the Forefront UAG COM objects.

Knowledge Base article:

Summary

A Forefront UAG trunk groups Forefront UAG applications for publishing with Forefront UAG repositories for authentication. A Forefront UAG application is accessible to clients via Forefront UAG trunks. A Forefront UAG repository holds information used to authenticate users accessing Forefront UAG portals.

Configuration

Discovery of Forefront UAG trunks, applications and repositories happens only if the machine is discovered as a Forefront UAG server. The information is gathered from the SessionMgrComLayer service.

Element properties:

TargetMicrosoft.Forefront.UAG.Server
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Source Code:

<Discovery ID="Microsoft.Forefront.UAG.TrunksDiscovery" Enabled="true" Target="Microsoft.Forefront.UAG.Server" ConfirmDelivery="false" Remotable="false" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Array">
<Property PropertyID="ID"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Server"/>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Trunk">
<Property PropertyID="ID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Application">
<Property PropertyID="ID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Application.BuiltIn">
<Property PropertyID="ServiceName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Forefront.UAG.Repository">
<Property PropertyID="ID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryRelationship TypeID="Microsoft.Forefront.UAG.ArrayContainsServer"/>
<DiscoveryRelationship TypeID="Microsoft.Forefront.UAG.ServerHostsTrunk"/>
<DiscoveryRelationship TypeID="Microsoft.Forefront.UAG.TrunkHostsApplication"/>
<DiscoveryRelationship TypeID="Microsoft.Forefront.UAG.TrunkHostsRepository"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.Forefront.UAG.TrunksDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Host/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>
'Option Explicit

'Copyright (c) Microsoft Corporation. All rights reserved.
'*************************************************************************
' $ScriptName: "Common" $
'
' Purpose: To have one place for common stuff across various TMG VBScripts
'
' $File: Common.vbs $
'*************************************************************************

'===============
' Global variables
'===============
Dim sUtilObj
Dim sErrObj
Dim sBlnTraceRefreshed

Const conForWriting = 2
Const conForAppending = 8
Const conTraceOn = "TRACEON"

sBlnTraceRefreshed = False

'##########################################################################
' Class: Error
' Description: Contains methods to Save Error details, Raise Error,
' Clear Error
' Assumptions: Util Object is created and available to use. It should be named
' as "sUtilObj"
'##########################################################################
Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Private ERROR_FILE_NOT_FOUND

Public Sub Class_Initiaze()
ERROR_FILE_NOT_FOUND = 2
End Sub

Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property

Public Sub PrintError
WScript.Echo "Error writing to trace." &amp; _
"Error: Number-" &amp; Err.number &amp; _
"; Description-" &amp; Err.Description &amp; _
"; Source-" &amp; Err.Source
End Sub
'=============
' Method: GenerateMOMErrorEvent
' Description: Uses the "MOM Script API" object to log a script event. Appends the Error
' details to the message sent as parameter
' Parameters: strMessage - contains the custom text to write to the event
'=============
Public Function GenerateMOMErrorEvent(ByVal strMessage)
strMessage = strMessage &amp; " Error - Number:" &amp; m_lNumber &amp; _
" Source:" &amp; m_sSource &amp; _
" Description:" &amp; m_sDescription &amp; _
" HelpContext:" &amp; m_sHelpContext &amp; _
" HelpFile:" &amp; m_sHelpFile
On Error Resume Next
CreateScriptErrorEvent(strMessage)
sUtilObj.ThrowEmptyDiscoveryData
Quit()
End Function

'=============
' Method: CreateScriptErrorEvent
' Description: Generate a MOM event with script error message in the
' Operations Manager Log.
' Parameters: strMessage - Message to write to the event
'=============
Public Function CreateScriptErrorEvent(ByVal strMessage)
On Error Resume Next
sUtilObj.MOMApiObject.LogScriptEvent WScript.ScriptName, 4001, 1, strMessage
End Function

'=============
' Method: ErrorCheck
' Description: Checks if an error occurred and writes the error to Operations Manager
' event log.
'=============
Public Sub ErrorCheck()
If Err.number &lt;&gt; 0 Then
Save
GenerateMOMErrorEvent("")
End If
End Sub

Public Sub ErrorCheckMsg(ByVal msg)
If Err.number &lt;&gt; 0 Then
Save
GenerateMOMErrorEvent(msg)
End If
End Sub
End Class

'##########################################################################
' Class: Util
' Description: Contains methods for tracing, generating events,
' creating objects
'##########################################################################
Class Util

' Used to say to LogMessage when/how to print the message.
Public DBG_NONE
Public DBG_ERROR
Public DBG_WARNING
Public DBG_TRACE
Public HKEY_LOCAL_MACHINE
Public MOMApiObject
'Internal Debug Level
Private m_nDebugLevel
'Name of the logfile for tracing
Private m_logFileName
'Values used for creating discovery objects
Private m_SourceId
Private m_ManagedEntityId
Private m_TargetComputer

'---------------
' Properties
'---------------
Public Property Get LogFileName
LogFileName = m_logFileName
End Property

Public Property Let LogFileName(ByVal fileName)
If Not (IsEmpty(filename) OR IsNull(fileName)) Then
m_logFileName = fileName
Else
sErrObj.GenerateMOMErrorEvent("Log file name cannot be empty or null")
End If
End Property

Public Property Get SourceId
SourceId = m_SourceId
End Property

Public Property Let SourceId(ByVal sourceIdVal)
If Not (IsEmpty(sourceIdVal) OR IsNull(sourceIdVal)) Then
m_SourceId = sourceIdVal
Else
sErrObj.GenerateMOMErrorEvent("SourceID cannot be empty or null")
End If
End Property

Public Property Get ManagedEntityId
ManagedEntityId = m_ManagedEntityId
End Property

Public Property Let ManagedEntityId(ByVal managedEntityIdVal)
If Not (IsEmpty(managedEntityIdVal) OR IsNull(managedEntityIdVal)) Then
m_ManagedEntityId = managedEntityIdVal
Else
sErrObj.GenerateMOMErrorEvent("ManagedEntityID cannot be empty or null")
End If
End Property

Public Property Get TargetComputer
TargetComputer = m_TargetComputer
End Property

Public Property Let TargetComputer(ByVal targetComputerVal)
If Not (IsEmpty(targetComputerVal) OR IsNull(targetComputerVal)) Then
m_TargetComputer = targetComputerVal
Else
sErrObj.GenerateMOMErrorEvent("TargetComputer cannot be empty or null")
End If
End Property

'---------------
' Methods
'---------------
'=============
' Method: Class_Initialize
' Description: This is the constructor
'=============
Private Sub Class_Initialize()
' Initialize Debug level constants

DBG_TRACE = 1
DBG_WARNING = 2
DBG_ERROR = 3
DBG_NONE = 4

'by default only errors are logged
m_nDebugLevel = DBG_ERROR
'Create a MOM Script API object
'Set MOMApiObject = MomCreateObject("MOM.ScriptAPI")
End Sub

'=============
' Method: Class_Terminate
' Description: This is the destructor
'=============
Private Sub Class_Terminate()
Set MOMApiObject = Nothing
End Sub

'=============
' Method: SetDebugLevel
' Description: To change the debugging output level of information
' generated by this utility.
' Parameters: nLevel - Level, either DBG_NONE, DBG_TRACE,
' DBG_WARNING or DBG_ERROR
'=============
Public Sub SetDebugLevel(ByVal nLevel)
m_nDebugLevel = nLevel
End Sub

'=============
' Method: WriteToTrace
' Description: Writes text to a trace file. For every run of the script,
' the trace file is recreated.
' Parameters: msg - Any text that needs to be written to the trace file.
'=============
Public Sub WriteToTrace (ByVal msg)
Dim fso, traceFileObj, objErr

Set objErr = new Error

If Not m_nDebugLevel = DBG_TRACE Then
Exit Sub
End If

On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0

'Checking whether the trace file is recreated in this run
If Not sBlnTraceRefreshed Then
On Error Resume Next
Set traceFileObj = fso.OpenTextFile(sUtilObj.LogFileName, conForWriting, True)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0
sBlnTraceRefreshed = True
Else
On Error Resume Next
Set traceFileObj = fso.OpenTextFile(sUtilObj.LogFileName, conForAppending, True)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0
End If

msg = FormatDateTime(Date(), vbShortDate) &amp; " " &amp; _
FormatDateTime(Time(), vbLongTime) &amp; "[" &amp; _
WScript.ScriptName &amp; "]--&gt; " &amp; msg
On Error Resume Next
traceFileObj.WriteLine(msg)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0

traceFileObj.Close
Set traceFileObj = Nothing
Set fso = Nothing

End Sub

'=============
' Method: MomCreateObject
' Description: Creates an Object and includes neccessary error handling
' Parameters: sProgramId - The Program ID of the object type to be created.
' Returns: Returns the object that is created.
'=============
Public Function MomCreateObject(ByVal sProgramId)
Dim errMsg
On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)

If Err.number &lt;&gt; 0 Then
errMsg = "Unable to create automation object '" &amp; sProgramID &amp; "'" &amp; "--" &amp; _
"Error- Number: " &amp; Err.number &amp; " Description:" &amp; Err.Description &amp; _
" Source:" &amp; Err.Source
If lcase(sProgramId) = lcase("MOM.ScriptAPI") Then
CreateOpsMgrEvent 312, WScript.ScriptName, "ERROR", errMsg
ThrowEmptyDiscoveryData()
Quit()
Else
sErrObj.GenerateMOMErrorEvent(errMsg)
End If
End If
End Function

'=============
' Method: CreateOpsMgrEvent
' Description: Create an event in the Operations Manager log
' Parameters: eventId - ID of the event to be created
' source - Source of this event
' eventType - String specifying the type of event (ERROR, INFORMATION, SUCCESS, WARNING)
' desc - Description of event.
' Returns: Returns the object that is created.
'=============
Public Sub CreateOpsMgrEvent(ByVal eventId, ByVal source, ByVal eventType, ByVal desc)
Dim strCommand, WshShell

On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "cmd /c eventcreate /ID " &amp; eventID &amp; _
" /SO " &amp; """" &amp; source &amp; """" &amp; _
" /T " &amp; """" &amp; eventType &amp; """" &amp; _
" /D " &amp; """" &amp; desc &amp; """" &amp; _
" /L " &amp; """Operations Manager"""
WshShell.Run strCommand

If Err.number &lt;&gt; 0 Then WScript.Echo "Error in 'Util.CreateOpsMgrEvent()'"
End Sub

'=============
' Method: ThrowEmptyDiscoveryData
' Description: Returns an empty discovery data
'=============
Public Sub ThrowEmptyDiscoveryData()
Dim oAPI, oDiscoveryData, errMsg

On Error Resume Next

Set oAPI = MOMApiObject
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, m_ManagedEntityId)

If Err.number &lt;&gt; 0 Then
errMsg = "Error while creating Empty Discovery Data." &amp; " Error Number:" &amp; _
Err.number &amp; " Description:" &amp; Err.Description &amp; " Source" &amp; Err.Source
sErrObj.CreateScriptErrorEvent(errMsg)
Quit()
End If

Call oAPI.Return(oDiscoveryData)

If Err.number &lt;&gt; 0 Then
errMsg = "Error while creating Empty Discovery Data." &amp; " Error Number:" &amp; _
Err.number &amp; " Description:" &amp; Err.Description &amp; " Source" &amp; Err.Source
sErrObj.CreateScriptErrorEvent(errMsg)
Quit()
End If

End Sub

End Class


'Copyright (c) Microsoft Corporation. All rights reserved.
'*************************************************************************
' $ScriptName: "AppCompDiscMain.vbs" $
'
' Purpose: Performs TMG Application Component Discoveries
'
' $File: AppCompDiscMain.vbs $
'*************************************************************************

' Include - Common.vbs, ISAAppCompDisc.vbs
' Arg(0) - Source ID
' Arg(1) - Target ID
' Arg(2) - Computer ID
' Arg(3) - ScriptFileName - The name with which script file should be created
' in the MOM Installation temp folder
' Arg(4) - Trace flag

Sub Main()

''''''''''''''''''''''''''''''''''''''''''''''''''''

'TMG's array name
'Instantiate the global objects declared in the Common.vbs
Set sUtilObj = new Util
Set sErrObj = new Error

Dim objFPCRoot, arrName
Set objFPCRoot = sUtilObj.MomCreateObject("FPC.Root")

Set arrName = objFPCRoot.GetContainingArray()

Set sUtilObj = Nothing
Set sErrObj = Nothing
''''''''''''

SetLocale("en-us")

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 3 Then
Wscript.Quit -1
End If

Dim SourceID, ManagedEntityId, TargetComputer

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)


Dim oAPI, oDiscoveryData, oUAGInst, oArrayInst, oRelArrServInst
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

Dim sessionMgr
set sessionMgr = CreateObject("SessionMgrComLayer.SessionMgr")
Dim userMgr

if TypeName(sessionMgr) = "Nothing" then
Wscript.Quit -1
else
on error resume next

set oUAGInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Forefront.UAG.Server']$")
call oUAGInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oUAGInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "UAG server " + TargetComputer)
call oUAGInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Server']/ArrayID$", arrName)

call oDiscoveryData.AddInstance(oUAGInst)

' add to array
set oArrayInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Forefront.UAG.Array']$")
call oArrayInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Array']/ID$", arrName)
call oArrayInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "UAG array " + arrName)
call oDiscoveryData.AddInstance(oArrayInst)

Set oRelArrServInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Forefront.UAG.ArrayContainsServer']$")
oRelArrServInst.Source = oArrayInst
oRelArrServInst.Target = oUAGInst
Call oDiscoveryData.AddInstance(oRelArrServInst)


' Discover the trunks
Dim rawTrunkList, oTrunkInst, oRelInst
Dim oAppInst, rawRepList, oRepInst
Dim oRelInst2, oRelInst3

set rawTrunkList = sessionMgr.GetSites()
if err &lt;&gt; 0 then
Wscript.Quit -1
else
Dim trunk
For each trunk in rawTrunkList.SiteVec
set oTrunkInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Forefront.UAG.Trunk']$")
call oTrunkInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oTrunkInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Trunk']/ID$", trunk.Name)
call oTrunkInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", trunk.Name)
call oDiscoveryData.AddInstance(oTrunkInst)

' Create a relationship between the UAG and the trunk.
Set oRelInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Forefront.UAG.ServerHostsTrunk']$")
oRelInst.Source = oUAGInst
oRelInst.Target = oTrunkInst
Call oDiscoveryData.AddInstance(oRelInst)

' Discover the apps of the trunk
Dim info
set info = CreateObject("SessionMgrComLayer.ResourceInfoId")
info.Site = trunk.Name
info.Secure = trunk.Secure
info.ResourceId = ""

on error resume next
Dim rawAppList
set rawAppList = sessionMgr.GetResourceInfoVec(info)
if err &lt;&gt; 0 then
Wscript.Quit -1
else
Dim app
For each app in rawAppList.ResourceInfoVec
if app.TypeName &lt;&gt; "Portal" and app.TypeName &lt;&gt; "InternalSite" then
Dim className
if app.TypeName = "FileAccess" then
className = "$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']$"
set oAppInst = oDiscoveryData.CreateClassInstance(className)
call oAppInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']/ServiceName$", "ShareAccess")
elseif app.TypeName = "TerminalServicesGateway" then
className = "$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']$"
set oAppInst = oDiscoveryData.CreateClassInstance(className)
call oAppInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']/ServiceName$", "TSGateway")
elseif app.TypeName = "RemoteNetworkAccess" then
className = "$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']$"
set oAppInst = oDiscoveryData.CreateClassInstance(className)
call oAppInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Application.BuiltIn']/ServiceName$", "RemoteAccess")
else
className = "$MPElement[Name='Microsoft.Forefront.UAG.Application.External']$"
set oAppInst = oDiscoveryData.CreateClassInstance(className)
end if

call oAppInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oAppInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Application']/ID$", app.Name)
call oAppInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Trunk']/ID$", trunk.Name)
call oAppInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", app.Name)
call oDiscoveryData.AddInstance(oAppInst)

' Create a relationship between the trunk and the app.
set oRelInst2 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Forefront.UAG.TrunkHostsApplication']$")
oRelInst2.Source = oTrunkInst
oRelInst2.Target = oAppInst
call oDiscoveryData.AddInstance(oRelInst2)
end if
next
end if

' Discover the reps of the trunk
set userMgr = CreateObject("UserMgrComLayer.UserMgr")

if TypeName(userMgr) = "Nothing" then
Wscript.Quit -1
else
set info = CreateObject("UserMgrComLayer.Site")
info.Site = trunk.Name
info.Secure = trunk.Secure

on error resume next
set rawRepList = userMgr.GetSiteAuthenticationRepositories(info)
if err &lt;&gt; 0 then
Wscript.Quit -1
else
Dim rep
For each rep in rawRepList.NameVec
set oRepInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Forefront.UAG.Repository']$")
call oRepInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oRepInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Repository']/ID$", rep)
call oRepInst.AddProperty("$MPElement[Name='Microsoft.Forefront.UAG.Trunk']/ID$", trunk.Name)
call oRepInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", rep)
call oDiscoveryData.AddInstance(oRepInst)

' Create a relationship between the trunk and the rep.
set oRelInst3 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Forefront.UAG.TrunkHostsRepository']$")
oRelInst3.Source = oTrunkInst
oRelInst3.Target = oRepInst
call oDiscoveryData.AddInstance(oRelInst3)
next
end if
end if

next

end if
end if

Call oAPI.Return(oDiscoveryData)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


End Sub

Main()

</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>