Email Alert Notification based on Alert Descriptions
Have you ever wanted to create email notifications for Alerts based on Alert Descriptions? This cannot be done using the E-mail Notification Channel and Subscriptions settings.
This can be done however with the use of the Notification Command Channel with uses a vbscript that sends an email based on the information in the Alert Description. All the logic and sending of the emails is done by a script.
This is probably my last blog post for some weeks because I'm going to enjoy a long holiday ;-)
Here are the steps:
Create a vbscript and save this script in a folder on the RMS.
(example of script is at end of article and attached)Create new Command Notification Channel
Full path to file:
c:\windows\system32\cmd.exeCommand line parameters:
/c d:\scripts\notificationalertdescriptionv0.1.vbs /desc:"$Data/Context/DataItem/AlertDescription$" /alert:"$Data/Context/DataItem/AlertName$" /source:"$Data/Context/DataItem/ManagedEntityDisplayName$" /sev:"$Data/Context/DataItem/Severity$" /prio:"$Data/Context/DataItem/Priority$" /state:"$Data/Context/DataItem/ResolutionStateName$"Remark: Don’t forget the " " for the OpsMgr parameters.
desc is used in the vbscript as an argument
Done!
And now the vbscript that makes this all possible:
'Example script to use in the OpsMgr Command Notification Channel to
'send Email Notifications based on Alert Description to Solution groups.
'Some info for this script is taken from Script: Notification Logfile weblog article by Anders Bengtsson
'https://contoso.se/blog/?p=265
Option Explicit
Dim colNamedArguments
Dim AlertDescription
Dim AlertSource
Dim AlertName
Dim AlertSev
Dim AlertPrio
Dim AlertState
Dim objEmail
Dim objShell
Dim strContents
Dim strEventCreate
Dim strEventDescription
Dim strFrom
Dim strSub
Dim strBody
Dim strSMTP
Dim strTo
Set colNamedArguments = Wscript.Arguments.Named
Set objShell = CreateObject("Wscript.Shell")
' ******************************************
' GET PARAMETERS INTO SCRIPT
' ******************************************
AlertDescription = colNamedArguments("desc")
'Use: /desc:"$Data/Context/DataItem/AlertDescription$" in Notification Command Channel Command Line parameters
AlertName = colNamedArguments("alert")
'Use: /alert:"$Data/Context/DataItem/AlertName$" in Notification Command Channel Command Line parameters
AlertSource = colNamedArguments("source")
'Use: /source:"$Data/Context/DataItem/ManagedEntityDisplayName$" in Notification Command Channel Command Line parameters
AlertSev = colNamedArguments("sev")
'Use: /sev:"$Data/Context/DataItem/Severity$" in Notification Command Channel Command Line parameters
AlertPrio = colNamedArguments("prio")
'Use: /prio:"$Data/Context/DataItem/Priority$" in Notification Command Channel Command Line parameters
AlertState = colNamedArguments("state")
'Use: /state:"$Data/Context/DataItem/ResolutionStateName$" in Notification Command Channel Command Line parameters
'Complete Notification Command Channel Command Line parameter:
' /c d:\scripts\notificationalertdescriptionv0.1.vbs /desc:"$Data/Context/DataItem/AlertDescription$" /alert:"$Data/Context/DataItem/AlertName$" /source:"$Data/Context/DataItem/ManagedEntityDisplayName$" /sev:"$Data/Context/DataItem/Severity$" /prio:"$Data/Context/DataItem/Priority$" /state:"$Data/Context/DataItem/ResolutionStateName$"
'Alert Description from OpsMgr Alert
strContents = AlertDescription
' ******************************************
' TRANSLATE SEVERITY AND PRIORITY
' ******************************************
if AlertSev = "1" Then
AlertSev = "Critical"
elseif AlertSev = "2" then
AlertSev = "Warning"
elseif AlertSev = "3" then
AlertSev = "Information"
End If
if AlertPrio = "1" Then
AlertPrio = "High"
elseif AlertPrio = "2" then
AlertPrio = "Medium"
elseif AlertPrio = "3" then
AlertPrio = "Low"
End If
' ******************************************
' SCRIPT LOGIC
' ******************************************
' Configure on "serverx" the string which determines to which email address an email notification should be sent.
'Change the search string
If InStr(strContents, "serverx") Then
'Configure email address Solution Group X
strTo = "solutiongroupx@contoso.local"
'Send email
Call SendEMail(strTo)
End If
'Change the search string
If InStr(strContents, "servery") Then
'Configure email address Solution Group Y
strTo = "solutiongroupy@contoso.local"
'Send email
Call SendEMail(strTo)
End If
' ******************************************
' MAIL CONFIGURATION
' ******************************************
strFrom = "opsmgrnotification@contoso.local"
strSub = "Notification from Operations Manager 2007. Severity: " & AlertSev & ". Priority: " & AlertPrio & ". State: " & AlertState
strBody = "Notification from Operations Manager" & VBCRLF & VBCRLF & "Alert Name: " & AlertName & VBCRLF & "Alert Source: " & AlertSource & VBCRLF & "Alert Description: " & AlertDescription
strSMTP = "mail.contoso.local"
' ******************************************
' SEND MESSAGE
' ******************************************
Public Function SendEmail(strTo)
set objEmail = CreateObject("CDO.Message")
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSub
objEmail.Textbody = strBody
objEmail.Configuration.Fields.Item("https://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("https://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
objEmail.Configuration.Fields.Update
objEmail.Send
End Function
notificationonalertdescriptionv0.1.txt
Comments
Anonymous
January 01, 2003
Salut, ISA Server 2006 : Le pack d'administration supervise ISA Server 2006 et inclut les moniteursAnonymous
January 01, 2003
The comment has been removedAnonymous
January 01, 2003
Salut, ISA Server 2006 : Le pack d'administration supervise ISA Server 2006 et inclut les moniteurs