mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Add context variables for metric, value and threshold with descriptions * Remove timestamp from this PR * sentences are hard * Fix lint rules * Add more usage examples Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
32331f21f9
commit
a3505d3d97
2 changed files with 41 additions and 0 deletions
|
@ -336,6 +336,9 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs, alertId: s
|
|||
group,
|
||||
alertState: stateToAlertMessage[nextState],
|
||||
reason,
|
||||
value: mapToConditionsLookup(alertResults, (result) => result[group].currentValue),
|
||||
threshold: mapToConditionsLookup(criteria, (c) => c.threshold),
|
||||
metric: mapToConditionsLookup(criteria, (c) => c.metric),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -352,3 +355,14 @@ export const FIRED_ACTIONS = {
|
|||
defaultMessage: 'Fired',
|
||||
}),
|
||||
};
|
||||
|
||||
const mapToConditionsLookup = (
|
||||
list: any[],
|
||||
mapFn: (value: any, index: number, array: any[]) => unknown
|
||||
) =>
|
||||
list
|
||||
.map(mapFn)
|
||||
.reduce(
|
||||
(result: Record<string, any>, value, i) => ({ ...result, [`condition${i}`]: value }),
|
||||
{}
|
||||
);
|
||||
|
|
|
@ -55,6 +55,30 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
|
|||
}
|
||||
);
|
||||
|
||||
const valueActionVariableDescription = i18n.translate(
|
||||
'xpack.infra.metrics.alerting.threshold.alerting.valueActionVariableDescription',
|
||||
{
|
||||
defaultMessage:
|
||||
'The value of the metric in the specified condition. Usage: (ctx.value.condition0, ctx.value.condition1, etc...).',
|
||||
}
|
||||
);
|
||||
|
||||
const metricActionVariableDescription = i18n.translate(
|
||||
'xpack.infra.metrics.alerting.threshold.alerting.metricActionVariableDescription',
|
||||
{
|
||||
defaultMessage:
|
||||
'The metric name in the specified condition. Usage: (ctx.metric.condition0, ctx.metric.condition1, etc...).',
|
||||
}
|
||||
);
|
||||
|
||||
const thresholdActionVariableDescription = i18n.translate(
|
||||
'xpack.infra.metrics.alerting.threshold.alerting.thresholdActionVariableDescription',
|
||||
{
|
||||
defaultMessage:
|
||||
'The threshold value of the metric for the specified condition. Usage: (ctx.threshold.condition0, ctx.threshold.condition1, etc...).',
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
id: METRIC_THRESHOLD_ALERT_TYPE_ID,
|
||||
name: 'Metric threshold',
|
||||
|
@ -82,6 +106,9 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
|
|||
{ name: 'group', description: groupActionVariableDescription },
|
||||
{ name: 'alertState', description: alertStateActionVariableDescription },
|
||||
{ name: 'reason', description: reasonActionVariableDescription },
|
||||
{ name: 'value', description: valueActionVariableDescription },
|
||||
{ name: 'metric', description: metricActionVariableDescription },
|
||||
{ name: 'threshold', description: thresholdActionVariableDescription },
|
||||
],
|
||||
},
|
||||
producer: 'metrics',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue