AcknowledgeAlarms.ps1 (DeployableResource)

Element properties:

TypeDeployableResource
File NameAcknowledgeAlarms.ps1
AccessibilityPublic
CommentPScript for acknowledging SoSSE alarms

Source Code:

<DeployableResource ID="AcknowledgeAlarms.ps1" Accessibility="Public" FileName="AcknowledgeAlarms.ps1" HasNullStream="false" Comment="PScript for acknowledging SoSSE alarms"/>

File Content: AcknowledgeAlarms.ps1

# Acknowledges Spotlight alarms


param($DSName,
$ConnectionName,
$AlarmName,
$AlarmFirstRaisedMSEpoch)


#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 Textbox
$txtAckMsg = New-Object System.Windows.Forms.TextBox
$txtAckMsg.Location = New-Object System.Drawing.Size(10,35)
$txtAckMsg.Width = 340
$WinForm.Controls.Add($txtAckMsg)

#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()
})

$WinForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(275,70)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({
$WinForm.Close()
})

$WinForm.Controls.Add($CancelButton)


$WinForm.Add_Shown($WinForm.Activate())
$WinForm.showdialog() | Out-Null

return $ackMsg
}

#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"

write-host "Acknowledging alarm: $alarmMsg"

$ackMsg=Display-AlarmDlg

[int]$dsAck_EventID = 71000
[int]$PortNo = 40403
$Action = "AcknowledgeAlarm"

# 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
}