Apache Ambari Operations
Also available as:
loading table of contents...

Customizing Notification Templates

The notification template content produced by Ambari is tightly coupled to a notification type. Email and SNMP notifications both have customizable templates that you can use to generate content. This section describes the steps necessary to change the template used by Ambari when creating alert notifications.

Alert Templates XML Location

By default, an alert-templates.xml ships with Ambari,. This file contains all of the templates for every known type of notification (for example, EMAIL and SNMP). This file is bundled in the Ambari server .jar file so that the template is not exposed on the disk; however, that file is used in the following text, as a reference example.

When you customize the alert template, you are effectively overriding the default alert template's XML, as follows:

  1. On the Ambari server host, browse to /etc/ambari-server/conf directory.

  2. Edit the ambari.properties file.

  3. Add an entry for the location of your new template:


  4. Save the file and restart Ambari Server.

After you restart Ambari, any notification types defined in the new template override those bundled with Ambari. If you choose to provide your own template file, you only need to define notification templates for the types that you wish to override. If a notification template type is not found in the customized template, Ambari will default to the templates that ship with the JAR.

Alert Templates XML Structure

The structure of the template file is defined as follows. Each <alert-template> element declares what type of alert notification it should be used for.

  <alert-template type="EMAIL">
    Subject Content
    Body Content
  <alert-template type="SNMP">
    Subject Content
    Body Content

Template Variables

The template uses Apache Velocity to render all tokenized content. The following variables are available for use in your template:


The definition of which the alert is an instance.


The specific alert text.


The name of the alert.


The alert state (OK, WARNING, CRITICAL, or UNKNOWN)


The name of the service that the alert is defined for.


True if the alert is for a specific service component.


The component, if any, that the alert is defined for.


True if the alert was triggered for a specific host.


The hostname, if any, that the alert was triggered for.


The Ambari Server URL.


The Ambari Server version.


The Ambari Server hostname.


The notification target name.


The notification target description.


A list of all alerts for a given service or alert state (OK|WARNING|CRITICAL|UNKNOWN)


A list of all services for a given alert state (OK|WARNING|CRITICAL|UNKNOWN)


A list of all services that are reporting an alert in the notification.


The CRITICAL alert count.


The OK alert count.


The total alert count.


The UNKNOWN alert count.


The WARNING alert count.


A list of all of the alerts in the notification.

Example: Modify Alert EMAIL Subject

The following example illustrates how to change the subject line of all outbound email notifications to include a hard-coded identifier:

  1. Download the alert-templates.xml code as your starting point.

  2. On the Ambari Server, save the template to a location such as /var/lib/ambari-server/resources/alert-templates-custom.xml .

  3. Edit the alert-templates-custom.xml file and modify the subject link for the <alert-template type="EMAIL"> template:

     <![CDATA[Petstore Ambari has $summary.getTotalCount() alerts!]]>
  4. Save the file.

  5. Browse to /etc/ambari-server/conf directory.

  6. Edit the ambari.properties file.

  7. Add an entry for the location of your new template file.


  8. Save the file and restart Ambari Server.