Skip to content

Commit

Permalink
[Logs UI] Add timestamp as a context variable to log threshold alerts (
Browse files Browse the repository at this point in the history
…elastic#78932) (elastic#79632)

* Add timestamp context variable
  • Loading branch information
Kerry350 authored Oct 6, 2020
1 parent 963b0fd commit d851039
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,12 @@ type AlertInstanceUpdater = (

export const updateAlertInstance: AlertInstanceUpdater = (alertInstance, state, actions) => {
if (actions && actions.length > 0) {
const sharedContext = {
timestamp: new Date().toISOString(),
};
actions.forEach((actionSet) => {
const { actionGroup, context } = actionSet;
alertInstance.scheduleActions(actionGroup, context);
alertInstance.scheduleActions(actionGroup, { ...sharedContext, ...context });
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import {
import { InfraBackendLibs } from '../../infra_types';
import { decodeOrThrow } from '../../../../common/runtime_types';

const timestampActionVariableDescription = i18n.translate(
'xpack.infra.logs.alerting.threshold.timestampActionVariableDescription',
{
defaultMessage: 'UTC timestamp of when the alert was triggered',
}
);

const documentCountActionVariableDescription = i18n.translate(
'xpack.infra.logs.alerting.threshold.documentCountActionVariableDescription',
{
Expand Down Expand Up @@ -85,6 +92,7 @@ export async function registerLogThresholdAlertType(
executor: createLogThresholdExecutor(libs),
actionVariables: {
context: [
{ name: 'timestamp', description: timestampActionVariableDescription },
{ name: 'matchingDocuments', description: documentCountActionVariableDescription },
{ name: 'conditions', description: conditionsActionVariableDescription },
{ name: 'group', description: groupByActionVariableDescription },
Expand Down

0 comments on commit d851039

Please sign in to comment.