Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending alerts to zenduty using native api integration. #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ inputs:
description: 'Slack Webhook URL. More info: https://api.slack.com/messaging/webhooks'
pager_duty_integration_key:
description: 'Pager Duty Integration Key. More info: https://support.pagerduty.com/docs/services-and-integrations'
zenduty_api_key:
description: 'Create a Zenduty API Key by visiting Account Settings > API Keys'
zenduty_service_id:
description: 'Zenduty Service ID: https://docs.zenduty.com/docs/services'
zenduty_escalation_policy_id:
description: 'Zenduty Escalation Policy ID: https://docs.zenduty.com/docs/escalationpolicies'
zenduty_integration_key:
description: 'Zenduty native api integration key. More info: https://docs.zenduty.com/docs/api'
email_from:
description: 'Sender email'
email_list:
Expand Down
16 changes: 5 additions & 11 deletions src/destinations/zenduty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Alert } from '../entities'
import { request } from '../utils'

export const sendAlertsToZenduty = async (
apiKey: string,
serviceId: string,
escalationPolicyId: string,
zenDutyIntegrationKey: string,
alerts: Alert[],
): Promise<void> => {
let summary = `
Expand All @@ -29,17 +27,13 @@ export const sendAlertsToZenduty = async (
---
`
const payload = {
service: serviceId,
escalation_policy: escalationPolicyId,
title: `${ACTION_SHORT_SUMMARY} - ${alerts[0].repository.name}`,
urgency: 0,
summary,
alert_type: "critical",
message: `${ACTION_SHORT_SUMMARY} - ${alerts[0].repository.name}` ,
summary: summary,
}
const bearer = `Token ${apiKey}`
await request('https://www.zenduty.com/api/incidents/', {
await request('https://www.zenduty.com/api/events/${zenDutyIntegrationKey}/', {
method: 'POST',
headers: {
Authorization: bearer,
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
Expand Down
19 changes: 3 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ async function run(): Promise<void> {
const microsoftTeamsWebhookUrl = getInput('microsoft_teams_webhook')
const slackWebhookUrl = getInput('slack_webhook')
const pagerDutyIntegrationKey = getInput('pager_duty_integration_key')
const zenDutyApiKey = getInput('zenduty_api_key')
const zenDutyServiceId = getInput('zenduty_service_id')
const zenDutyEscalationPolicyId = getInput('zenduty_escalation_policy_id')
const zenDutyIntegrationKey= getInput('zenduty_integration_key')
const emailFrom = getInput('email_from')
const emailList = getInput('email_list')
const emailSubject = getInput('email_subject')
Expand Down Expand Up @@ -46,19 +44,8 @@ async function run(): Promise<void> {
if (pagerDutyIntegrationKey) {
await sendAlertsToPagerDuty(pagerDutyIntegrationKey, alerts)
}
if (zenDutyApiKey) {
if (zenDutyServiceId && zenDutyEscalationPolicyId) {
await sendAlertsToZenduty(
zenDutyApiKey,
zenDutyServiceId,
zenDutyEscalationPolicyId,
alerts,
)
} else {
setFailed(
new Error('Check your Zenduty Service ID and Escalation Policy ID'),
)
}
if (zenDutyIntegrationKey) {
await sendAlertsToZenduty(zenDutyIntegrationKey, alerts)
}
if (emailFrom && emailList) {
const emailWikiLink =
Expand Down