forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting] Adds navigation by consumer and alert type to alerting (el…
…astic#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
- Loading branch information
Showing
62 changed files
with
2,546 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Alerting Example | ||
|
||
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. | ||
|
||
To run this example, use the command `yarn start --run-examples`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export const ALERTING_EXAMPLE_APP_ID = 'AlertingExample'; | ||
|
||
// always firing | ||
export const DEFAULT_INSTANCES_TO_GENERATE = 5; | ||
|
||
// Astros | ||
export enum Craft { | ||
OuterSpace = 'Outer Space', | ||
ISS = 'ISS', | ||
} | ||
export enum Operator { | ||
AreAbove = 'Are above', | ||
AreBelow = 'Are below', | ||
AreExactly = 'Are exactly', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "alertingExample", | ||
"version": "0.0.1", | ||
"kibanaVersion": "kibana", | ||
"configPath": ["alerting_example"], | ||
"server": true, | ||
"ui": true, | ||
"requiredPlugins": ["triggers_actions_ui", "charts", "data", "alerting", "actions"], | ||
"optionalPlugins": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "alerting_example", | ||
"version": "1.0.0", | ||
"main": "target/examples/alerting_example", | ||
"kibana": { | ||
"version": "kibana", | ||
"templateVersion": "1.0.0" | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"kbn": "node ../../scripts/kbn.js", | ||
"build": "rm -rf './target' && tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "3.7.2" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
examples/alerting_example/public/alert_types/always_firing.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React, { Fragment } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiFieldNumber, EuiFormRow } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { AlertTypeModel } from '../../../../x-pack/plugins/triggers_actions_ui/public'; | ||
import { DEFAULT_INSTANCES_TO_GENERATE } from '../../common/constants'; | ||
|
||
interface AlwaysFiringParamsProps { | ||
alertParams: { instances?: number }; | ||
setAlertParams: (property: string, value: any) => void; | ||
errors: { [key: string]: string[] }; | ||
} | ||
|
||
export function getAlertType(): AlertTypeModel { | ||
return { | ||
id: 'example.always-firing', | ||
name: 'Always Fires', | ||
iconClass: 'bolt', | ||
alertParamsExpression: AlwaysFiringExpression, | ||
validate: (alertParams: AlwaysFiringParamsProps['alertParams']) => { | ||
const { instances } = alertParams; | ||
const validationResult = { | ||
errors: { | ||
instances: new Array<string>(), | ||
}, | ||
}; | ||
if (instances && instances < 0) { | ||
validationResult.errors.instances.push( | ||
i18n.translate('AlertingExample.addAlert.error.invalidRandomInstances', { | ||
defaultMessage: 'instances must be equal or greater than zero.', | ||
}) | ||
); | ||
} | ||
return validationResult; | ||
}, | ||
}; | ||
} | ||
|
||
export const AlwaysFiringExpression: React.FunctionComponent<AlwaysFiringParamsProps> = ({ | ||
alertParams, | ||
setAlertParams, | ||
}) => { | ||
const { instances = DEFAULT_INSTANCES_TO_GENERATE } = alertParams; | ||
return ( | ||
<Fragment> | ||
<EuiFlexGroup gutterSize="s" wrap direction="column"> | ||
<EuiFlexItem grow={true}> | ||
<EuiFormRow | ||
label="Random Instances to generate" | ||
helpText="How many randomly generated Alert Instances do you wish to activate on each alert run?" | ||
> | ||
<EuiFieldNumber | ||
name="instances" | ||
value={instances} | ||
onChange={event => { | ||
setAlertParams('instances', event.target.valueAsNumber); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</Fragment> | ||
); | ||
}; |
Oops, something went wrong.