mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use cloud notifier types for metadata on Cloud AMs (#91054)
This commit is contained in:
parent
ce8f5b5e1a
commit
1d96cd8ed9
@ -39,7 +39,7 @@ export const ContactPoint = ({
|
||||
const styles = useStyles2(getStyles);
|
||||
|
||||
// TODO probably not the best way to figure out if we want to show either only the summary or full metadata for the receivers?
|
||||
const showFullMetadata = receivers.some((receiver) => Boolean(receiver[RECEIVER_STATUS_KEY]));
|
||||
const showFullMetadata = receivers.some((receiver) => Boolean(receiver[RECEIVER_META_KEY]));
|
||||
|
||||
return (
|
||||
<div className={styles.contactPointWrapper} data-testid="contact-point">
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Receiver,
|
||||
generatedReceiversApi,
|
||||
} from 'app/features/alerting/unified/openapi/receiversApi.gen';
|
||||
import { cloudNotifierTypes } from 'app/features/alerting/unified/utils/cloud-alertmanager-notifier-types';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
|
||||
import { getNamespace, shouldUseK8sApi } from 'app/features/alerting/unified/utils/k8s/utils';
|
||||
|
||||
@ -175,7 +176,7 @@ export function useContactPointsWithStatus() {
|
||||
contactPoints: result.data
|
||||
? enhanceContactPointsWithMetadata(
|
||||
fetchContactPointsStatus.data,
|
||||
fetchReceiverMetadata.data,
|
||||
isGrafanaAlertmanager ? fetchReceiverMetadata.data : cloudNotifierTypes,
|
||||
onCallMetadata,
|
||||
result.data.alertmanager_config.receivers ?? [],
|
||||
result.data
|
||||
|
@ -34,13 +34,14 @@ export function getReceiverDescription(receiver: ReceiverConfigWithMetadata): Re
|
||||
if (!receiver.settings) {
|
||||
return undefined;
|
||||
}
|
||||
const { settings } = receiver;
|
||||
switch (receiver.type) {
|
||||
case 'email': {
|
||||
const hasEmailAddresses = 'addresses' in receiver.settings; // when dealing with alertmanager email_configs we don't normalize the settings
|
||||
return hasEmailAddresses ? summarizeEmailAddresses(receiver.settings['addresses']) : undefined;
|
||||
const addresses = settings.addresses || settings.to; // when dealing with alertmanager email_configs we don't normalize the settings
|
||||
return addresses ? summarizeEmailAddresses(addresses) : undefined;
|
||||
}
|
||||
case 'slack': {
|
||||
const recipient: string | undefined = receiver.settings['recipient'];
|
||||
const recipient = settings.recipient || settings.channel;
|
||||
if (!recipient) {
|
||||
return;
|
||||
}
|
||||
@ -50,12 +51,10 @@ export function getReceiverDescription(receiver: ReceiverConfigWithMetadata): Re
|
||||
return `#${channelName}`;
|
||||
}
|
||||
case 'kafka': {
|
||||
const topicName: string | undefined = receiver.settings['kafkaTopic'];
|
||||
return topicName;
|
||||
return settings.kafkaTopic;
|
||||
}
|
||||
case 'webhook': {
|
||||
const url: string | undefined = receiver.settings['url'];
|
||||
return url;
|
||||
return settings.url;
|
||||
}
|
||||
case ReceiverTypes.OnCall: {
|
||||
return receiver[RECEIVER_PLUGIN_META_KEY]?.description;
|
||||
@ -123,11 +122,7 @@ export function enhanceContactPointsWithMetadata(
|
||||
const usedContactPoints = getUsedContactPoints(fullyInheritedTree);
|
||||
const usedContactPointsByName = groupBy(usedContactPoints, 'receiver');
|
||||
|
||||
const contactPointsList = alertmanagerConfiguration
|
||||
? (alertmanagerConfiguration?.alertmanager_config.receivers ?? [])
|
||||
: (contactPoints ?? []);
|
||||
|
||||
const enhanced = contactPointsList.map((contactPoint) => {
|
||||
const enhanced = contactPoints.map((contactPoint) => {
|
||||
const receivers = extractReceivers(contactPoint);
|
||||
const statusForReceiver = status.find((status) => status.name === contactPoint.name);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { isEmpty, times } from 'lodash';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import { GrafanaManagedReceiverConfig, Receiver } from 'app/plugins/datasource/alertmanager/types';
|
||||
|
||||
@ -12,10 +12,14 @@ import { GrafanaManagedReceiverConfig, Receiver } from 'app/plugins/datasource/a
|
||||
* We don't normalize the configuration settings and those are blank for vanilla Alertmanager receivers.
|
||||
*
|
||||
* Example input:
|
||||
* { name: 'my receiver', email_configs: [{ from: "foo@bar.com" }] }
|
||||
* ```
|
||||
* { name: 'my receiver', email_configs: [{ from: "foo@bar.com" }] }
|
||||
* ```
|
||||
*
|
||||
* Example output:
|
||||
* { name: 'my receiver', grafana_managed_receiver_configs: [{ type: 'email', settings: {} }] }
|
||||
* ```
|
||||
* { name: 'my receiver', grafana_managed_receiver_configs: [{ type: 'email', settings: {} }] }
|
||||
* ```
|
||||
*/
|
||||
export function extractReceivers(receiver: Receiver): GrafanaManagedReceiverConfig[] {
|
||||
if ('grafana_managed_receiver_configs' in receiver) {
|
||||
@ -27,13 +31,14 @@ export function extractReceivers(receiver: Receiver): GrafanaManagedReceiverConf
|
||||
.filter(([_, value]) => Array.isArray(value) && !isEmpty(value))
|
||||
.reduce((acc: GrafanaManagedReceiverConfig[], [key, value]) => {
|
||||
const type = key.replace('_configs', '');
|
||||
|
||||
const configs = times(value.length, () => ({
|
||||
name: receiver.name,
|
||||
type: type,
|
||||
settings: [], // we don't normalize the configuration values
|
||||
disableResolveMessage: false,
|
||||
}));
|
||||
const configs = value.map((settings: unknown) => {
|
||||
return {
|
||||
name: receiver.name,
|
||||
type,
|
||||
settings,
|
||||
disableResolveMessage: false,
|
||||
};
|
||||
});
|
||||
|
||||
return acc.concat(configs);
|
||||
}, []);
|
||||
|
Loading…
Reference in New Issue
Block a user