Skip to content

Commit

Permalink
TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Nov 13, 2024
1 parent f6d1303 commit 96f2687
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import { selectMonitorListState } from '../../../state';
import { getDynamicSettingsAction } from '../../../state/settings/actions';
import { useSyntheticsSettingsContext } from '../../../contexts';
import { ConfigKey } from '../../../../../../common/runtime_types';
import { useActiveRules } from '../../monitors_page/overview/overview/use_active_rules';
import {
SYNTHETICS_STATUS_RULE,
SYNTHETICS_TLS_RULE,
} from '../../../../../../common/constants/synthetics_alerts';

export const AlertingCallout = ({ isAlertingEnabled }: { isAlertingEnabled?: boolean }) => {
const dispatch = useDispatch();
Expand All @@ -51,12 +56,43 @@ export const AlertingCallout = ({ isAlertingEnabled }: { isAlertingEnabled?: boo
return locator?.getUrl({});
}, [locator]);

const hasAlertingConfigured =
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);

const hasMonitorsRunningWithAlertingConfigured =
isAlertingEnabled ??
(monitorsLoaded &&
monitors.some((monitor) => monitor[ConfigKey.ALERT_CONFIG]?.status?.enabled));

const showCallout = !hasDefaultConnector && hasAlertingConfigured && defaultRuleEnabled;
const hasHttpMonitorsRunningWithAlertingEnabled =
monitorsLoaded &&
monitors.some(
(monitor) =>
monitor[ConfigKey.MONITOR_TYPE] === 'http' &&
monitor[ConfigKey.ALERT_CONFIG]?.status?.enabled &&
monitor[ConfigKey.ENABLED]
);
const showMonitorStatusCallout = !hasStatusRule && hasMonitorsRunningWithAlertingConfigured;
const showTlsCallout = !hasTls && hasHttpMonitorsRunningWithAlertingEnabled;
console.log('monitors', monitors);
console.log('has http monitors', hasHttpMonitorsRunningWithAlertingEnabled);

console.log('url', url);
const showCallout =
!hasDefaultConnector && hasMonitorsRunningWithAlertingConfigured && defaultRuleEnabled;
const hasDefaultRules =
!rulesLoaded || Boolean(defaultRules?.statusRule && defaultRules?.tlsRule);
const missingRules = !hasDefaultRules && !canSave;
Expand All @@ -65,13 +101,47 @@ export const AlertingCallout = ({ isAlertingEnabled }: { isAlertingEnabled?: boo
dispatch(getDynamicSettingsAction.get());
}, [dispatch]);

if (!showMonitorStatusCallout && !showTlsCallout) return null;
return (
<>
<MissingMonitorStatusRuleCallout showCallout={showMonitorStatusCallout} />
<MissingTlsCallout showCallout={showTlsCallout} />
</>
);
// return (
// <>
// <MissingRulesCallout
// url={url}
// missingConfig={Boolean(showCallout)}
// missingRules={missingRules}
// />
// <EuiSpacer size="m" />
// </>
// );
};

const MissingMonitorStatusRuleCallout = ({ showCallout }: { showCallout?: boolean }) => {
if (!showCallout) {
return null;
}
return (
<>
<EuiCallOut title="Alerts are not being sent" color="warning" iconType="warning">
You have Monitors enabled that are not covered by alerts
</EuiCallOut>
<EuiSpacer size="m" />
</>
);
};
const MissingTlsCallout = ({ showCallout }: { showCallout?: boolean }) => {
if (!showCallout) {
return null;
}
return (
<>
<MissingRulesCallout
url={url}
missingConfig={Boolean(showCallout)}
missingRules={missingRules}
/>
<EuiCallOut title="TLS Alerts are not being sent" color="warning" iconType="warning">
You have HTTP Monitors enabled that are not covered by TLS alerts
</EuiCallOut>
<EuiSpacer size="m" />
</>
);
Expand Down
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" />}
</>
);
}
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 ?? [] };
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SearchField } from '../common/search_field';
import { NoMonitorsFound } from '../common/no_monitors_found';
import { OverviewErrors } from './overview/overview_errors/overview_errors';
import { AlertingCallout } from '../../common/alerting_callout/alerting_callout';
import { AlertMissingCallout } from './overview/alert_missing_callout';

export const OverviewPage: React.FC = () => {
useTrackPageview({ app: 'synthetics', path: 'overview' });
Expand Down Expand Up @@ -76,6 +77,7 @@ export const OverviewPage: React.FC = () => {
<>
<DisabledCallout total={absoluteTotal} />
<AlertingCallout />
{/* <AlertMissingCallout /> */}
<EuiFlexGroup gutterSize="s" wrap={true}>
<EuiFlexItem>
<SearchField />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DefaultAlertService {
const interval = minimumIntervalInMs < defaultIntervalInMs ? '1m' : minimumInterval.value;
return interval;
}

setupStatusRule() {
const minimumRuleInterval = this.getMinimumRuleInterval();
if (this.settings?.defaultStatusRuleEnabled === false) {
Expand Down

0 comments on commit 96f2687

Please sign in to comment.