mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-04 17:23:21 +00:00
feat: add google sheets notification provider (#6777)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
co-authored by
autofix-ci[bot]
Frank Elsinga
parent
f1d3e9adcc
commit
a38c6dea25
@@ -0,0 +1,60 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
|
||||
class GoogleSheets extends NotificationProvider {
|
||||
name = "GoogleSheets";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
// Prepare the data to be logged
|
||||
const timestamp = new Date().toISOString();
|
||||
let status = "N/A";
|
||||
let monitorName = "N/A";
|
||||
let monitorUrl = "N/A";
|
||||
let responseTime = "N/A";
|
||||
let statusCode = "N/A";
|
||||
|
||||
if (monitorJSON) {
|
||||
monitorName = monitorJSON.name || "N/A";
|
||||
monitorUrl = this.extractAddress(monitorJSON) || "N/A";
|
||||
}
|
||||
|
||||
if (heartbeatJSON) {
|
||||
status = heartbeatJSON.status === DOWN ? "DOWN" : heartbeatJSON.status === UP ? "UP" : "UNKNOWN";
|
||||
responseTime = heartbeatJSON.ping || "N/A";
|
||||
statusCode = heartbeatJSON.statusCode || "N/A";
|
||||
}
|
||||
|
||||
// Send data to Google Apps Script webhook
|
||||
const config = this.getAxiosConfigWithProxy({
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
const data = {
|
||||
timestamp,
|
||||
status,
|
||||
monitorName,
|
||||
monitorUrl,
|
||||
message: msg,
|
||||
responseTime,
|
||||
statusCode,
|
||||
};
|
||||
|
||||
await axios.post(notification.googleSheetsWebhookUrl, data, config);
|
||||
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GoogleSheets;
|
||||
@@ -17,6 +17,7 @@ const Feishu = require("./notification-providers/feishu");
|
||||
const Notifery = require("./notification-providers/notifery");
|
||||
const FreeMobile = require("./notification-providers/freemobile");
|
||||
const GoogleChat = require("./notification-providers/google-chat");
|
||||
const GoogleSheets = require("./notification-providers/google-sheets");
|
||||
const Gorush = require("./notification-providers/gorush");
|
||||
const Gotify = require("./notification-providers/gotify");
|
||||
const GrafanaOncall = require("./notification-providers/grafana-oncall");
|
||||
@@ -117,6 +118,7 @@ class Notification {
|
||||
new Feishu(),
|
||||
new FreeMobile(),
|
||||
new GoogleChat(),
|
||||
new GoogleSheets(),
|
||||
new Gorush(),
|
||||
new Gotify(),
|
||||
new GrafanaOncall(),
|
||||
|
||||
Reference in New Issue
Block a user