Incident Message and Email Templates

The Policy Template Language makes it possible to use text templates to define the content of messages shown to users when an incident is created both in the UI and in emails.

Templates have access to the escalation data via the built-in data function. They also have access to the policy template parameter values via the parameters function. Other functions listed below provide access to contextual information such as the Flexera organization and project. The output of the template is interpreted as markdown before being rendered into HTML. For details, see the Text Template Syntax Overview.

The complete list of functions available to templates is:

data—The policy escalation data.
parameters—The applied policy parameter values as a hash.
rs_governance_host—Returns the Flexera Automation endpoints.
rs_org_id—The Flexera organization ID where the policy is applied.
rs_org_name—The Flexera organization name where the policy is applied.
rs_project_id—The Flexeraproject ID where the policy is applied.
rs_project_name—The Flexera project name where the policy is applied.
rs_ss_host—The Flexera Self-Service API hostname.
rs_optima_host—The Flexera Cloud Cost Optiization API hostname.

Text Template Syntax Overview

Control structures in templates are delimited by {{ and }}. For example the following template:

"Project {{ rs_project_id }}: {{ rs_project_name }}"

produces Project 123: foo where 123 is the ID of the RightScale project, and foo is its name.

If a control structure left delimiter is followed immediately by a minus sign and space character ({{-), all trailing white space is trimmed from the immediately preceding text. Similarly, if the right delimiter is preceded by a space and minus sign (-}}), all leading white space is trimmed from the immediately following text. The following template produces the same output as the previous one:

<<EOS

Project

  {{- rs_project_id }}:

  {{- rs_project_name }}

EOS

Elements of an object or hash are accessed using ., for example the following prints the value of the field name in the escalation data:

"{{ data.name }}"

If the escalation data is an array then the values can be iterated over using the function range:

<<EOS

{{ range data -}}

* "{{ .name }}"

{{ end -}}

EOS

Note how the fields of the current element are accessed using .<name-of-field>. range supports an alternative syntax that makes it possible to access the index and the current element explicitly:

<<EOS

{{ $index, $elem := range data -}}

{{ $index }}. "{{ $elem.name }}"

{{ end -}}

EOS

You may want to include your result in a table. Below is an example how to build a table from the data array.

# If a value is passed as first parameter of export, we'll extract that subpath into a table. 

export "reportData" do 

  # resource_level is false by default 

  # if true, there must be an "id" field and it must be unique 

  resource_level true 

  field "id" do 

    # label is for display purposes, if left blank the field name (in this case "id") will be used 

    label "Billing Center ID" 

  end 

  field "name" do 

    label "Billing Center Name" 

  end 

  field "budget" do 

    label "Budget" 

  end 

  field "actual" do 

    label "Month to Date Spend" 

    # format tells the UI how the field should be displayed. It can be semantic 

    format "currency" 

    # or css style directive 

    format "right $%.2f" 

  end 

end 

You can format the incident fields as hyperlinks in the incident export table. The following are the supported hyperlink formats:

link-internal—Indicates that the incident field contains a link to a page in Flexera One. Clicking the link opens the page in the current tab.

Note:To open the link in a new tab, select the Ctrl key, and then click the link. Or, select the Ctrl key, right-click the link and select the Open link in new tab option.

link-external—Indicates that the incident field contains a link to a page on an external system. Clicking the link opens the page in a new tab.

You can provide a display name for the hyperlink within the incident field value, separated from the URL by the delimiter (||). Adding the display name provides additional context for the linked information.

Example:

Consider the following definition of the incident field for product:

  field "product" do

    label "New Product"

    format "link-external"

  end

In this example, the incident field "product" is configured to be displayed as a hyperlink with a link-external format. The actual value of the field is specified as follows:

"product": "CentOS 7.5||https://my-company.com"

The rendered hyperlink displays the name CentOS 7.5 and links to the provided URL https://my-company.com.

Control structures may also test the value of data for conditional output, for example:

<<EOS

{{- if .data.email }}

Email: {{ data.email }}

{{- end }}

EOS

A condition is true if it evaluates to anything other than false, 0, an empty string, array or data structure. There is also a set of binary comparison operators defined as functions:

eq returns true if arg1 == arg2
ne returns true if arg1 != arg2
lt returns true if arg1 < arg2
le returns true if arg1 <= arg2
gt returns true if arg1 > arg2
ge returns true if arg1 >= arg2