[Logs UI] Add timestamp as a context variable to log threshold alerts (#78932)

* Add timestamp context variable
This commit is contained in:
Kerry Gallagher 2020-10-06 11:12:20 +01:00 committed by GitHub
parent 08a4586b14
commit 2ba729f904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

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

View file

@ -13,6 +13,13 @@ import {
import { InfraBackendLibs } from '../../infra_types'; import { InfraBackendLibs } from '../../infra_types';
import { decodeOrThrow } from '../../../../common/runtime_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( const documentCountActionVariableDescription = i18n.translate(
'xpack.infra.logs.alerting.threshold.documentCountActionVariableDescription', 'xpack.infra.logs.alerting.threshold.documentCountActionVariableDescription',
{ {
@ -85,6 +92,7 @@ export async function registerLogThresholdAlertType(
executor: createLogThresholdExecutor(libs), executor: createLogThresholdExecutor(libs),
actionVariables: { actionVariables: {
context: [ context: [
{ name: 'timestamp', description: timestampActionVariableDescription },
{ name: 'matchingDocuments', description: documentCountActionVariableDescription }, { name: 'matchingDocuments', description: documentCountActionVariableDescription },
{ name: 'conditions', description: conditionsActionVariableDescription }, { name: 'conditions', description: conditionsActionVariableDescription },
{ name: 'group', description: groupByActionVariableDescription }, { name: 'group', description: groupByActionVariableDescription },