commit
8c69c18f6d
@ -0,0 +1,25 @@
|
|||||||
|
name: json-yaml-validate
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write # enable write permissions for pull request comments
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
json-yaml-validate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: json-yaml-validate
|
||||||
|
id: json-yaml-validate
|
||||||
|
uses: GrantBirki/json-yaml-validate@v1.2.0
|
||||||
|
with:
|
||||||
|
comment: "true" # enable comment mode
|
@ -0,0 +1,97 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { UP, DOWN } = require("../../src/util");
|
||||||
|
|
||||||
|
const opsgenieAlertsUrlEU = "https://api.eu.opsgenie.com/v2/alerts";
|
||||||
|
const opsgenieAlertsUrlUS = "https://api.opsgenie.com/v2/alerts";
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
class Opsgenie extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "Opsgenie";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let opsgenieAlertsUrl;
|
||||||
|
let priority = (notification.opsgeniePriority == "") ? 3 : notification.opsgeniePriority;
|
||||||
|
const textMsg = "Uptime Kuma Alert";
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (notification.opsgenieRegion) {
|
||||||
|
case "US":
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlUS;
|
||||||
|
break;
|
||||||
|
case "EU":
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlEU;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
let notificationTestAlias = "uptime-kuma-notification-test";
|
||||||
|
let data = {
|
||||||
|
"message": msg,
|
||||||
|
"alias": notificationTestAlias,
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
"priority": "P5"
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsUrl, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === DOWN) {
|
||||||
|
let data = {
|
||||||
|
"message": monitorJSON ? textMsg + `: ${monitorJSON.name}` : textMsg,
|
||||||
|
"alias": monitorJSON.name,
|
||||||
|
"description": msg,
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
"priority": `P${priority}`
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsUrl, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === UP) {
|
||||||
|
let opsgenieAlertsCloseUrl = `${opsgenieAlertsUrl}/${encodeURIComponent(monitorJSON.name)}/close?identifierType=alias`;
|
||||||
|
let data = {
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsCloseUrl, data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {BeanModel} notification
|
||||||
|
* @param {string} url Request url
|
||||||
|
* @param {Object} data Request body
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async post(notification, url, data) {
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": `GenieKey ${notification.opsgenieApiKey}`,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = await axios.post(url, data, config);
|
||||||
|
if (res.status == null) {
|
||||||
|
return "Opsgenie notification failed with invalid response!";
|
||||||
|
}
|
||||||
|
if (res.status < 200 || res.status >= 300) {
|
||||||
|
return `Opsgenie notification failed with status code ${res.status}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Opsgenie;
|
@ -0,0 +1,41 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class Twilio extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "twilio";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
let accountSID = notification.twilioAccountSID;
|
||||||
|
let authToken = notification.twilioAuthToken;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
||||||
|
"Authorization": "Basic " + Buffer.from(accountSID + ":" + authToken).toString("base64"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = new URLSearchParams();
|
||||||
|
data.append("To", notification.twilioToNumber);
|
||||||
|
data.append("From", notification.twilioFromNumber);
|
||||||
|
data.append("Body", msg);
|
||||||
|
|
||||||
|
let url = "https://api.twilio.com/2010-04-01/Accounts/" + accountSID + "/Messages.json";
|
||||||
|
|
||||||
|
await axios.post(url, data, config);
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Twilio;
|
@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-region" class="form-label">{{ $t("Region") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<select id="opsgenie-region" v-model="$parent.notification.opsgenieRegion" class="form-select" required>
|
||||||
|
<option value="us">
|
||||||
|
US (Default)
|
||||||
|
</option>
|
||||||
|
<option value="eu">
|
||||||
|
EU
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-apikey" class="form-label">{{ $t("API Key") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<HiddenInput id="opsgenie-apikey" v-model="$parent.notification.opsgenieApiKey" required="true" autocomplete="false"></HiddenInput>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-priority" class="form-label">{{ $t("Priority") }}</label>
|
||||||
|
<input id="opsgenie-priority" v-model="$parent.notification.opsgeniePriority" type="number" class="form-control" min="1" max="5" step="1">
|
||||||
|
</div>
|
||||||
|
<div class="form-text">
|
||||||
|
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||||
|
<i18n-t tag="p" keypath="aboutWebhooks" style="margin-top: 8px;">
|
||||||
|
<a href="https://docs.opsgenie.com/docs/alert-api" target="_blank">https://docs.opsgenie.com/docs/alert-api</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-account-sid" class="form-label">{{ $t("Account SID") }}</label>
|
||||||
|
<input id="twilio-account-sid" v-model="$parent.notification.twilioAccountSID" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-auth-token" class="form-label">{{ $t("Auth Token") }}</label>
|
||||||
|
<input id="twilio-auth-token" v-model="$parent.notification.twilioAuthToken" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-from-number" class="form-label">{{ $t("From Number") }}</label>
|
||||||
|
<input id="twilio-from-number" v-model="$parent.notification.twilioFromNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-to-number" class="form-label">{{ $t("To Number") }}</label>
|
||||||
|
<input id="twilio-to-number" v-model="$parent.notification.twilioToNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
||||||
|
<a href="https://www.twilio.com/docs/sms" target="_blank">https://www.twilio.com/docs/sms</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in new issue