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

feat: keephq notification provider #4722

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
47 changes: 47 additions & 0 deletions server/notification-providers/keep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const FormData = require("form-data");
Copy link
Collaborator

Choose a reason for hiding this comment

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

(in general, not only this PR)

I think we can remove this dependency in v2.0, as we have upgraded to the minimum supported node version to 18:
image

Copy link
Contributor Author

@ezhil56x ezhil56x Apr 30, 2024

Choose a reason for hiding this comment

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

Removed this as it is no longer required


class Keep extends NotificationProvider {
name = "Keep";

/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

try {
let data = {
heartbeat: heartbeatJSON,
monitor: monitorJSON,
msg,
};
let config = {
headers: {
"x-api-key": notification.webhookAPIKey,
},
};

const formData = new FormData();
formData.append("data", JSON.stringify(data));
config.headers = formData.getHeaders();
data = formData;

let url = notification.webhookURL;

if (url.endsWith("/")) {
url = url.slice(0, -1);
}

let webhookURL = url + "/alert/events/uptimekuma";

await axios.post(webhookURL, data, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}

module.exports = Keep;
2 changes: 2 additions & 0 deletions server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 Keep = require("./notification-providers/keep");
const Kook = require("./notification-providers/kook");
const Line = require("./notification-providers/line");
const LineNotify = require("./notification-providers/linenotify");
Expand Down Expand Up @@ -95,6 +96,7 @@ class Notification {
new GrafanaOncall(),
new HomeAssistant(),
new HeiiOnCall(),
new Keep(),
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 @@ -123,6 +123,7 @@ export default {
"GrafanaOncall": "Grafana Oncall",
"HeiiOnCall": "Heii On-Call",
"HomeAssistant": "Home Assistant",
"Keep": "Keep",
"Kook": "Kook",
"line": "LINE Messenger",
"LineNotify": "LINE Notify",
Expand Down
52 changes: 52 additions & 0 deletions src/components/notifications/Keep.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="mb-3">
<label for="webhook-url" class="form-label">{{ $t("Host URL") }}</label>
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
<input
id="webhook-url"
v-model="$parent.notification.webhookURL"
type="url"
pattern="https?://.+"
class="form-control"
required
/>
</div>

<div class="mb-3">
<label for="webhook-apikey" class="form-label">{{ $t("API Key") }}</label>
<input
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
id="webhook-apikey"
v-model="$parent.notification.webhookAPIKey"
type="text"
class="form-control"
required
/>
</div>
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
</template>

<script>
export default {
computed: {
headersPlaceholder() {
return this.$t("Example:", [
`{
"Authorization": "Authorization Token"
}`,
]);
},
customBodyPlaceholder() {
return this.$t("Example:", [
`{
"Title": "Uptime Kuma Alert{% if monitorJSON %} - {{ monitorJSON['name'] }}{% endif %}",
"Body": "{{ msg }}"
}`
]);
}
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
},
};
</script>

<style lang="scss" scoped>
textarea {
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
min-height: 200px;
}
</style>
2 changes: 2 additions & 0 deletions src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import GrafanaOncall from "./GrafanaOncall.vue";
import GtxMessaging from "./GtxMessaging.vue";
import HomeAssistant from "./HomeAssistant.vue";
import HeiiOnCall from "./HeiiOnCall.vue";
import Keep from "./Keep.vue";
import Kook from "./Kook.vue";
import Line from "./Line.vue";
import LineNotify from "./LineNotify.vue";
Expand Down Expand Up @@ -82,6 +83,7 @@ const NotificationFormList = {
"GrafanaOncall": GrafanaOncall,
"HomeAssistant": HomeAssistant,
"HeiiOnCall": HeiiOnCall,
"Keep": Keep,
"Kook": Kook,
"line": Line,
"LineNotify": LineNotify,
Expand Down
Loading