Knowledge Base

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I customize variables in Apache Velocity Templates?

Table of Contents

Background

Variables

Sample Payloads for HTTP Request Templates

Additional Resources

 

Background

If you create health rule policies that trigger HTTP request actions or email notifications, you can use templates to customize the HTTP request or email message and render specific values when the action is triggered. These templates have a set of predefined variables that are processed using Apache Velocity Engine v1.7.

 

  • For HTTP request actions, templates describe the HTTP request. You can use variables that replace values in the URL path and payload when the HTTP request is sent.
  • For emails, you can use a template with variables to replace values in the body of the message.

 

You can configure custom variables if you need something beyond the predefined ones. This article provides examples of how you can use different Apache Velocity Template variables in HTTP request action and email templates.

 

Variables

The table below describes widely used Velocity variables to help you become more familiar with Velocity when you are customizing templates. A variable consists of a leading “$” followed by an identifier. It should look like this: $foo

 

Description Variable
A custom variable Usage: $foo
Set a variable #set ($message = "Hello")
If statement

#if ($message == "Hello")

 Message received and is "Hello"

#end

Replace HTML tags #set( $sm = $sm.replace("<b>", "[") )
Escape characters $esc.java(${latestEvent.summaryMessage})
Get the first element from an Array/List

${latestEvent.affectedEntities[0].name}

${latestEvent.affectedEntities[0].entityTypeDisplayName}

Loop through an Array/List #foreach( ${entity} in ${latestEvent.affectedEntities} )${entity.name}#if( $foreach.hasNext ),#end#end
Split #set ($summary = ${latestEvent.summaryMessage})
#set ($job = $summary.split(" "))
summary: $summary
Job: $job[2]
Job2: $job.get(2)
Replace #set( $sm = $!{latestEvent.summaryMessage.replace('"',"*")} )
#set( $sm = $sm.replace("<b>", "[") )
#set( $sm = $sm.replace("</b>", "]") )
#set( $sm = $sm.replace("<br>", " ") )

 

Sample Payloads for HTTP Request Templates 

Attached to this article are three sample payloads for HTTP request templates. 

  • Hipchat
  • Slack
  • ServiceNow

 

Additional Resources

Version history
Revision #:
3 of 3
Last update:
‎03-29-2019 04:46 PM
Updated by:
 


Found this article helpful? Click the Thumbs Up button.
Have an additional comment? Post it below.