#What parameter values have we received - write these to the task output window
write-host ("{0} `n{1} `n{2} `n{3} `n{4} `n " -f "Alarm to be acknowledged:",
"DSName: $DSName",
"ConnectionName: $ConnectionName",
"AlarmName: $AlarmName",
"AlarmFirstRaisedMSEpoch: $AlarmFirstRaisedMSEpoch")
#
# function for retrieving the optional ackMsg when the user is about to acknowledge an alarm
#
function Display-AlarmDlg
{
#Create the form to show
[System.Reflection.Assembly]::LoadWithPartialName(‘System.Windows.Forms’) | Out-Null
$WinForm = New-Object Windows.Forms.Form
$WinForm.text = "Acknowledging a Spotlight Alarm"
$WinForm.Size = New-Object Drawing.Size(380,150)
$WinForm.StartPosition = "CenterScreen"
#Add in the labels
$lblAckMsg = New-Object System.Windows.Forms.Label
$lblAckMsg.Text = "(Optional) Enter an acknowledgement message."
$lblAckMsg.Width = 400
$lblAckMsg.Location = New-Object System.Drawing.Size(10,10)
$WinForm.Controls.Add($lblAckMsg)
#Add in Event handlers
$WinForm.KeyPreview = $True
$WinForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{
#Put this in a common function at some stage
$Script:ackMsg = $txtAckMsg.Text;
$WinForm.Close()}
})
$WinForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$WinForm.Close()}
})
#Add in some buttons
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(195,70)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({
#Put this in a common function at some stage
$Script:ackMsg = $txtAckMsg.Text;
$WinForm.Close()
})
#Need to establish if we have access to the assemblies that we need to be able to snooze the alarms with
$sossePath="$env:sosse_mp_path"
if (-not (Test-Path $sossePath))
{
write-host ("{0} `n{1} `n{2} `n{3}" -f "The sossePath does not exist.",
"Please ensure that environment variable: `"sosse_mp_path`" ",
"has been set and that the Spotlight on SQL Server Enterprise MP assemblies have been copied",
"into a lib directory in this path")
exit 0
}
else
{
$sosseLibPath = "$sossePath\lib"
if (-not (Test-Path $sosseLibPath))
{
write-host ("{0} `n{1} `n{2}" -f "The path to the Spotlight on SQL Server Enterprise MP assemblies cannot be located.",
"Please ensure the directory $sosseLibPath exists and contains the",
"Spotlight on SQL Server Enterprise assemblies that accompanied the Spotlight management pack")
exit 0
}
}
$alarmMsg = "$AlarmName from Diagnostic server: $DSName and connection: $ConnectionName"
# Load the assemblies from a path defined by %sosse_mp_path% env variable...
try
{
[Reflection.Assembly]::LoadFile("$sosseLibPath\DSUtilities.dll") | Out-Null
[Reflection.Assembly]::LoadFile("$sosseLibPath\Waffle.Windows.AuthProvider.dll") | Out-Null
[Reflection.Assembly]::LoadFile("$sosseLibPath\Newtonsoft.Json.dll") | Out-Null
# make a connection to the DS and send off alarm acknowledgement details
$dsSession = New-Object -TypeName Dell.Diagnostic.Server.SCOM.DSUtilities+DSRequest -ArgumentList $DSName, $PortNo, $Action
$dsAckRequest = $dsSession.AcknowledgeAlarm($DSName, $ConnectionName, $AlarmName, $AlarmFirstRaisedMSEpoch, $ackMsg)
if ($dsAckRequest)
{
$request_msg = "The alarm was successfully acknowledged"
}
else
{
$request_msg = "Acknowledgement of the alarm failed"
}
write-host "$request_msg"
}
catch
{
$Status = $_.Exception.Message #Report back as part of DS
#$fullException= "Exception occurred acknowledging alarm:" + $ManagedObjectName + " " + $_.Exception|format-list -force
Write-Host ("{0} `n `n{1}" -f "The following error occurred attempting to acknowledge the alarm:",
"$Status")
exit 0
}