mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.16`: - [[Synthetics] Fix to handle ops genie as default connector !! (#201923)](https://github.com/elastic/kibana/pull/201923) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2024-12-02T19:20:26Z","message":"[Synthetics] Fix to handle ops genie as default connector !! (#201923)\n\n## Summary\r\n\r\nfixes https://github.com/elastic/kibana/issues/168681\r\n\r\nFix to handle ops genie as default connector !!\r\n\r\nTested by creating a trail account in ops genie \r\n\r\n<img width=\"1712\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ec768758-0fd3-4e3e-bb16-2bc11f10f6b7\">","sha":"a674b9d043faf58494feda039bb2a563c9f4d661","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","backport:prev-major","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[Synthetics] Fix to handle ops genie as default connector !!","number":201923,"url":"https://github.com/elastic/kibana/pull/201923","mergeCommit":{"message":"[Synthetics] Fix to handle ops genie as default connector !! (#201923)\n\n## Summary\r\n\r\nfixes https://github.com/elastic/kibana/issues/168681\r\n\r\nFix to handle ops genie as default connector !!\r\n\r\nTested by creating a trail account in ops genie \r\n\r\n<img width=\"1712\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ec768758-0fd3-4e3e-bb16-2bc11f10f6b7\">","sha":"a674b9d043faf58494feda039bb2a563c9f4d661"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201923","number":201923,"mergeCommit":{"message":"[Synthetics] Fix to handle ops genie as default connector !! (#201923)\n\n## Summary\r\n\r\nfixes https://github.com/elastic/kibana/issues/168681\r\n\r\nFix to handle ops genie as default connector !!\r\n\r\nTested by creating a trail account in ops genie \r\n\r\n<img width=\"1712\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ec768758-0fd3-4e3e-bb16-2bc11f10f6b7\">","sha":"a674b9d043faf58494feda039bb2a563c9f4d661"}}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
515bcb0d57
commit
3eeb9f17ee
5 changed files with 111 additions and 1 deletions
|
@ -291,4 +291,77 @@ describe('Alert Actions factory', () => {
|
|||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('generate expected action for email opsgenie connector', async () => {
|
||||
const resp = populateAlertActions({
|
||||
groupId: SYNTHETICS_MONITOR_STATUS.id,
|
||||
defaultActions: [
|
||||
{
|
||||
frequency: {
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
summary: false,
|
||||
throttle: null,
|
||||
},
|
||||
actionTypeId: '.opsgenie',
|
||||
group: 'xpack.synthetics.alerts.actionGroups.monitorStatus',
|
||||
params: {},
|
||||
id: 'f2a3b195-ed76-499a-805d-82d24d4eeba9',
|
||||
},
|
||||
] as unknown as ActionConnector[],
|
||||
defaultEmail: {
|
||||
to: ['test@email.com'],
|
||||
},
|
||||
translations: {
|
||||
defaultActionMessage: SyntheticsMonitorStatusTranslations.defaultActionMessage,
|
||||
defaultRecoveryMessage: SyntheticsMonitorStatusTranslations.defaultRecoveryMessage,
|
||||
defaultSubjectMessage: SyntheticsMonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage:
|
||||
SyntheticsMonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
});
|
||||
expect(resp).toEqual([
|
||||
{
|
||||
frequency: {
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
summary: false,
|
||||
throttle: null,
|
||||
},
|
||||
group: 'recovered',
|
||||
id: 'f2a3b195-ed76-499a-805d-82d24d4eeba9',
|
||||
params: {
|
||||
subAction: 'closeAlert',
|
||||
subActionParams: {
|
||||
alias: '{{rule.id}}:{{alert.id}}',
|
||||
description:
|
||||
'The alert for monitor "{{context.monitorName}}" from {{context.locationNames}} is no longer active: {{context.recoveryReason}}. - Elastic Synthetics\n\nDetails:\n\n- Monitor name: {{context.monitorName}} \n- {{context.monitorUrlLabel}}: {{{context.monitorUrl}}} \n- Monitor type: {{context.monitorType}} \n- From: {{context.locationNames}} \n- Last error received: {{{context.lastErrorMessage}}} \n{{{context.linkMessage}}}',
|
||||
message:
|
||||
'Monitor "{{context.monitorName}}" ({{context.locationNames}}) {{context.recoveryStatus}} - Elastic Synthetics',
|
||||
priority: 'P2',
|
||||
tags: ['{{rule.tags}}'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
frequency: {
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
summary: false,
|
||||
throttle: null,
|
||||
},
|
||||
group: 'xpack.synthetics.alerts.actionGroups.monitorStatus',
|
||||
id: 'f2a3b195-ed76-499a-805d-82d24d4eeba9',
|
||||
params: {
|
||||
subAction: 'createAlert',
|
||||
subActionParams: {
|
||||
alias: '{{rule.id}}:{{alert.id}}',
|
||||
description:
|
||||
'Monitor "{{context.monitorName}}" is {{{context.status}}} from {{context.locationNames}}.{{{context.pendingLastRunAt}}} - Elastic Synthetics\n\nDetails:\n\n- Monitor name: {{context.monitorName}} \n- {{context.monitorUrlLabel}}: {{{context.monitorUrl}}} \n- Monitor type: {{context.monitorType}} \n- Checked at: {{context.checkedAt}} \n- From: {{context.locationNames}} \n- Reason: {{{context.reason}}} \n- Error received: {{{context.lastErrorMessage}}} \n{{{context.linkMessage}}}',
|
||||
message:
|
||||
'Monitor "{{context.monitorName}}" ({{context.locationNames}}) is down - Elastic Synthetics',
|
||||
priority: 'P2',
|
||||
tags: ['{{rule.tags}}'],
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,10 +14,12 @@ import type {
|
|||
WebhookActionParams,
|
||||
EmailActionParams,
|
||||
SlackApiActionParams,
|
||||
OpsgenieActionParams,
|
||||
} from '@kbn/stack-connectors-plugin/server/connector_types';
|
||||
import { RuleAction as RuleActionOrig } from '@kbn/alerting-plugin/common';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { OpsgenieSubActions } from '@kbn/stack-connectors-plugin/common';
|
||||
import { ActionConnector, ActionTypeId } from './types';
|
||||
import { DefaultEmail } from '../runtime_types';
|
||||
|
||||
|
@ -31,6 +33,7 @@ export const SERVICE_NOW_ACTION_ID: ActionTypeId = '.servicenow';
|
|||
export const JIRA_ACTION_ID: ActionTypeId = '.jira';
|
||||
export const WEBHOOK_ACTION_ID: ActionTypeId = '.webhook';
|
||||
export const EMAIL_ACTION_ID: ActionTypeId = '.email';
|
||||
export const OPSGENIE_ACTION_ID: ActionTypeId = '.opsgenie';
|
||||
|
||||
export type RuleAction = Omit<RuleActionOrig, 'actionTypeId'>;
|
||||
|
||||
|
@ -128,6 +131,14 @@ export function populateAlertActions({
|
|||
actions.push(recoveredAction);
|
||||
}
|
||||
break;
|
||||
case OPSGENIE_ACTION_ID:
|
||||
// @ts-expect-error
|
||||
action.params = getOpsgenieActionParams(translations);
|
||||
// @ts-expect-error
|
||||
recoveredAction.params = getOpsgenieActionParams(translations, true);
|
||||
actions.push(recoveredAction);
|
||||
break;
|
||||
|
||||
default:
|
||||
action.params = {
|
||||
message: translations.defaultActionMessage,
|
||||
|
@ -293,3 +304,24 @@ function getEmailActionParams(
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getOpsgenieActionParams(
|
||||
{
|
||||
defaultActionMessage,
|
||||
defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage,
|
||||
defaultRecoveryMessage,
|
||||
}: Translations,
|
||||
isRecovery?: boolean
|
||||
): OpsgenieActionParams {
|
||||
return {
|
||||
subAction: isRecovery ? OpsgenieSubActions.CloseAlert : OpsgenieSubActions.CreateAlert,
|
||||
subActionParams: {
|
||||
alias: '{{rule.id}}:{{alert.id}}',
|
||||
tags: ['{{rule.tags}}'],
|
||||
message: isRecovery ? defaultRecoverySubjectMessage : defaultSubjectMessage,
|
||||
description: isRecovery ? defaultRecoveryMessage : defaultActionMessage,
|
||||
priority: 'P2',
|
||||
},
|
||||
} as OpsgenieActionParams;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import type {
|
|||
TeamsConnectorTypeId,
|
||||
WebhookConnectorTypeId,
|
||||
EmailConnectorTypeId,
|
||||
OpsgenieConnectorTypeId,
|
||||
} from '@kbn/stack-connectors-plugin/server/connector_types';
|
||||
|
||||
import type { ActionConnector as RawActionConnector } from '@kbn/triggers-actions-ui-plugin/public';
|
||||
|
@ -31,6 +32,7 @@ export type ActionTypeId =
|
|||
| typeof ServiceNowConnectorTypeId
|
||||
| typeof JiraConnectorTypeId
|
||||
| typeof WebhookConnectorTypeId
|
||||
| typeof EmailConnectorTypeId;
|
||||
| typeof EmailConnectorTypeId
|
||||
| typeof OpsgenieConnectorTypeId;
|
||||
|
||||
export type ActionConnector = Omit<RawActionConnector, 'secrets'> & { config?: SlackApiConfig };
|
||||
|
|
|
@ -63,6 +63,7 @@ export { ConnectorTypeId as WebhookConnectorTypeId } from './webhook';
|
|||
export type { ActionParamsType as WebhookActionParams } from './webhook/types';
|
||||
export { ConnectorTypeId as XmattersConnectorTypeId } from './xmatters';
|
||||
export type { ActionParamsType as XmattersActionParams } from './xmatters';
|
||||
export { OpsgenieConnectorTypeId } from './opsgenie';
|
||||
|
||||
export type {
|
||||
OpsgenieActionConfig,
|
||||
|
|
|
@ -39,6 +39,8 @@ export const getOpsgenieConnectorType = (): SubActionConnectorType<Config, Secre
|
|||
};
|
||||
};
|
||||
|
||||
export { OpsgenieConnectorTypeId };
|
||||
|
||||
export type {
|
||||
Config as OpsgenieActionConfig,
|
||||
Secrets as OpsgenieActionSecrets,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue