Logon Simulator Monitor

Community.Citrix.LogonSimulator.TestMonitor (UnitMonitor)

Performs an application launch to test availability

Element properties:

TargetCommunity.Citrix.LogonSimulator.Test
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeCommunity.Citrix.LogonSimulator.PowerShellTwoStateMonitorType
RemotableTrue
AccessibilityInternal
Alert Message
Citrix Simulated Logon Failed
An automated test to launch an application failed. The application may be unavailable to some or all users.
RunAsCommunity.Citrix.LogonSimulator.TestUserAccount

Source Code:

<UnitMonitor ID="Community.Citrix.LogonSimulator.TestMonitor" Accessibility="Internal" Enabled="true" Target="Community.Citrix.LogonSimulator.Test" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="Community.Citrix.LogonSimulator.PowerShellTwoStateMonitorType" ConfirmDelivery="false" RunAs="Community.Citrix.LogonSimulator.TestUserAccount">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Community.Citrix.LogonSimulator.AlertMessage">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/Interval$</IntervalSeconds>
<SyncTime>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/SyncTime$</SyncTime>
<ScriptName>Execute-Test.ps1</ScriptName>
<ScriptBody><Script>param(
$StoreFrontUrl,
$ResourceName,
$Domain,
$UserName,
$Password,
$TestName,
$ConfigurationPath,
$LogFileName,
$TimeoutForSFLoginPage,
$TimeoutForSFResourcesPage,
$TimeoutForSessionLogin,
$TimeoutForOther
)

$scriptName = "Execute-Test.ps1"

# Initialise SCOM API
$api = new-object -comObject "MOM.ScriptAPI"

# Put everything in a try-catch to report errors to SCOM
try {

# SCOM log start
$api.LogScriptEvent($scriptName, 1000, 0, "Started")

$scriptProcessStartInfo = New-Object System.Diagnostics.ProcessStartInfo "PowerShell"
$scriptProcessStartInfo.Arguments = "$ConfigurationPath\Scripts\Test-CitrixApp.ps1 -LogFilePath '$ConfigurationPath\Logs\$TestName' -LogFileName 'sflauncher.log' -SiteURL '$StoreFrontUrl' -UserName '$Domain\$UserName' -Password $Password -ResourceName $ResourceName -TimeoutForSFLoginPage $TimeoutForSFLoginPage -TimeoutForSFResourcesPage $TimeoutForSFResourcesPage -TimeoutForSessionLogin $TimeoutForSessionLogin -TimeoutForOther $TimeoutForOther"
$scriptProcessStartInfo.Domain = $Domain
$scriptProcessStartInfo.UserName = $UserName
$scriptProcessStartInfo.Password = (ConvertTo-SecureString $Password -AsPlainText -Force)
$scriptProcessStartInfo.LoadUserProfile = $true
$scriptProcessStartInfo.Verb = "runas"
$scriptProcessStartInfo.UseShellExecute = $false
$process = [System.Diagnostics.Process]::Start($scriptProcessStartInfo)
$process.WaitForExit()
$returnCode = $process.ExitCode

# Log complete
$api.LogScriptEvent($scriptName, 1001, 0, "Finished with output '$returnCode'")

# Interpret errors as SCOM monitor result
if($returnCode -eq 0) { $state = "good" } else { $state = "bad" }

$api.LogScriptEvent($scriptName, 1001, 0, "Adding state: $state")

# Create the SCOM "property bag"
$pb = $api.CreatePropertyBag()

$pb.AddValue("State", $state)

# Write the property bag to the output
$pb

}
catch {
# Top level error handling - log to SCOM
$api.LogScriptEvent($scriptName, 1002, 2, $_.Exception.Message)
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>StoreFrontUrl</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/StoreFrontUrl$</Value>
</Parameter>
<Parameter>
<Name>ResourceName</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/ResourceName$</Value>
</Parameter>
<Parameter>
<Name>Domain</Name>
<Value>$RunAs[Name="Community.Citrix.LogonSimulator.TestUserAccount"]/Domain$</Value>
</Parameter>
<Parameter>
<Name>UserName</Name>
<Value>$RunAs[Name="Community.Citrix.LogonSimulator.TestUserAccount"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>Password</Name>
<Value>$RunAs[Name="Community.Citrix.LogonSimulator.TestUserAccount"]/Password$</Value>
</Parameter>
<Parameter>
<Name>TestName</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/TestName$</Value>
</Parameter>
<Parameter>
<Name>ConfigurationPath</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/ConfigurationPath$</Value>
</Parameter>
<Parameter>
<Name>LogFileName</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/LogFileName$</Value>
</Parameter>
<Parameter>
<Name>TimeoutForSFLoginPage</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/TimeoutForSFLoginPage$</Value>
</Parameter>
<Parameter>
<Name>TimeoutForSFResourcesPage</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/TimeoutForSFResourcesPage$</Value>
</Parameter>
<Parameter>
<Name>TimeoutForSessionLogin</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/TimeoutForSessionLogin$</Value>
</Parameter>
<Parameter>
<Name>TimeoutForOther</Name>
<Value>$Target/Property[Type="Community.Citrix.LogonSimulator.Test"]/TimeoutForOther$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>600</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>NotEqual</Operator>
<ValueExpression>
<Value Type="String">good</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">good</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>