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

Add Heii On-Call Notification Provider #4485

Merged
Show file tree
Hide file tree
Changes from 13 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
67 changes: 67 additions & 0 deletions server/notification-providers/heii-oncall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class HeiiOnCall extends NotificationProvider {
name = "HeiiOnCall";

/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const payload = heartbeatJSON || {};

const baseURL = await setting("primaryBaseURL");
if (baseURL && monitorJSON) {
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
}

try {
if (!heartbeatJSON) {
// Testing or general notification like certificate expiry
payload["msg"] = msg;
return this.postNotification(notification, "alert", payload);
}

if (heartbeatJSON.status === DOWN) {
return this.postNotification(notification, "alert", payload);
}

if (heartbeatJSON.status === UP) {
return this.postNotification(notification, "resolve", payload);
}
} catch (error) {
this.throwGeneralAxiosError(error);
}

}

/**
* Post to Heii On-Call
* @param {BeanModel} notification Message title
* @param {string} action Trigger action (alert, resovle)
* @param {object} payload Data for Heii On-Call
* @returns {Promise<string>} Success message
*/
async postNotification(notification, action, payload) {
const config = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + notification.heiiOnCallApiKey,
},
};

// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
await axios.post(
`https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/${action}`,
payload,
config
);

return "Sent Successfully";
}
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}

module.exports = HeiiOnCall;
2 changes: 2 additions & 0 deletions server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Gorush = require("./notification-providers/gorush");
const Gotify = require("./notification-providers/gotify");
const GrafanaOncall = require("./notification-providers/grafana-oncall");
const HomeAssistant = require("./notification-providers/home-assistant");
const HeiiOnCall = require("./notification-providers/heii-oncall");
const Kook = require("./notification-providers/kook");
const Line = require("./notification-providers/line");
const LineNotify = require("./notification-providers/linenotify");
Expand Down Expand Up @@ -87,6 +88,7 @@ class Notification {
new Gotify(),
new GrafanaOncall(),
new HomeAssistant(),
new HeiiOnCall(),
new Kook(),
new Line(),
new LineNotify(),
Expand Down
1 change: 1 addition & 0 deletions src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
"gorush": "Gorush",
"gotify": "Gotify",
"GrafanaOncall": "Grafana Oncall",
"HeiiOnCall": "Heii On-Call",
"HomeAssistant": "Home Assistant",
"Kook": "Kook",
"line": "LINE Messenger",
Expand Down
32 changes: 32 additions & 0 deletions src/components/notifications/HeiiOnCall.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="mb-3">
<label for="heiioncall-apikey" class="form-label">{{ $t("API Key") }}<span
style="color: red;"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General note (not for this PR to fix ^^)
I really don't like that this has to be done. This is way more error prawn tan necessary.

><sup>*</sup></span></label>
<HiddenInput
id="heiioncall-apikey" v-model="$parent.notification.heiiOnCallApiKey" required="true"
autocomplete="false"
></HiddenInput>
</div>
<div class="mb-3">
<label for="heiioncall-trigger-id" class="form-label">Trigger ID<span
style="color: red;"
><sup>*</sup></span></label>
<HiddenInput
id="heiioncall-trigger-id" v-model="$parent.notification.heiiOnCallTriggerId" required="true"
autocomplete="false"
></HiddenInput>
</div>
<i18n-t tag="p" keypath="wayToGetHeiiOnCallDetails" class="form-text mt-3">
<a href="https://heiioncall.com/docs" target="_blank">{{ $t("documentationOf", ["Heii On-Call"]) }}</a>
hevans66 marked this conversation as resolved.
Show resolved Hide resolved
</i18n-t>
</template>

<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
};
</script>
2 changes: 2 additions & 0 deletions src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Gorush from "./Gorush.vue";
import Gotify from "./Gotify.vue";
import GrafanaOncall from "./GrafanaOncall.vue";
import HomeAssistant from "./HomeAssistant.vue";
import HeiiOnCall from "./HeiiOnCall.vue";
import Kook from "./Kook.vue";
import Line from "./Line.vue";
import LineNotify from "./LineNotify.vue";
Expand Down Expand Up @@ -74,6 +75,7 @@ const NotificationFormList = {
"gotify": Gotify,
"GrafanaOncall": GrafanaOncall,
"HomeAssistant": HomeAssistant,
"HeiiOnCall": HeiiOnCall,
"Kook": Kook,
"line": Line,
"LineNotify": LineNotify,
Expand Down
4 changes: 3 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -883,5 +883,7 @@
"deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?",
"GrafanaOncallUrl": "Grafana Oncall URL",
"Browser Screenshot": "Browser Screenshot",
"What is a Remote Browser?": "What is a Remote Browser?"
"What is a Remote Browser?": "What is a Remote Browser?",
"wayToGetHeiiOnCallDetails": "How to get the Tigger ID and API Keys is explained in the {0}",
hevans66 marked this conversation as resolved.
Show resolved Hide resolved
"documentationOf": "{0} Documentation"
}
Loading