mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-18 12:14:41 -05:00
Apply suggestions from code review
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
parent
673f9a7744
commit
4cdc8f344b
@ -3,9 +3,6 @@ const { setting } = require("../util-server");
|
|||||||
|
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
|
||||||
const heiiOnCallBaseUrl = "https://heiioncall.com";
|
|
||||||
|
|
||||||
class HeiiOnCall extends NotificationProvider {
|
class HeiiOnCall extends NotificationProvider {
|
||||||
name = "HeiiOnCall";
|
name = "HeiiOnCall";
|
||||||
|
|
||||||
@ -13,28 +10,24 @@ class HeiiOnCall extends NotificationProvider {
|
|||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
// Payload to Heii On-Call is the entire heartbat JSON
|
const payload = heartbeatJSON || {};
|
||||||
const payload = heartbeatJSON ? heartbeatJSON : {};
|
|
||||||
|
|
||||||
// If we can, add url back to monitor to payload
|
|
||||||
const baseURL = await setting("primaryBaseURL");
|
const baseURL = await setting("primaryBaseURL");
|
||||||
if (baseURL && monitorJSON) {
|
if (baseURL && monitorJSON) {
|
||||||
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!heartbeatJSON) {
|
if (!heartbeatJSON) {
|
||||||
// No heartbeatJSON. Could be test button, but not necessarily. Just pull msg into payload.
|
// Testing or general notification like certificate expiry
|
||||||
payload["msg"] = msg;
|
payload["msg"] = msg;
|
||||||
return this.postNotification(notification, "alert", payload);
|
return this.postNotification(notification, "alert", payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON.status === DOWN) {
|
if (heartbeatJSON.status === DOWN) {
|
||||||
// Monitor is DOWN, alert on Heii On-Call
|
|
||||||
return this.postNotification(notification, "alert", payload);
|
return this.postNotification(notification, "alert", payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON.status === UP) {
|
if (heartbeatJSON.status === UP) {
|
||||||
// Monitor is UP, resolve on Heii On-Call
|
|
||||||
return this.postNotification(notification, "resolve", payload);
|
return this.postNotification(notification, "resolve", payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +51,7 @@ class HeiiOnCall extends NotificationProvider {
|
|||||||
// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
|
// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
|
||||||
try {
|
try {
|
||||||
await axios.post(
|
await axios.post(
|
||||||
`${heiiOnCallBaseUrl}/triggers/${notification.heiiOnCallTriggerId}/${action}`,
|
`https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/${action}`,
|
||||||
payload,
|
payload,
|
||||||
config
|
config
|
||||||
);
|
);
|
||||||
@ -66,7 +59,7 @@ class HeiiOnCall extends NotificationProvider {
|
|||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Heii On-Call post sent successfully.";
|
return "Sent Successfully";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-text">
|
<div class="form-text">
|
||||||
<i18n-t tag="p" keypath="wayToGetHeiiOnCallDetails" style="margin-top: 8px;">
|
<i18n-t tag="p" keypath="wayToGetHeiiOnCallDetails" style="margin-top: 8px;">
|
||||||
<a href="https://heiioncall.com/docs" target="_blank">Heii On-Call Documentation</a>
|
<a href="https://heiioncall.com/docs" target="_blank">{{ $t("documentationOf", ["Heii On-Call"]) }}</a>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -885,5 +885,5 @@
|
|||||||
"Browser Screenshot": "Browser Screenshot",
|
"Browser Screenshot": "Browser Screenshot",
|
||||||
"What is a Remote Browser?": "What is a Remote Browser?",
|
"What is a Remote Browser?": "What is a Remote Browser?",
|
||||||
"Trigger ID": "Trigger ID",
|
"Trigger ID": "Trigger ID",
|
||||||
"wayToGetHeiiOnCallDetails": "To get a Heii On-Call Tigger ID and Api Token visit: {0}"
|
"wayToGetHeiiOnCallDetails": "How to get the Tigger ID and API Keys is explained in the {documentation}"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user