Skip to content

Commit 2dd869f

Browse files
committed
[Alerting] Adds navigation by consumer and alert type to alerting (#58997)
Adds Navigation APIs to Alerting. Parts to this PR: Adds a client side (Public) plugin to Alerting, including two APIs: registerNavigation & registerDefaultNavigation. These allow a plugin to register navigation handlers for any alerts which it is the consumer of- one for specific AlertTypes and one for a default handler for all AlertTypes created by the plugin. The Alert Details page now uses these navigation handlers for the View In App button. If there's an AlertType specific handler it uses that, otherwise it uses a default one and if the consumer has not registered a handler - it remains disabled. A generic Alerting Example plugin that demonstrates usage of these APIs including two AlertTypes - one that always fires, and another that checks how many people are in Outer Space and allows you to trigger based on that. 😉 To enable the plugin run yarn start --ssl --run-examples
1 parent 038b956 commit 2dd869f

62 files changed

Lines changed: 2546 additions & 57 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Alerting Example
2+
3+
This example plugin shows you how to create a custom Alert Type, create alerts based on that type and corresponding UI for viewing the details of all the alerts within the custom plugin.
4+
5+
To run this example, use the command `yarn start --run-examples`.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export const ALERTING_EXAMPLE_APP_ID = 'AlertingExample';
21+
22+
// always firing
23+
export const DEFAULT_INSTANCES_TO_GENERATE = 5;
24+
25+
// Astros
26+
export enum Craft {
27+
OuterSpace = 'Outer Space',
28+
ISS = 'ISS',
29+
}
30+
export enum Operator {
31+
AreAbove = 'Are above',
32+
AreBelow = 'Are below',
33+
AreExactly = 'Are exactly',
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "alertingExample",
3+
"version": "0.0.1",
4+
"kibanaVersion": "kibana",
5+
"configPath": ["alerting_example"],
6+
"server": true,
7+
"ui": true,
8+
"requiredPlugins": ["triggers_actions_ui", "charts", "data", "alerting", "actions"],
9+
"optionalPlugins": []
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "alerting_example",
3+
"version": "1.0.0",
4+
"main": "target/examples/alerting_example",
5+
"kibana": {
6+
"version": "kibana",
7+
"templateVersion": "1.0.0"
8+
},
9+
"license": "Apache-2.0",
10+
"scripts": {
11+
"kbn": "node ../../scripts/kbn.js",
12+
"build": "rm -rf './target' && tsc"
13+
},
14+
"devDependencies": {
15+
"typescript": "3.7.2"
16+
}
17+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import React, { Fragment } from 'react';
21+
import { EuiFlexGroup, EuiFlexItem, EuiFieldNumber, EuiFormRow } from '@elastic/eui';
22+
import { i18n } from '@kbn/i18n';
23+
import { AlertTypeModel } from '../../../../x-pack/plugins/triggers_actions_ui/public';
24+
import { DEFAULT_INSTANCES_TO_GENERATE } from '../../common/constants';
25+
26+
interface AlwaysFiringParamsProps {
27+
alertParams: { instances?: number };
28+
setAlertParams: (property: string, value: any) => void;
29+
errors: { [key: string]: string[] };
30+
}
31+
32+
export function getAlertType(): AlertTypeModel {
33+
return {
34+
id: 'example.always-firing',
35+
name: 'Always Fires',
36+
iconClass: 'bolt',
37+
alertParamsExpression: AlwaysFiringExpression,
38+
validate: (alertParams: AlwaysFiringParamsProps['alertParams']) => {
39+
const { instances } = alertParams;
40+
const validationResult = {
41+
errors: {
42+
instances: new Array<string>(),
43+
},
44+
};
45+
if (instances && instances < 0) {
46+
validationResult.errors.instances.push(
47+
i18n.translate('AlertingExample.addAlert.error.invalidRandomInstances', {
48+
defaultMessage: 'instances must be equal or greater than zero.',
49+
})
50+
);
51+
}
52+
return validationResult;
53+
},
54+
};
55+
}
56+
57+
export const AlwaysFiringExpression: React.FunctionComponent<AlwaysFiringParamsProps> = ({
58+
alertParams,
59+
setAlertParams,
60+
}) => {
61+
const { instances = DEFAULT_INSTANCES_TO_GENERATE } = alertParams;
62+
return (
63+
<Fragment>
64+
<EuiFlexGroup gutterSize="s" wrap direction="column">
65+
<EuiFlexItem grow={true}>
66+
<EuiFormRow
67+
label="Random Instances to generate"
68+
helpText="How many randomly generated Alert Instances do you wish to activate on each alert run?"
69+
>
70+
<EuiFieldNumber
71+
name="instances"
72+
value={instances}
73+
onChange={event => {
74+
setAlertParams('instances', event.target.valueAsNumber);
75+
}}
76+
/>
77+
</EuiFormRow>
78+
</EuiFlexItem>
79+
</EuiFlexGroup>
80+
</Fragment>
81+
);
82+
};

0 commit comments

Comments
 (0)