Product Documentation

Director 7.7: Manage and configure alerts and notifications with PowerShell

Jul 11, 2016

With Director 7.7, you have the capability to configure policies and conditions that will alert you when the configured threshold is breached in a XenDesktop 7.7 environment. This article will help you configure your proactive alerts and notifications using the POSH cmdlets.

Configuring the notification subscription

Let’s assume that you are a XenDesktop admin and you are trying to understand the usage of your XenDesktop deployment. You need to be proactively alerted when the number of concurrent sessions crosses a threshold value. 

Before you can configure alerts and notifications, you need to configure your notification subscription. For this, you first need to add an SMTP Exchange server (don’t configure more than one), which you can use later to send emails when there is an alert. 

The Set-MonitorNotificationEmailServerConfiguration POSH cmdlet will help you in configuring the SMTP server. 

Here is a sample script that can help you get it done.

Code Copy

asnp Citrix.Monitor.*

PS C:\Users\administrator.BANDIT> Set-MonitorNotificationEmailServerConfiguration -ProtocolType SMTP -ServerName NameOfTheSMTPServerOrIPAddress -PortNumber PortNumber -SenderEmailAddress EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert -RequiresAuthentication 0

ProtocolType : SMTP

ServerName : NameOfTheSMTPServerOrIPAddress

PortNumber : PortNumber

SenderEmailAddress : EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert

RequiresAuthentication : False

Credential :

command Copy

PS C:\Users\administrator.BANDIT> Set-MonitorNotificationEmailServerConfiguration -ProtocolType SMTP -ServerName NameOfTheSMTPServerOrIPAddress -PortNumber PortNumber -SenderEmailAddress EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert -RequiresAuthentication 1 -Credential “SenderEmailAddressUserNameAsPerYourExchangeServerOrAD”

ProtocolType : SMTP

ServerName : NameOfTheSMTPServerOrIPAddress

PortNumber : PortNumber

SenderEmailAddress : EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert

RequiresAuthentication : False

Credential : System.Management.Automation.PSCredential

In case your SMTP server does not require authentication, you can set the 

-RequiresAuthentication flag to false.

command Copy

PS C:\Users\administrator.BANDIT> Set-MonitorNotificationEmailServerConfiguration -ProtocolType SMTP -ServerName NameOfTheSMTPServerOrIPAddress -PortNumber PortNumber -SenderEmailAddress EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert -RequiresAuthentication 0

ProtocolType : SMTP

ServerName : NameOfTheSMTPServerOrIPAddress

PortNumber : PortNumber

SenderEmailAddress : EmailAddressFromWhichDirectorShouldSendAnEmailWhenThereIsAnAlert

RequiresAuthentication : False

Credential :

Director also supports multiple protocols to connect with your SMTP server, including SMTP, SMTP-SSL, and SMTP-TSL.

Note: You can’t remove a SMTP configuration, but you can edit it and change its value.

A sample script

Here is a sample script that will help us in creating a policy with an alert rule, parameters, conditions, and email recipients. We will break each part of the script to understand more about it.

command Copy

asnp Citrix.Monitor.*

# Add Parameters

$timeSpan = New-TimeSpan -Seconds 30

$alertThreshold = 1

$alarmThreshold = 2

# Add Target UID’s

$targetIds = @()

$targetIds += “0e406be1-1647-4a97-845c-7601ae1d8883”

# Add email addresses

$emailaddress = @()

$emailaddress += “batman@gotham.com”

# Create new policy

$policy = New-MonitorNotificationPolicy -Name “MyTestPolicy” -Description “Policy created to test new cmdlets” -Enabled $true

Add-MonitorNotificationPolicyCondition -Uid $policy.Uid -ConditionType SessionsConcurrentCount -AlertThreshold $alertThreshold -AlarmThreshold $alarmThreshold -AlertRenotification $timeSpan -AlarmRenotification $timeSpan

Add-MonitorNotificationPolicyCondition -Uid $policy.Uid -ConditionType SessionsPeakconnectedCount -AlertThreshold $alertThreshold -AlarmThreshold $alarmThreshold -AlertRenotification $timeSpan -AlarmRenotification $timeSpan

Add-MonitorNotificationPolicyTargets -Uid $policy.Uid -Scope “My Test Targets” -TargetKind DesktopGroup -TargetIds $targetIds

Add-MonitorNotificationPolicyEmailAddresses -Uid $policy.Uid -EmailAddresses $emailaddress -EmailCultureName “en-US”

$policy = Get-MonitorNotificationPolicy -Uid $policy.Uid

$policy

Configuring recipient email addresses

Now that you’ve configured the SMTP Exchange server, you now need to configure the email recipients.

Using the Add-MonitorNotificationPolicyEmailAddresses cmdlet, you can specify the recipients of the email notification and choose the locale.

command Copy

$emailaddress = @()

$emailaddress += “batman@gotham.com”

Add-MonitorNotificationPolicyEmailAddresses -Uid $policy.Uid -EmailAddresses $emailaddress -EmailCultureName “en-US”

Configuring targets and target values

Now you’ll create a policy. The first thing to do is specify a target. A target is nothing but the entity on which the alert rule will be applied. For example, if my rule is “Alert me when the Peak Connected Session hits 100 on all the machines in my Delivery Group xyz,” then “delivery group xyz” is the target.

To specify a target and target value, you have to use the cmdlet:  

Code Copy

Add-MonitorNotificationPolicyTargets

Let’s suppose that you want to set the session concurrent alert on a Delivery Group for RDS machines. You will have to get the DG unique identifier and supply it as a value to the Add-MonitorNotificationPolicyTargets cmdlet.

How can you get it? Use the get-brokerDesktopGroup cmdlet, and you will find the unique identifier under UUID 

So now we have set the target value of the Delivery Group on which we want to target our alert rule.

Next, we have to specify the target and target type. Here, we can use the Add-MonitorNotificationPolicyTargets and specify the target type as “RDSWorker.”

command Copy

$targetIds = @()

$targetIds += “0e406be1-1647-4a97-845c-7601ae1d8883”

Add-MonitorNotificationPolicyTargets -Uid $policy.Uid -Scope “My Test Targets” -TargetKind DesktopGroup -TargetIds $targetIds

We can specify the target type as RDSWorker or a SITE or a DesktopGroup.

In general, you should target alert policies at three different scopes. 

  1. Site – Will apply to all the machines in the entire Site, and the alert threshold will be applied on the aggregate value of all the machines included.

  2. Desktop Group – Will apply to all the machines in the entire Delivery Group, and the alert threshold will be applied on the aggregate value of all the machines included.

  3. RDS Worker – Will apply to all the machines in the Delivery Group, but the alert threshold value will be applied to individual machines. 

Configuring conditions and parameters

Similar to earlier when we we wanted to set an alert rule policy for session concurrent policy, there are other conditions for which you can set policies:

Alert Type

Condition checked

Peak Connected Sessions

Detected when an instantaneous (one-minute samples) number of peak connected sessions for the entire site of a particular Delivery Group exceeds a configured count threshold.

Peak Disconnect Sessions

Detected when an instantaneous (one-minute samples) number of peak disconnected sessions for the entire site of a particular Delivery Group exceeds a configured count threshold.

Peak Concurrent Sessions

Detected when an instantaneous (one-minute samples) number of peak concurrent (total) sessions for the entire site of a particular Delivery Group exceeds a configured count threshold.

Connection Failure Count

Detected when the number of connections in a configurable time period fails across the entire site of a particular Delivery Group exceeds a configured count threshold.

Connection Failure Rate

Detected when the ratio of connection failures to connection attempts in a configurable time period across the entire site of a particular Delivery Group exceeds a configured percentage threshold.

Failed Desktop OS Machines

Detected when an instantaneous (one-minute samples) number of desktop OS machines in a failure state for the entire site of a particular Delivery Group exceeds a configured count threshold.

Failed Server OS Machines

Detected when an instantaneous (one-minute samples) number of server OS machines in a failure state for the entire site of a particular Delivery Group exceeds a configured count threshold.

Average Logon Duration

Detected when the average session logon time in a configurable time period across the entire site or for a particular Delivery Group exceeds a configured duration threshold.

RDS Load Evaluator Index

Detected when a configured load index value is sustained for five minutes.

Now we need to define the conditions and parameters for the policy.

Using the Add-MonitorNotificationPolicyCondition, we can add the alarm threshold, alert threshold, the alert and alarm re-notification times, and the period.

command Copy

Add-MonitorNotificationPolicyCondition -Uid $policy.Uid -ConditionType SessionsConcurrentCount -AlertThreshold $alertThreshold -AlarmThreshold $alarmThreshold -AlertRenotification $timeSpan -AlarmRenotification $timeSpan

 

  • AlertThreshold – Threshold value at which the warning notification will be triggered

  • AlarmThreshold – Threshold value at which the critical notification will be triggered

  • AlertRenotification – Duration after which the warning notification will be re-triggered

  • AlarmRenotification – Duration after which the critical notification will be re-triggered

  • Period – Window in which the alert threshold condition, warning or critical, is checked

The New-MonitorNotificationPolicy cmdlet will help you in creating a new policy. 

This article was modified from a Citrix blog post written by Issac Bharathi. You can read the original post here: https://www.citrix.com/blogs/2016/01/19/director-7-7-managing-and-configuring-alerts-notifications-using-powershell/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+CitrixBlogs+%28Citrix+Blogs%29.