Skip to content

Latest commit

 

History

History
197 lines (148 loc) · 5.68 KB

File metadata and controls

197 lines (148 loc) · 5.68 KB
copyright
years
2021, 2025
lastupdated 2025-10-29
keywords event notifications, event-notifications, tutorials
subcollection event-notifications

{{site.data.keyword.attribute-definition-list}}

Creating an {{site.data.keyword.en_short}} template

{: #en-create-en-template}

An {{site.data.keyword.en_full_notm}} template defines the layout and content of notifications (email, webhook, Slack, etc.). Templates can include images, static text, and dynamic content (variables, conditional logic) based on events.

Event Notifications supports two types of templates:

  1. User-defined templates: You can design your own templates to structure notification messages.

  2. Pre-defined templates: These are standard templates defined for a pair of specific source and destination. You can customize pre-defined templates to create a user defined template.

{: shortdesc}

Creating a user-defined template

{: #en-create-template}

  1. In the {{site.data.keyword.cloud_notm}} console, click the menu icon hamburger icon > Platform Automation > Event notifications.

  2. Click the name of your {{site.data.keyword.en_short}} instance.

  3. Select Templates from the left panel and click Create.

  4. Enter details about the template such as the name and description, and select a template type. Event Notifications currently supports the following user-defined templates:

  5. Click Add to save your updates.

Handlebars Integration

{: #handlebars-integration}

Handlebars is a templating language that allows for dynamic content generation within templates. Handlebars can be used to customize notification messages using template variables ,conditional logic and various other helpers.

Template Variables

{: #template-variables}

Template variables are placeholders within the notification message templates that get replaced with actual data when a notification is triggered. These variables allow users to personalize messages and include relevant information from the event being notified.

Usage:

{: #usage-template-variables}

{{variable_name}}

Example:

Event Name: {{event_name}}

Conditional Logic Helper

{: #conditional-logic-helper}

Conditional logic allows users to define conditions within the message templates, enabling dynamic content generation based on the values of variables. This feature is useful for creating flexible notification messages that adapt to different scenarios.

Usage:

{: #usage-conditional-logic-helper}

{{#if condition}}
   
{{else}}
   
{{/if}}

Example:

{{#if severity}}
   Severity: {{severity}}
{{else}}
   No severity information available
{{/if}}

Contains Helper

{: #contains-helper}

The contains helper allows users to check whether there is a specific word in any of the fields of the payload.

Example:

{: #example-contains-helper}

"data":
{
	"message": "this is test alert from dev account"
}

Use the contains helpers like:

{
{{#contains data.message "dev"}}
"environment": "development"
{{/contains}}
}

There are more helpers available for use that can be referenced from here {: note}

Examples:

{: #template-examples}

Payload:

"data":
{
	"message": "this is test alert from dev account",
	"secrets": [
	{
		"event_time": "2025-01-24T00:45:01Z",
		"event_triggered_by": "SecretsManager",
		"secret_expiration": "2025-04-24T00:45:01Z"
	}
],
}

Using Conditional Logic Helpers along with Contains helpers

{: #conditional-contains-helpers}

{{#if (contains data.message "dev")}}
"color":"#1E90FF"
{{else if (contains ibmendefaultlong "prod")}}
"color":"#dc143c"
{{else}}
"color":"#097969"
{{/if}}

For loop to print each and every key value from array of map

{: #for-loop-1}

{
	{{#each data.secrets}}
	  {
	"type": "TextBlock",
	"text": "{{@key}}: {{this}}",
	"wrap": true
	},
	{{/each}}
}

For loop to print specific values from a array of map

{: #for-loop-2}

{{#each data.secrets}}
	{
	"secret_expiration": "{{secret_expiration}}",
	 "event_time": "{{event_time}}"
	 }
{{/each}}

Accessing value from payload where the key contains special chanracters

Payload:

"toolchain.tool-instance":{
	"name":"sample-date"
}

{: codeblock}

Accessing name:

{{[toolchain.tool-instance].name}}

{: codeblock}

To access the name value from a JSON payload where the key is "toolchain.tool-instance" , the syntax {{[toolchain.tool-instance].name}} is used because the key contains special characters and cannot directly be accessed with a dot notation.