uptime-kuma/server/notification-providers/google-sheets.js
Dharun Ashokkumar 491741be23 feat: add google sheets notification provider
logs monitor events to google spreadsheet via apps script webhook
2026-01-20 09:52:35 +05:30

63 lines
1.9 KiB
JavaScript

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.status || "N/A";
}
// Send data to Google Apps Script webhook
const webhookUrl = notification.googleSheetsWebhookUrl;
const config = this.getAxiosConfigWithProxy({
headers: {
"Content-Type": "application/json"
}
});
const data = {
timestamp: timestamp,
status: status,
monitorName: monitorName,
monitorUrl: monitorUrl,
message: msg,
responseTime: responseTime,
statusCode: statusCode
};
await axios.post(webhookUrl, data, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = GoogleSheets;