Skip to content

Commit

Permalink
- Add support for Mattermost, OneSignal and PagerDuty
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Aschmann committed Jul 21, 2022
1 parent 2e30d70 commit d496036
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 0 deletions.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ Slack
SMTP
Mailgun
Matrix
Mattermost
Microsoft Teams
OneSignal
PagerDuty
Telegram
Webhook

Expand Down Expand Up @@ -391,6 +394,21 @@ In order to send notifications to Matrix, Reach requires the Homeserver Url, a a

<hr>

## Mattermost

```
required: {
mattermostWebhookUrl: "",
text: ""
},
optional: {}
```

#### Setup
In order to send notifications to Mattermost, you will need to enable incoming webhooks for your instance. You can do this from the Main Menu, under integrations. Copy the URL and use this in the mattermostWebhookUrl parameter.

<hr>

## Microsoft Teams

```
Expand All @@ -406,6 +424,51 @@ In order to receive notifications in MS Teams, you need to enable a incoming web

<hr>

## OneSignal

```
required: {
onesignalAppId: "",
onesignalApiKey: "",
text: ""
},
optional: {
title: ""
}
```

#### Setup
OneSignal requires that you create a setup a API Key.

<hr>


## PagerDuty

```
required: {
pagerDutyApiKey: "",
pagerDutyRoutingKey: "",
eventAction: "", (trigger, acknowldge or resolve)
source: "",
severity: "", (critical, warning, error or info)
text: ""
},
optional: {
dedup_key: "",
timestamp: "",
component: "",
group: "",
class: "",
custom_details: {}
}
```

#### Setup
To setup PagerDuty to work with Reach, you will need a Api Key and Routing Key (aka Integration Key). The Api Key can be found in the Integrations Menu, then API Access and Keys page. The Routng Key will be provided when you create a new Service, the service will need to haev the Events API v2 Integration selected, after creating you will be provided with the Routing/Integration key.

<hr>

## Webhook

```
Expand Down
32 changes: 32 additions & 0 deletions providers/mattermost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const provider = require("./provider");
const axios = require("axios");

class Slack extends provider {

name = "mattermost";

parameters = {
required: {
mattermostWebhookUrl: "",
text: ""
},
optional: {

}
};

async send(notification) {
try {
let data = {
"text": notification.required.text
};

await axios.post(notification.required.mattermostWebhookUrl, data);
return "Sent Successfully.";
} catch (err) {
return err;
}
}
}

module.exports = Slack;
47 changes: 47 additions & 0 deletions providers/onesignal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const provider = require("./provider");
const axios = require("axios");

class OneSignal extends provider {

name = "onesignal";

parameters = {
required: {
onesignalAppId: "",
onesignalApiKey: "",
playerId: "",
text: "",
subject: ""
},
optional: {}
};

async send(notification) {
try {
const serverUrl = "https://onesignal.com/api/v1/notifications";

const data = {
app_id: notification.required.onesignalAppId,
include_player_ids: [notification.required.playerId],
email_subject: notification.required.subject,
email_body: notification.required.text
};

let config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + notification.required.onesignalApiKey,
"Accept": "application/json",
}
};

await axios.post(serverUrl, JSON.stringify(data), config);

return "Sent Successfully.";
} catch (err) {
return err;
}
}
}

module.exports = OneSignal;
64 changes: 64 additions & 0 deletions providers/pagerduty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const provider = require("./provider");
const axios = require("axios");

class PagerDuty extends provider {

name = "pagerduty";

parameters = {
required: {
pagerDutyApiKey: "",
pagerDutyRoutingKey: "",
eventAction: "",
source: "",
severity: "",
text: "Test"
},
optional: {
dedup_key: "",
timestamp: "",
component: "",
group: "",
class: "",
custom_details: {}
}
};

async send(notification) {
try {
const serverUrl = "https://events.pagerduty.com/v2/enqueue";

const data = {
routing_key: notification.required.pagerDutyRoutingKey,
event_action: notification.required.eventAction,
... (notification.optional.dedup_key && { timestamp: notification.optional.dedup_key }),
payload: {
summary: notification.required.text,
source: notification.required.source,
severity: notification.required.severity,
... (notification.optional.timestamp && { timestamp: notification.optional.timestamp }),
... (notification.optional.component && { component: notification.optional.component }),
... (notification.optional.group && { group: notification.optional.group }),
... (notification.optional.class && { class: notification.optional.class }),
... (notification.optional.custom_details && { custom_details: notification.optional.custom_details })
}
};

let config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + notification.required.pagerDutyApiKey,
"Accept": "application/json",
}
};

await axios.post(serverUrl, JSON.stringify(data), config);

return "Sent Successfully.";
} catch (err) {
return err;
}
}
}

module.exports = PagerDuty;
8 changes: 8 additions & 0 deletions reach.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const Gitter = require("./providers/gitter");
const Ifttt = require("./providers/ifttt");
const Mailgun = require("./providers/mailgun");
const Matrix = require("./providers/matrix");
const Mattermost = require("./providers/mattermost");
const OneSignal = require("./providers/onesignal");
const PagerDuty = require("./providers/pagerduty");


class Reach {
providers = {};
Expand All @@ -31,6 +35,7 @@ class Reach {
this.providers["clicksendsms"] = new ClickSendSMS();
this.providers["line"] = new Line();
this.providers["teams"] = new Teams();
this.providers["googlechat"] = new GoogleChat();
this.providers["signal"] = new Signal();
this.providers["webhook"] = new Webhook();
this.providers["sendgrid"] = new SendGrid();
Expand All @@ -39,6 +44,9 @@ class Reach {
this.providers["ifttt"] = new Ifttt();
this.providers["mailgun"] = new Mailgun();
this.providers["matrix"] = new Matrix();
this.providers["mattermost"] = new Mattermost();
this.providers["onesignal"] = new OneSignal();
this.providers["pagerduty"] = new PagerDuty();
}

static async send(notification) {
Expand Down

0 comments on commit d496036

Please sign in to comment.