-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6d1303
commit 96f2687
Showing
5 changed files
with
170 additions
and
8 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
40 changes: 40 additions & 0 deletions
40
...blic/apps/synthetics/components/monitors_page/overview/overview/alert_missing_callout.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiCallOut } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { useActiveRules } from './use_active_rules'; | ||
import { | ||
SYNTHETICS_STATUS_RULE, | ||
SYNTHETICS_TLS_RULE, | ||
} from '../../../../../../../common/constants/synthetics_alerts'; | ||
|
||
export function AlertMissingCallout() { | ||
const { activeRules, activeRuleLoading } = useActiveRules(); | ||
console.log('active rules', activeRules, activeRuleLoading); | ||
|
||
if (!activeRules) { | ||
return null; | ||
} | ||
console.log('active rules', activeRules); | ||
const hasStatusRule = activeRules.some( | ||
(rule) => rule.rule_type_id === SYNTHETICS_STATUS_RULE && rule.enabled | ||
); | ||
const hasTls = activeRules.some( | ||
(rule) => rule.rule_type_id === SYNTHETICS_TLS_RULE && rule.enabled | ||
); | ||
console.log('has status rule', hasStatusRule); | ||
console.log('has tls rule', hasTls); | ||
return ( | ||
<> | ||
{!hasStatusRule && ( | ||
<EuiCallOut title="Status alert is missing" color="warning" iconType="alert" /> | ||
)} | ||
{!hasTls && <EuiCallOut title="TLS alert is missing" color="warning" iconType="alert" />} | ||
</> | ||
); | ||
} |
50 changes: 50 additions & 0 deletions
50
...ics/public/apps/synthetics/components/monitors_page/overview/overview/use_active_rules.ts
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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { useFetcher } from '@kbn/observability-shared-plugin/public'; | ||
import { ClientPluginsStart } from '../../../../../../plugin'; | ||
import { | ||
SYNTHETICS_STATUS_RULE, | ||
SYNTHETICS_TLS_RULE, | ||
} from '../../../../../../../common/constants/synthetics_alerts'; | ||
|
||
export function generateFilter(types: string[]) { | ||
if (types.length === 0) { | ||
return ''; | ||
} | ||
|
||
return types.reduce((acc, type) => { | ||
if (acc === '') { | ||
return `alert.attributes.alertTypeId: "${type}"`; | ||
} | ||
return `${acc} OR alert.attributes.alertTypeId: "${type}"`; | ||
}, ''); | ||
} | ||
|
||
interface RuleInfo { | ||
id: string; | ||
enabled: boolean; | ||
name: string; | ||
rule_type_id: string; | ||
} | ||
|
||
export function useActiveRules() { | ||
const { http } = useKibana<ClientPluginsStart>().services; | ||
|
||
const { data, loading } = useFetcher( | ||
() => | ||
http.get(`/internal/alerting/rules/_find`, { | ||
query: { | ||
filter: generateFilter([SYNTHETICS_TLS_RULE, SYNTHETICS_STATUS_RULE]), | ||
}, | ||
}), | ||
[http] | ||
); | ||
|
||
return { activeRuleLoading: loading, activeRules: (data as { data?: RuleInfo[] })?.data ?? [] }; | ||
} |
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
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