Hello there!
With the subjects lines created by the Standard Email Plugin being archaic as:
"[vRealize Operations Manager] new alert Type:Virtualization/Hypervisor, Sub-Type:Availability, State:critical, Object Type:VirtualMachine, Name:fooserver"
You might want to utilize the available template structure hinted at in KB2125759 and documented in the API under /suite-api/docs/rest/index.html
Synopsis:
You can create your own email templates without modifying the underlying base templates or framework.
We are provided a basic template in the KB with the necessary variables for a clean, concise notification.
We first create the template using a put web command. /suite-api/docs/rest/index.html#createEmailTemplate
We then create conditions under which the template is used. /suite-api/docs/rest/index.html#setEmailCondition
If a notification being put out by the Standard Email Plugin and matches *all* of the criteria in the conditions, the custom template is applied, otherwise the default is used.
Before you begin:
Be willing to interact with the REST system through Curl or Invoke-RestMethod.
You must have the Standard Email Plugin already working.
Gather all of the Email addresses that will be receiving alerts. Setting up notifications to DLs instead of individuals is advised.
Have a local vRops admin account credentials available.
Understand the three main ingredients
- Alert Status
- New
- Active
- Updated
- Canceled
- Alert Type
- 15 - Application
- 16 - Virtualization/Hypervisor
- 17 - Hardware (OSI) Alerts
- 18 - Storage Alerts
- 19 - Network Alerts
- Alert SubType
- 18 - Availability
- 19 - Performance
- 20 - Capacity
- 21 - Compliance
- 22 - Configuration
Decide on how many templates are needed to match your needs.
Example:
Subject "[vRops] FooServer - Virtual Machine Disk Space is Running Low"
New alert was generated at: Thu Aug 18 20:36:21 CDT 2016
Info: FooServer VirtualMachine
Alert Definition Name: Virtual Machine Disk Space is Running Low
Alert Definition Description: One or more guest file systems of the virtual machine are running out of disk space.
Alert Impact: health : AlertLevel: Immediate
Alert Type : Virtualization Problem : Capacity Problem : 3.0
Symptoms:
SYMPTOM SET - self
Symptom Name
Object Name
Object ID
Metric
Message Info
Guest file system overall disk space usage reaching immediate limit
FooServer
xxxxxxxx
Guest File System stats|Total Guest File System Usage
90.58 > 90.0
Recommendations:
- Reclaim disk space using in-guest disk cleanup mechanisms.
Notification Rule Name: Notification Rule
vRops Server - link to Alert
Commands
Reference Variables for below commands.
vrops.domain.com = your vRops server IP address or VIP
user = a local admin account 'ie admin' or 'user@domain'
password = password to admin account
TemplateID = the ID of the custom template you created. Provided by Get /suite-api/api/notifications/email/templates/ shown below
Email@domain.com = A specific email address that will be receiving the template
The commands:
Starting with the most important; how to back-out completely, removing your changes.
curl -X DELETE -u user:"password" "https://vrops.domain.com/suite-api/api/notifications/email/templates/TemplateID/conditions/" curl -X DELETE -u user:"password" "https://vrops.domain.com/suite-api/api/notifications/email/templates/TemplateID/"
Now creating the template.
The return will include the Template ID in the header.
curl -X POST -H "Content-Type: application/xml" -u user:"password" -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ops:email-template html="true" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/"> <ops:name>TemplateForNew</ops:name> <ops:template>$$Subject=[vRops] {{AffectedResourceName}} - {{AlertDefinitionName}} New alert was generated at: {{AlertGenerateTime}} Info: {{AffectedResourceName}} {{AffectedResourceKind}}<br> Alert Definition Name: {{AlertDefinitionName}} Alert Definition Description: {{AlertDefinitionDesc}} Alert Impact: {{AlertImpact}} : {{AlertCriticality}} Alert Type : {{AlertType}} : {{AlertSubType}} Symptoms:<br>{{Anomalies}} Recommendations: {{AlertRecommendation}} Notification Rule Name: {{FilterRuleName}} vRops Server - {{vcopsServerName}} <a href={{AlertSummaryLink}}>Alert details</a></ops:template></ops:email-template>' "https://vrops.domain.com/suite-api/api/notifications/email/templates/"
Viewing the Templates and Template IDs
curl -X GET -u user:"password" "https://vrops.domain.com/suite-api/api/notifications/email/templates/"
Viewing an individual Template
curl -X GET -u user:"password" "https://vrops.domain.com/suite-api/api/notifications/email/templates/TemplateID/"
Create the conditions to apply the Template to Virtualization(16) Availability(18) alerts
curl -X POST -i -H "X-vRealizeOps-API-use-unsupported: true" -H "Content-Type: application/xml" -u user:"$password" -d "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ops:email-template-condition alertSubType=\"16\" alertType=\"18\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ops=\"http://webservice.vmware.com/vRealizeOpsMgr/1.0/\"><ops:alertStatus>NEW</ops:alertStatus><ops:emailAddress>Email@domain.com</ops:emailAddress></ops:email-template-condition>" https://vrops.domain.com/suite-api/api/notifications/email/templates/TemplateID/conditions
Shell script to automate condition creation
#!/bin/bash read -sp 'Password for account Admin' password #define your world user=Admin templateid=TemplateID host=vrops.domain.com mail=(Email@domain.com Email2@domain.com Email3@domain.com) alertstatus=(NEW ACTIVE UPDATED CANCELED) alerttype=(15 16 17 18 19) alertsubtype=(18 19 20 21 22) for email in ${mail[@]} do for a in ${alerttype[@]} do for b in ${alertsubtype[@]} do for STATUS in ${alertstatus[@]} do curl -X POST -i -H "X-vRealizeOps-API-use-unsupported: true" -H "Content-Type: application/xml" -u $user:"$password" -d "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ops:email-template-condition alertSubType=\"$b\" alertType=\"$a\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ops=\"http://webservice.vmware.com/vRealizeOpsMgr/1.0/\"><ops:alertStatus>$STATUS</ops:alertStatus><ops:emailAddress>$email</ops:emailAddress></ops:email-template-condition>" https://$host/suite-api/api/notifications/email/templates/$templateid/conditions done done done done