VMware vSphere

 View Only

 Customize email alert subject line

Jim L's profile image
Jim L posted Aug 06, 2024 06:41 PM

I have been searching with absolutely no luck.

I would like to add the vcenter hostname to the alert subject line and would like to do this with a variable.  I have a powershell script to create the alert actions, but I can not find anything close to what variables are supported on the subject line.  The closet I found was Customizing vCenter Alarm Email Subject and Body

WilliamLam.com remove preview
Customizing vCenter Alarm Email Subject and Body
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 c...
View this on WilliamLam.com >

However this does not work when I type "{" I do not get the drop down list described.  

I have multiple vcenters and would like to keep consistency across them without having to put the actual name in the subject line.  I usually speak good google, but it is letting me down. And Broadcom taking over the community the search is useless.

What I am looking for is for the email subject the variable that will give me the vcenter server name

{VariableForHostname} - {Alarm name} on Virtual Machine : {Target Name} is {New status}

The other variable are working as they should and I find lots of references to that format, but I have not been able to find link to the doc to find what others are supported

This link which is in William Lam's page also does not work.

https://code.vmware.com/apis/358/vsphere/doc/vim.action.Action.ActionParameter.html

Broadcom Platform Admin's profile image
Community Manager Broadcom Platform Admin

@Jim L - have you tried https://docs.vmware.com/en/search/#/Customizing%20vCenter%20Alarm%20Email%20Subject%20and%20Body

I did a search in support.broadcom.com as well which had results but I don't know enough about the product and question to dig it out.   The support portal has all data sources.

Jason McClellan, Platform Mgr.

JDMils_Interact's profile image
JDMils_Interact

It would be best to see your code in order to answer this question. 

Jim L's profile image
Jim L

It is not even a question on the powershell code.  I know how to manually code in the vcenter name if I do it that way. If I am just using the UI to edit the email subject.  Instead of hardcoding in the name of the vcenter, I would like it to be a variable.  I did find a link referencing the action parameter

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1ef6c336-7bef-477d-b9bb-caa1767d7e30/82521f49-9d9a-42b7-b19b-9e6cd9b30db1/

It seems that only these are supported. Nothing referencing hostname or viserver name.  Not that I ever expect the vcenter server name to change, but I would prefer a variable vs hard coding the name in case that should ever happen.

alarm

alarmName

declaringSummary

eventDescription

newStatus

oldStatus

target

targetName

triggeringSummary

email subject
JDMils_Interact's profile image
JDMils_Interact

OK, sorry, didn't realise you were using the New Alarm UI within vCenter. But am I missing something? I created a new host-related alarm with the following subject line:

Alarm {Alarm name} on Host : {Target Name} is {New status}

{Target Name} IS the host name! What happens if you put this variable into your subject line?

I'm assuming that the alarm you are creating has nothing to do with the host and thus the variable may not be available?

JDMils_Interact's profile image
JDMils_Interact

Yeah, looks like the variable is dependent on the initial target you use for the alarm. So I chose an alarm for VMs and got this subject line:

Alarm {Alarm name} on Virtual Machine : {Target Name} is {New status}

Where {Target Name} is the VM now.

JDMils_Interact's profile image
JDMils_Interact

Come to think about it, since you are already knee-deep into PowerCLI, your best option going-forward would be to handle the alarms thru your script thus you will be able to customise everything about the email. Setup the vCenter GUI alarm to trigger on xxxx, do not send email, do not send SNMP trap, Run Script xyz.

Your script can then query the environmental variables:

  • VMWARE_ALARM_NAME
  • VMWARE_ALARM_TARGET_NAME
  • VMWARE_ALARM_EVENTDESCRIPTION
  • VMWARE_ALARM_ALARMVALUE

To get everything you need.

PS C:\Users\jmilano> $Target_Name = 'MyVM'
PS C:\Users\jmilano> $TheVM = Get-VM -Name $Target_Name
PS C:\Users\jmilano> $TheHost = $TheVM.VMHost
PS C:\Users\jmilano> $Target_Name, $TheHost

MyVM
MyHost.mydomain
PS C:\Users\jmilano>

Your script then sends a customised email with all the required values.

Reference: https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.vsphere.monitoring.doc/GUID-AB74502C-5F01-478D-AF66-672AB5B8065C.html

Jim L's profile image
Jim L

JDMils_Interact,

Thanks for the time and insight.

I need to refresh all of the alarms now to include any new in vcenter8 I haven't updated these since 6.5.  The powershell script I use will modify the alarm actions and Can set the Subject line as well.  Due to an upstream change in mail servers I can no longer see the header to determine where the main came from.  My end goal is to include the vcenter server name so that the subject is vcenter..mysite.com - Alarm {Alarm Name} on {Target} is {New Status}.

As I stated it will be easy enough with PowerShell to modify this, the the vcenter.mysite.com will be hard coded.  I had hoped for this to be a variable so my definitions are the same across all of my vcenters and in the event I need to change the vcenter name at some point, I won't have to modify 100+ Alerts again.

This is something I do fairly easily on Linux or Windows.  A single script I can port/run anywhere and send an email with the hostname in the subject line without it being hardcoded.