-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Heii On-Call Notification Provider (#4485)
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 okMsg = "Sent Successfully."; | ||
const payload = heartbeatJSON || {}; | ||
|
||
const baseURL = await setting("primaryBaseURL"); | ||
if (baseURL && monitorJSON) { | ||
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id); | ||
} | ||
|
||
const config = { | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer " + notification.heiiOnCallApiKey, | ||
}, | ||
}; | ||
const heiiUrl = `https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/`; | ||
// docs https://heiioncall.com/docs#manual-triggers | ||
try { | ||
if (!heartbeatJSON) { | ||
// Testing or general notification like certificate expiry | ||
payload["msg"] = msg; | ||
await axios.post(heiiUrl + "alert", payload, config); | ||
return okMsg; | ||
} | ||
|
||
if (heartbeatJSON.status === DOWN) { | ||
await axios.post(heiiUrl + "alert", payload, config); | ||
return okMsg; | ||
} | ||
if (heartbeatJSON.status === UP) { | ||
await axios.post(heiiUrl + "resolve", payload, config); | ||
return okMsg; | ||
} | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = HeiiOnCall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<div class="mb-3"> | ||
<label for="heiioncall-apikey" class="form-label">{{ $t("API Key") }}<span | ||
style="color: red;" | ||
><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"> | ||
<template #documentation> | ||
<a href="https://heiioncall.com/docs" target="_blank">{{ $t("documentationOf", ["Heii On-Call"]) }}</a> | ||
</template> | ||
</i18n-t> | ||
</template> | ||
|
||
<script> | ||
import HiddenInput from "../HiddenInput.vue"; | ||
export default { | ||
components: { | ||
HiddenInput, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters