Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Elsinga <[email protected]>
  • Loading branch information
hevans66 and CommanderStorm authored Feb 14, 2024
1 parent 673f9a7 commit 4cdc8f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
15 changes: 4 additions & 11 deletions server/notification-providers/heii-oncall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,31 @@ const { setting } = require("../util-server");

const NotificationProvider = require("./notification-provider");
const axios = require("axios");

const heiiOnCallBaseUrl = "https://heiioncall.com";

class HeiiOnCall extends NotificationProvider {
name = "HeiiOnCall";

/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
// Payload to Heii On-Call is the entire heartbat JSON
const payload = heartbeatJSON ? heartbeatJSON : {};
const payload = heartbeatJSON || {};

// If we can, add url back to monitor to payload
const baseURL = await setting("primaryBaseURL");
if (baseURL && monitorJSON) {
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
}

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;
return this.postNotification(notification, "alert", payload);
}

if (heartbeatJSON.status === DOWN) {
// Monitor is DOWN, alert on Heii On-Call
return this.postNotification(notification, "alert", payload);
}

if (heartbeatJSON.status === UP) {
// Monitor is UP, resolve on Heii On-Call
return this.postNotification(notification, "resolve", payload);
}
}
Expand All @@ -58,15 +51,15 @@ class HeiiOnCall extends NotificationProvider {
// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
try {
await axios.post(
`${heiiOnCallBaseUrl}/triggers/${notification.heiiOnCallTriggerId}/${action}`,
`https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/${action}`,
payload,
config
);
} catch (error) {
this.throwGeneralAxiosError(error);
}

return "Heii On-Call post sent successfully.";
return "Sent Successfully";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/notifications/HeiiOnCall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<div class="form-text">
<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>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -885,5 +885,5 @@
"Browser Screenshot": "Browser Screenshot",
"What is a Remote Browser?": "What is a Remote Browser?",
"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}"
}

0 comments on commit 4cdc8f3

Please sign in to comment.