Using Dynamic Variables in Alarm Messages

Update an alarm in Monitoring to include values of alarm message parameters in messages.

How Dynamic Variables are Rendered

The value of an alarm message parameter is rendered in an alarm message when you insert the associated dynamic variable into supported fields. For example, enter the following as the alarm body:

{{severity}} alarm triggered because threshold got breached due to {{metricValues}} at {{timestamp}}

In the following image of an alarm message, the alarm body (Body) is rendered as: CRITICAL alarm triggered because threshold got breached due to [CpuUtilization[1m].mean():92] at 2023-08-15T19:51:00Z

Example of dynamic variables rendered in a formatted email message.

Dynamic variables appear in notifications that contain body elements.

  • If data is available for a dynamic variable, then the variable is resolved and data appears in its place. The previous example alarm message shows [CpuUtilization[1m].mean():92] in place of the dynamic variable {{metricValues}}.
  • If no data is available for a dynamic variable, then the variable is unresolved and it appears as coded. For example, if no metric values are available for the dynamic variable {{metricValues}}, such as when the alarm is in the OK state, then the dynamic variable {{metricValues}} appears in the alarm message.
  • SMS messages lack body elements, so dynamic variables aren't resolved.

Looking Up Dynamic Variables

To look up a dynamic variable for a parameter, see Dynamic Variables.

    1. Open the navigation menu and click Observability & Management. Under Monitoring, click Alarm Definitions.
    2. Click the name of the alarm that you want.
    3. On the alarm details page, click Actions and then select Edit alarm.
    4. On the Edit alarm page, find the field that you want to add dynamic variables to.
      • Alarm body (body alarm message parameter): Rendered as a field within the body of the alarm message.
      • Alarm summary (alarmSummary alarm message parameter): Rendered as a field within the body of the alarm message.
      • Notification subject (title alarm message parameter): Rendering depends on the type of message. For a formatted email message, renders as the subject line. For a Slack message, renders as the title. For an SMS message, renders as part of the message.

      For information about the default appearance of these alarm message parameters in formatted messages, see Alarm Message Format.

    5. Insert dynamic variables for the alarm message parameters that you want.

      Example with dynamic variables:

      {{severity}} alarm triggered because threshold got breached due to {{metricValues}} at {{timestamp}}

      To look up dynamic variables for a parameter, see Dynamic Variables.

      You can disable HTML escaping by using the longer dynamic variable for an alarm parameter. For example, to render the value of the query parameter in the alarm message with HTML escaping disabled, enter the dynamic variable {{{query}}}.

    6. Click Save alarm.
  • Use the oci monitoring alarm update command and required parameters to update an alarm to use dynamic variables in the field that you want:

    oci monitoring alarm update --alarm-summary <text-including-dynamic-variables> --body <text-including-dynamic-variables> --notification-title <text-including-dynamic-variables> [...]

    With line breaks:

    oci monitoring alarm update 
    --alarm-summary <text-including-dynamic-variables> 
    --body <text-including-dynamic-variables> 
    --notification-title <text-including-dynamic-variables> [...]

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Monitoring.

  • Run the UpdateAlarm operation to update an alarm to use the message format option that you want.

    When defining details for UpdateAlarmDetails, set the field that you want (alarmSummary, body, or notificationTitle) to the text that you want, including dynamic variables.