Monitor Variables

Use the monitor variables to add context and details to action messages for troubleshooting

When you create an action for a monitor, the message should be clear about the problem, condition, and affected resources. The message of an action supports standard Mustache scripting to form the content. The following tables list a variety of monitoring variables that you can include to enrich the message with information from the indexed data, monitor, and triggering condition to help the alert consumer quickly understand the problem.

👍

How to access ctx.results fields

If you want to use the ctx.results variable (or any array field) in a message, use {{ctx.results.0}} rather than {{ctx.results[0]}}. This difference relates to the way in which Mustache handles bracket notation.

Similarly, to reference a field inside the hits array, use a notation such as {{ctx.results.0.hits.hits.0.field_name}} to use the field's value for messages.

Monitor Variables

VariableData TypeDescription
ctx.monitorObjectIncludes ctx.monitor.name, ctx.monitor.type, ctx.monitor.enabled, ctx.monitor.enabled_time, ctx.monitor.schedule, ctx.monitor.inputs, triggers and ctx.monitor.last_update_time
ctx.monitor.userObjectIncludes information about the user who created the monitor. Includes ctx.monitor.user.backend_roles and ctx.monitor.user.roles, which are arrays that contain the backend roles and roles assigned to the user.
ctx.monitor.enabledBooleanWhether the monitor is enabled
ctx.monitor.enabled_timeMillisecondsUnix epoch time of when the monitor was last enabled
ctx.monitor.scheduleObjectContains a schedule of how often or when the monitor should run
ctx.monitor.schedule.period.intervalIntegerThe interval at which the monitor runs
ctx.monitor.schedule.period.unitStringThe interval’s unit of time
ctx.monitor.inputsArrayAn array that contains the indexes and definition used to create the monitor
ctx.monitor.inputs.search.indicesArrayAn array that contains the indexes the monitor observes
ctx.monitor.inputs.search.queryN/AThe definition used to define the monitor

Trigger Variables

VariableData TypeDescription
ctx.trigger.idStringThe trigger’s ID
ctx.trigger.nameStringThe trigger’s name
ctx.trigger.severityStringThe trigger’s severity
ctx.trigger.conditionObjectThe trigger condition and Painless script label for the monitor
ctx.trigger.condition.script.sourceStringThe script that defines the trigger
ctx.trigger.condition.script.langStringThe language used to define the script. Must be painless
ctx.trigger.actionsArrayAn array with one element that contains information about the action for the trigger and monitor

Action Variables

VariableData TypeDescription
ctx.trigger.actions.idStringThe action’s ID
ctx.trigger.actions.nameStringThe action’s name
ctx.trigger.actions.message_template.sourceStringThe message to send in the alert
ctx.trigger.actions.message_template.langStringThe scripting language used to define the message (mustache)
ctx.trigger.actions.throttle_enabledBooleanWhether throttling is enabled for this trigger
ctx.trigger.actions.subject_template.sourceStringThe message’s subject in the alert
ctx.trigger.actions.subject_template.langStringThe scripting language used to define the subject (mustache)

Other Variables

VariableData TypeDescription
ctx.resultsArrayAn array with one element (i.e. ctx.results[0]). Contains the query results. This variable is empty if the trigger was unable to retrieve results. See ctx.error.
ctx.last_update_timeMillisecondsUnix epoch time of when the monitor was last updated
ctx.periodStartStringUnix timestamp for the beginning of the period during which the alert triggered. For example, if a monitor runs every ten minutes, a period might begin at 10:40 and end at 10:50.
ctx.periodEndStringThe end of the period during which the alert triggered
ctx.errorStringThe error message if the trigger was unable to retrieve results or unable to evaluate the trigger, typically due to a compile error or null pointer exception. Null otherwise.
ctx.alertObjectThe current, active alert (if it exists). Includes ctx.alert.id, ctx.alert.version, and ctx.alert.isAcknowledged. Null if no alert is active. Only available with query-level monitors.
ctx.dedupedAlertsObjectAlerts that have already been triggered. OpenSearch keeps the existing alert to prevent the plugin from creating endless amounts of the same alerts. Only available with bucket-level monitors.
ctx.newAlertsObjectNewly created alerts. Only available with bucket-level monitors.
ctx.completedAlertsObjectAlerts that are no longer ongoing. Only available with bucket-level monitors.
bucket_keysStringComma-separated list of the monitor’s bucket key values. Available only for ctx.dedupedAlerts, ctx.newAlerts, and ctx.completedAlerts. Accessed through ctx.dedupedAlerts[0].bucket_keys.
parent_bucket_pathStringThe parent bucket path of the bucket that triggered the alert. Accessed through ctx.dedupedAlerts[0].parent_bucket_path.