Ambari 2.0 leverages its own alerting system to convey the state of various aspects of managed clusters. The notification template content produced by Ambari is tightly coupled to a notification type. Email and SNMP both have customizable templates that can be used to generate content. This document describes the steps necessary to change the template used by Ambari 2.0 when creating alert notifications.
This procedure is targeted at Ambari Administrators that have access to the Ambari Server file system and the ambari.properties
file. Those Administrators can create new templates or change the existing templates that are used when generating alert notification content. At this time, there is no mechanism to expose this flexibility via the APIs or the web client to end users.
Alert Templates XML Location
By default, an alert-templates.xml ships with Ambari 2.0 bundled inside of Ambari Server JAR. 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 so the template is not exposed on the disk. But we can use that file as a reference example.
When you customize the alert template, you are effectively overriding the template bundled by default. To override the alert templates XML:
- On the Ambari Server host, browse to
/etc/ambari-server/conf
directory. - Edit the
ambari.properties
file. Add an entry for the location of your new template (that will override the default template).
alerts.template.file=/foo/var/alert-templates-custom.xml
- Save the file and restart Ambari Server.
Some alert notification types, such as EMAIL, automatically combine all pending alerts into a single outbound notification ("digest"). Others, like SNMP, never combine pending alerts and will always create a 1:1 notification for every alert in the system ("individual"). All alert notification types are specified in the same alert templates file, but the specific alert template for each notification type will most likely vary greatly.
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-templates> <alert-template type="EMAIL"> <subject> Subject Content </subject> <body> Body Content </body> </alert-template> <alert-template type="SNMP"> <subject> Subject Content </subject> <body> Body Content </body> </alert-template> </alert-templates>
Template Variables
The template uses Apache Velocity to render all tokenized content. The following variables are available for use in your template:
Variable | Description | Example |
---|---|---|
$summary.getTotalCount() |
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:
- Download the alert-templates.xml code as your starting point.
- On the Ambari Server, save the template to a location such as
/var/lib/ambari-server/resources/alert-templates-custom.xml
. - Edit the
alert-templates-custom.xml
file and modify the subject link for the<alert-template type="EMAIL">
template:
<subject> <![CDATA[Petstore Ambari has $summary.getTotalCount() alerts!]]> </subject>
- Save the file.
- Browse to
/etc/ambari-server/conf
directory. - Edit the
ambari.properties
file. Add an entry for the location of your new template file.
alerts.template.file=/var/lib/ambari-server/resources/alert-templates-custom.xml
- Save the file and restart Ambari Server.