Skip to content

Commit

Permalink
[7.x] Add timestamp context variable (#67482) (#69250)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
phillipb and elasticmachine authored Jun 16, 2020
1 parent 2bdd46a commit 8c91475
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { mapValues, first } from 'lodash';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { InfraDatabaseSearchResponse } from '../../adapters/framework/adapter_types';
import { createAfterKeyHandler } from '../../../utils/create_afterkey_handler';
import { getAllCompositeData } from '../../../utils/get_all_composite_data';
Expand Down Expand Up @@ -336,6 +337,7 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs, alertId: s
group,
alertState: stateToAlertMessage[nextState],
reason,
timestamp: moment().toISOString(),
value: mapToConditionsLookup(alertResults, (result) => result[group].currentValue),
threshold: mapToConditionsLookup(criteria, (c) => c.threshold),
metric: mapToConditionsLookup(criteria, (c) => c.metric),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
}
);

const timestampActionVariableDescription = i18n.translate(
'xpack.infra.metrics.alerting.threshold.alerting.timestampDescription',
{
defaultMessage: 'A timestamp of when the alert was detected.',
}
);

const valueActionVariableDescription = i18n.translate(
'xpack.infra.metrics.alerting.threshold.alerting.valueActionVariableDescription',
{
Expand Down Expand Up @@ -106,6 +113,7 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
{ name: 'group', description: groupActionVariableDescription },
{ name: 'alertState', description: alertStateActionVariableDescription },
{ name: 'reason', description: reasonActionVariableDescription },
{ name: 'timestamp', description: timestampActionVariableDescription },
{ name: 'value', description: valueActionVariableDescription },
{ name: 'metric', description: metricActionVariableDescription },
{ name: 'threshold', description: thresholdActionVariableDescription },
Expand Down

0 comments on commit 8c91475

Please sign in to comment.