Tag Archives: MimboloveEmail Notifications
I have previously posted the Enhanced SCOM Alerts Notification email scripts back in July 2010.
I’d like to thank everyone who have tested it and provided feedbacks. You made me aware there are few issues and bugs with the script. Since I have just resigned and my new job won’t start in few weeks time, I have spent the last couple of days updating the script.
This is what I’ve done:
1. Removed GetNetbiosName function
- Few people advised there are often this function running into errors. I realised I originally wrote this function because one of my previous employers required the SCOM agent NetBios name in the email. but since SCOM is designed to monitor applications and objects rather than individual servers, I don’t see any reasons to include Computer NetBIOS name in the email. For sure it will often fail if the alert source is from a AD Site or distributed application, etc.
- Instead, I’ve added Alert Source, Path and Principal name in the email.
- P.S. I’ve also rewritten the function, trying to fix the bug. I’ve still left the
- function in the script (but commented out). Feel free to use it somewhere else.
2. Reformatted HTML email body
- I have changed the format of few items from <h3> (header 3) to just <b> (bold) to make the email more readable.
- I also made the alert severity more visual: Critical is displayed in Red, Warning displayed in Yellow and information displayed in Blue (if you subscribe informational alerts)
3. Added error handling for $rule.GetKnowledgeArticle() as sometimes there is no knowledge article.
- I often get error emails because GetKnowledgeArticle() method returns error. This is because not all rules and monitors will have knowledge articles associated to them. I have added few lines of code to handle errors occurred when calling this method. basically if calling this method failed, it will remove the entry from $error.
4. Fixed the problem with unconverted Unicode characters (i.e. %002d) displayed in emails.
I have also updated the original post, so this script can still be downloaded from the download link on the original post.
17/08/2012: The version 2 of this script has just been released: http://blog.tyang.org/2012/08/16/scom-enhanced-email-notification-script-version-2/
29/01/2012: The command notification channel setup section of this blog has been updated. More details of the change can be found HERE: http://blog.tyang.org/2012/01/29/command-line-parameters-for-scom-command-notification-channel/
Please Note: This post and associated script has been updated on 30/09/2010.
Even though SCOM is a great product, I personally believe that alert notification emails is something that really needs improvements. It is very hard (and almost impossible – according to my standard) to configure a meaningful notification email using the variables SCOM provides.
Most of times, the SCOM administrator would include a URL that takes you straight to the alert using SCOM web console. Web Console is greatly improved in SCOM 2007 R2, and it pretty much contains everything about the alert (such as alert name, description, source, time raised, monitor/rule name, description, knowledge article, etc).
But why can’t we have all this information in the notification email so we don’t have to come to the web console?
This cannot be done natively using SMTP notification channels. I accomplished it almost 2 years ago for my previous employer, using PowerShell and SCOM Command Notification Channel. I wrote a PowerShell script to utilise System.Net.Mail classes to send out HTML formatted email that contains EVERYTHING that you can get from SCOM Operations Console or Web Console.
The following information is included in the notification email:
- – Alert name, description, severity, resolution state, source, path, Time created
- – Monitor / Rule name
- – Knowledge Article for the particular monitor / rule
- – Web console URL link to the alert
- – PowerShell command to retrieve the alert from SCOM command console
I completed forgot about this script until recently one of my customer’s support team asked me if there are any better ways to configure Alert Notification emails in SCOM. Now I’ve decided to post it in my blog so you all can benefit from it.
Below is the email notification for the alert from the above web console screenshot:
OK. if you want to try this out in your SCOM environment, please keep reading. Let’s go through the steps setting this up in SCOM:
1. Download SCOMEnhancedEmailNotification.ps1
2. Modify this section of the script (line 26-48, Highlighted in Yellow):
- $NotifiedResState – At the end of this script, after the email is sent, it changes the resolution state of the alert to “Notified”. I have manually created such resolution state using SCOM Operations Console with number 85. You can use other number if you wish, just make sure this variable represent the right number of the resolution state you want the script to set the alert to at the end.
- Function getResStateName – Modify function getResStateName to have ALL the resolution states for your SCOM environment.
- $strSMTP – The FQDN of your SMTP server
- $iPort – Port used for SMTP. default is 25. if your SMTP server is not use port 25, please change this variable accordingly.
- $Sender – make sure you have the sender (return address) and the display name set inside the bracket( )
- $ErrRecipient – If the script is running into errors, it will try to email the error message to this recipient. I’d suggest you to set this to your company’s SCOM administrator so they know there is a problem.
3. Once the script is modified, save it to a local folder on your RMS server. In this blog, we will use D:\Scripts\ as an example.
4. Setting up SCOM Command notification channel:
NOTE: Because we are not using SMTP channels, we cannot specify the email addresses in Subscriber’s properties. Instead, we are passing in the email addresses as parameters. So for subscriptions with different subscribers, you will need to create multiple command channels with different email addresses.
- Full path of the command file: C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe
- Command line parameters: -Command “& ‘”D:\Scripts\SCOMEnhancedEmailNotification.ps1″‘” -alertID ‘$Data/Context/DataItem/AlertId$’ -Recipients @(‘Tao Yang;Tao.Yang@xxxx.com’,John Smith;John.Smith@xxxx.com‘)
- Recipients are passed into the script as an array variable. make sure you use this format inside the (): ‘Recipient 1 Name;Email’,’Recipient 2 Name;Email’
- Alert ID is quoted using single quotation mark ONLY.
- Startup folder for the command line: D:\Scripts
- This is the location of the script
5. Setting up subscribers
6. Setting up subscriptions
One last thing to remember: The powerShell execution policy on your RMS needs to set to RemoteSigned or Unrestricted.
This script can be downloaded HERE. Feel free to email me if you are having issues setting this up!