AKN410055

Monitor_AKN410055 (UnitMonitor)

Lync Certificate will expire in less than 7 days

Knowledge Base article:

External

http://go.microsoft.com/fwlink/?LinkId=262377

Element properties:

TargetMicrosoft.KnowledgeServices.Lync.2010.CsServer.Certificates
Parent MonitorSystem.Health.ConfigurationState
CategoryAlert
EnabledTrue
Alert GenerateTrue
Alert SeverityError
Alert PriorityHigh
Alert Auto ResolveTrue
Monitor TypeMicrosoft.KnowledgeServices.Library.PowerShellMonitorEx
RemotableTrue
AccessibilityPublic
Alert Message
Lync Certificate will expire in less than 7 days
<Details>
<Content> A Lync Server Certificate will expire in 7 days or less. An expired certificate will cause Lync services to not start or communication between servers could fail.

See the KB article for information on how to identify which certificates are about to expire.</Content>
<CollectedInformation>
<Info>
<Name>Certificate Type</Name>
<Value>{0}</Value>
</Info>
<Info>
<Name>Thumbprint</Name>
<Value>{1}</Value>
</Info>
<Info>
<Name>Subject</Name>
<Value>{2}</Value>
</Info>
</CollectedInformation>
</Details>
RunAsDefault
CommentSupportTopic=TBD;VersionNumber=1.0.0.0;

Source Code:

<UnitMonitor ID="Monitor_AKN410055" Comment="SupportTopic=TBD;VersionNumber=1.0.0.0;" Accessibility="Public" Enabled="true" Target="MicrosoftKnowledgeServicesLyncLibrary!Microsoft.KnowledgeServices.Lync.2010.CsServer.Certificates" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="High" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.PowerShellMonitorEx" ConfirmDelivery="true">
<Category>Alert</Category>
<AlertSettings AlertMessage="MonitorMessage2e24d853e16d4e91b75ee448ab6b5cbf">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>High</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="MicrosoftKnowledgeServicesLyncLibrary!Microsoft.KnowledgeServices.Lync.2010.CsServer.Certificates"]/Type$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="MicrosoftKnowledgeServicesLyncLibrary!Microsoft.KnowledgeServices.Lync.2010.CsServer.Certificates"]/Thumbprint$</AlertParameter2>
<AlertParameter3>$Target/Property[Type="MicrosoftKnowledgeServicesLyncLibrary!Microsoft.KnowledgeServices.Lync.2010.CsServer.Certificates"]/Subject$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AKN410055.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>ExpiryDate</Name>
<Value>$Target/Property[Type="MicrosoftKnowledgeServicesLyncLibrary!Microsoft.KnowledgeServices.Lync.2010.CsServer.Certificates"]/ExpiryDate$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>


param($ExpiryDate)

$ErrorActionPreference = "Stop"

# Set up the arguments
$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "ExpiryDate" $ExpiryDate

# Set up the output
$global:scriptoutput = new-object psobject
$scriptoutput | add-member NoteProperty "HasIssue" $false
#-----------------------------------------------------
# MAIN CODE SECTION
#-----------------------------------------------------

# Environment
$scriptenv = New-Object psobject
$scriptenv | Add-Member NoteProperty "RuntimeError" $false
$scriptenv | Add-Member NoteProperty "HasIssue" $false
$scriptenv | Add-Member NoteProperty "ExpiryDate" ""

# Check to see if Lync Certificate will expire in 7 days or less.
function CheckCertificateExpiryDate()
{
$expiryDateTime = [System.DateTime]::Parse($scriptenv.ExpiryDate, [System.Globalization.CultureInfo]::InvariantCulture)
$daysUntilExpiration = [int]$expiryDateTime.Subtract([System.DateTime]::Now).TotalDays

if ($daysUntilExpiration -le 7)
{
$scriptenv.HasIssue = $true
}
}

# Main Function
function AdvisorRule($scriptargs, $scriptoutput)
{
trap [Exception]
{
$scriptenv.RuntimeError = $true
continue;
}

$scriptoutput.HasIssue = $false
$scriptenv.ExpiryDate = $scriptargs.ExpiryDate

CheckCertificateExpiryDate

if($scriptenv.HasIssue -eq $true -and $scriptenv.RuntimeError -eq $false)
{
$scriptoutput.HasIssue = $true
}
}

AdvisorRule $scriptargs $scriptoutput

# set the output
$mom = new-object -comobject "MOM.ScriptAPI"
$bag = $mom.CreatePropertyBag()

if ($scriptoutput.HasIssue -ne $null)
{
$bag.AddValue("HasIssue", $scriptoutput.HasIssue)
}

$bag

</Script></ScriptBody>
<SnapIns/>
<TimeoutSeconds>300</TimeoutSeconds>
<Schedule>16400</Schedule>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<Not>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Not>
</SuccessExpression>
</Configuration>
</UnitMonitor>