One of the automated actions that can be configured when a vCenter Server Alarm is triggered is to send an email notification. Over the years, I have seen a number of requests and questions about customizing the email and whether an email template exists. I personally have not used this feature much which has been around since the introduction of vCenter Server and mainly because I have always worked in an environment where we had dedicated monitoring tools that provide notifications including emails.
Most recently, I noticed an increase number of questions around this topic and I was curious on whether a solution exists today or if this is still a gap today? A quick Google search landed me on this 2013 VMTN thread which included several workarounds that customers have found. However, the only viable "supported" and "persisted" option at the time within that thread was to use the vSphere API/PowerCLI to customize the alarm action.
While going through this exercise myself, I found that our vSphere UI has had some enhancements since that 2013 thread and I thought it was worth sharing an update in 2019 on how customers can customize both the email subject and body for vCenter Alarms. One thing to note is that there is no generic email template that can be edited, the email customizations are applied on a per-Alarm action basis and this is applicable for both vCenter Server running in a traditional on-premises environment as well as for VMware Cloud on AWS or Dell EMC.
Email Subject
One of the most common request is to change the email subject line so that it contains additional keywords which maybe used for filtering and/or compliance purposes. Once of the nice enhancements about the vSphere HTML5 UI re-design was that the VMware UX team did not just port over the Flash-based vSphere Client but they had the opopournity to improve a number of workflows including vCenter Server Alarm configurations.
In both the prior vSphere C# and Flash Client, the subject line was not configurable using the UI and was only configurable when using the vSphere API or PowerCLI. Given this was a common customization, it made sense to include this in the UI as part of the email notification as shown in the screenshot below. In fact, even the run-time values can easily be added by simply typing "{" and a drop-down list will be provided for the 9 different options that can be used which are also documented here for your reference. Customers can change or add additional information to the subject and this can now be done simply by using the vSphere UI.
Here is an example of what the email notification would look like based on our modified subject line from above:
Email Body
The next level of customization which is not frequently asked about is customizing the body of the email. Unfortunately, this is not configurable using the vSphere H5 Client and must be done using the vSphere API. With PowerCLI, it is very easy to do to update the body of the email to include additional information or simply re-formatting the text to fit your needs. Below is an example that includes a multi-line format as I noticed many of the examples online has everything on a single line, which can make it difficult to read 🙂 If you need to customize the body, then you can use the vSphere API or PowerCLI to simply update both the subject line and body in one shot rather than having to do some of it via the UI or if you wish to simply automate this across a number of important vCenter Alarms.
Get-AlarmDefinition -Name "Customer-PowerOn-Action" | New-AlarmAction -Email -To '*protected email*' -Body ' ### virtuallyGhetto Alarm ### {alarmName} triggered on {targetName} virtuallyGhetto Alarm ### ' -Subject '[virtuallyghetto-alarm] {targetName}'
Note: When you copy the above command, make sure the line breaks are preserved which will ensure you have line breaks in the actual email.
Here is an example of what the email notification would look like based on our modified subject line and body from above:
Hopefully this article makes it clear on how you can customize the various email notifications, which are applied on an individual vCenter Alarm, in a supported and persisted manner. If you have multiple alarms to update, you should definitely Automate this using something like PowerCLI to help speed things up and ensure you do not make any mistakes. One last thing to note is that vCenter Server does not support TLS/SSL-based SMTP servers, a basic email relay may need to be setup if you wish to have vCenter Server send emails. An alternative option is to leverage our vCenter Event Broker Appliance Fling which would allow you to integrate with any email system or any other type of automated triggers for that matter.
barname android says
hey great
it worked for me correctly.
thanks a lot
leanroid says
i used it and worked so nice
tnx for sharing
android app says
so nice
tnx for sharing
android application says
awsome content
new music says
why i cant share comment
gbwhatsapp says
try again
have no problem here
application says
omg it works
John SysAdmin says
William,
It is helpful to understand who performed an action.
I was able to include {Target Summary} in the subject line (which includes username) but it is not very useful as the user is deeper into the subject length, making it hard to read/filter.
Is there any way to include the user name in body of the alert?
I tried adding {Target Summary} but it treated it as TEXT not a variable.
Anyway to break down {Target Summary} into a more readable format in the body?
Thanks in advance.
itaish says
hi william,
i'm also looking for the answer on the question above, your answer will be appreciated.
in addition, i have a few other things:
1. can the body of the mail can be reverted to default after you change it by the script you mentioned or you need to delete it and start again?
2. i created an alarm from the GUI and set email alerts, then I changed the email body with your commands, now I receive 2 mails together, one from the GUI body and subject, and one with the powercli body and subject.
is it only possible to set the alarm definition from only one tool (gui vs powecli)?
3. if i'll set the powercli option only, would i see the alarm in the GUI?
Christoph Reeber says
Hi Wiliam,
great example.
Is there a documentation about the usable variables in the body text?
Thanks in advance
Christoph
William Lam says
Yes, its linked in the blog post 🙂 Search for "also documented here"
Srinivas says
Hi William
Greetings!!
I gave a try by changing the subject line as "Datastore : {Target Name} is {New status}" but it didnt trigger any mail, not sure what Iam missing here, can you please help on this.
Also I need to customize the mail body content, can you please let us know do we need to edit any file in vcsa appliance or if we need to run thru script where do we need to keep this script file and execute, can you please share some light on this.
Thanks in advance.
Regards
Srinivas
Christoph Reeber says
Thanks for the hint, I overlooked the Link in here 🙂
David Wagner says
Any chance on getting a updated version of this for vCenter 7? I cannot find any information related to what commands to use. The PowerCLI commands listed here do not seem to work on vCenter 7.
William Lam says
There’s nothing in script that is version specific. Always install latest version of PowerCLI, it’s backwards compat and includes fixes/features. Rather than posting “do not seem to work”, actually post what you’ve tried along with any error message … hard to help without anything useful to go off of