WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • Apple
You are here: Home / PowerCLI / Customizing vCenter Alarm Email Subject and Body

Customizing vCenter Alarm Email Subject and Body

11.20.2019 by William Lam // 13 Comments

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.

More from my site

  • How to modernize your vSphere Alarm actions using the VMware Event Broker Appliance (VEBA)?
  • Creating vCenter Alarms based on Task Events such as Folder creation
  • Create vCenter Alarms for monitoring HCX migration events
  • How to run a script from a vCenter Alarm action in the VCSA?
  • How to automatically log all VM configuration changes using a vCenter Server Alarm?

Categories // PowerCLI, VCSA, VMware Cloud on AWS, vSphere Tags // alarm, email, vcenter

Comments

  1. barname android says

    11/24/2019 at 10:37 pm

    hey great
    it worked for me correctly.
    thanks a lot

    Reply
  2. leanroid says

    04/07/2020 at 11:28 am

    i used it and worked so nice
    tnx for sharing

    Reply
  3. android app says

    04/23/2020 at 3:43 pm

    so nice
    tnx for sharing

    Reply
  4. android application says

    09/14/2020 at 7:10 am

    awsome content

    Reply
  5. new music says

    10/06/2020 at 9:12 am

    why i cant share comment

    Reply
    • gbwhatsapp says

      10/06/2020 at 9:15 am

      try again
      have no problem here

      Reply
  6. application says

    10/06/2020 at 9:14 am

    omg it works

    Reply
  7. John SysAdmin says

    06/01/2021 at 2:28 pm

    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.

    Reply
    • itaish says

      06/29/2021 at 6:17 pm

      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?

      Reply
  8. Christoph Reeber says

    06/14/2021 at 6:15 am

    Hi Wiliam,

    great example.
    Is there a documentation about the usable variables in the body text?

    Thanks in advance

    Christoph

    Reply
    • William Lam says

      06/14/2021 at 1:38 pm

      Yes, its linked in the blog post 🙂 Search for "also documented here"

      Reply
      • Srinivas says

        01/13/2023 at 3:07 am

        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

        Reply
  9. Christoph Reeber says

    06/15/2021 at 2:16 am

    Thanks for the hint, I overlooked the Link in here 🙂

    Reply

Thanks for the comment! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • Self-Contained & Automated VMware Cloud Foundation (VCF) deployment using new VLC Holodeck Toolkit 03/29/2023
  • ESXi configstorecli enhancement in vSphere 8.0 Update 1 03/28/2023
  • ESXi on Intel NUC 13 Pro (Arena Canyon) 03/27/2023
  • Quick Tip - Enabling ESXi Coredumps to be stored on USB 03/26/2023
  • How to disable the Efficiency Cores (E-cores) on an Intel NUC? 03/24/2023

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2023

 

Loading Comments...