Active IQ Unified Manager Discussions

Modify Email Alerts OCUM 7

Vikramjeet_Singh

We are looking to modify email alert send through OCUM when volume is full

 

We need to edit email body to our needs i.e. add couple of line to the email body

 

I have looked into some forums but I am bit confused.

 

Can you please help...where shall I start from?

 

I know that we can write a powershell script and add that to each and every alert on OCUM

 

I dont know how to modify email alert through powershell scripts Smiley Sad 

 

Can you please advice!!!

1 REPLY 1

Re: Modify Email Alerts OCUM 7

mbeattie

Hi Vikramjeet,

 

Here is an "example" for you that you can modify to meet your requirements. You would need to:

 

  • Update the variables "$to", "$from" and "$smtpServer" to the relevent values in your infrastructure
  • Add any additional lines you require to the $body variable
  • Format the CSS and HTML to meet your requirements

 

Please let me know if you have any questions.

 

#'------------------------------------------------------------------------------
#'Initialization Section. Define Global Variables.
#'------------------------------------------------------------------------------
[String]$hostname       = $env:computername
[HashTable]$event       = @{}
[HashTable]$eventArgs   = @{}
[String]$to             = ""
[String]$from           = "" 
[String]$smtpserver     = ""
#'------------------------------------------------------------------------------
#'Add the OCUM event arguments to hashtable.
#'------------------------------------------------------------------------------
For($i = 0; $i -le $Args.Count -1; $i++){
   If($Args[$i] -is [String]){
      If($Args[$i].StartsWith("-")){
         [String]$key = $Args[$i] -Replace("-", "")
         If(-Not($event.ContainsKey($key))){
            [HashTable]$event.Add($key, $Args[$i + 1])
         }
      }
   }
}
#'------------------------------------------------------------------------------
#'Add the OCUM event "eventArgs" to a hashtable if it contains sub arguments.
#'------------------------------------------------------------------------------
[String]$arguments     = $event["eventArgs"]
[Bool]$isEventArgsNull = $True
If(($arguments -ne $Null) -And ($arguments.Contains("="))){
   [Bool]$isEventArgsNull = $False
   [Array]$elements = $arguments.Split(" ")
   ForEach($element In $elements){
      $key   = $element.Split("=")[0]
      $value = $element.Split("=")[1]
      If(-Not($eventArgs.ContainsKey($key))){
         [HashTable]$eventArgs.Add($key, $value)
      }
   }
}
#'------------------------------------------------------------------------------
#'Exit processing if the OCUM event state is not new (Exit if resolved or obselete).
#'------------------------------------------------------------------------------
[Int]$eventId       = $event["eventID"]
[String]$eventState = $event["eventState"]
If(-Not($eventState -eq "new")){
   Exit 0
}
#'------------------------------------------------------------------------------
#'Set the HTML body and CSS for style formatting.
#'------------------------------------------------------------------------------
$body  = "<html><head><title></title><style type=""text/css"">.Title {background: #0077D4;color: #FFFFFF;text-align:center;font-weight:bold;}</style></head><body>"
$body += "<h2>OCUM Event</h2>"
$body += "<table><tr class='Title'><td>Event Property Name</td><td>Event Property Value</td></tr>"
ForEach($key In $event.Keys){
   Do{
      If($key -eq "eventArgs"){
         Break;
      }
      $body += $("<tr><td>" + $key + "</td><td>" + $event[$key] + "</td></tr>")
   }Until($True)
 
}
If(-Not($isEventArgsNull)){
   ForEach($key In $eventArgs.Keys){
      $body += $("<tr><td>" + $key + "</td><td>" + $eventArgs[$key] + "</td></tr>") 
   }
}
$body += "</table></body></html>"
$body += "<p>Script run from ""$hostName"""
#'------------------------------------------------------------------------------
#'Send the OCUM event as a HTML email (only for volume full or volume nearly full events).
#'------------------------------------------------------------------------------
If(-Not($isEventArgsNull)){
   If(($eventArgs.ContainsKey("volNearlyFull")) -Or ($eventArgs.ContainsKey("volFull"))){
   Try{
      Send-MailMessage -to $to -from $from -Subject "OCUM Event`: $eventId" -SmtpServer $smtpserver -Body $body -BodyAsHtml -ErrorAction Stop
   }Catch{
      Exit -1
   }
}
} #'------------------------------------------------------------------------------

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Earn Rewards for Your Review!
GPI Review Banner
All Community Forums
Public