From a5119510527d0ff24c86540102996ca57feeb67d Mon Sep 17 00:00:00 2001 From: Dharun Ashokkumar Date: Tue, 20 Jan 2026 09:32:11 +0530 Subject: [PATCH] feat: add google sheets notification provider logs monitor events to google spreadsheet via apps script webhook --- .../notification-providers/google-sheets.js | 76 +------- src/components/NotificationDialog.vue | 4 +- src/components/notifications/GoogleSheets.vue | 181 +++++++++--------- 3 files changed, 106 insertions(+), 155 deletions(-) diff --git a/server/notification-providers/google-sheets.js b/server/notification-providers/google-sheets.js index 41d3e5367..416c5ba8a 100644 --- a/server/notification-providers/google-sheets.js +++ b/server/notification-providers/google-sheets.js @@ -31,82 +31,26 @@ class GoogleSheets extends NotificationProvider { statusCode = heartbeatJSON.status || "N/A"; } - // Prepare row data based on user configuration - let rowData = []; - - if (notification.googleSheetsCustomFormat) { - // Custom format - user defines their own columns - const customColumns = notification.googleSheetsColumns || "timestamp,status,monitor,message"; - const columns = customColumns.split(",").map(col => col.trim()); - - columns.forEach(column => { - switch (column.toLowerCase()) { - case "timestamp": - rowData.push(timestamp); - break; - case "status": - rowData.push(status); - break; - case "monitor": - case "monitorname": - rowData.push(monitorName); - break; - case "url": - case "monitorurl": - rowData.push(monitorUrl); - break; - case "message": - case "msg": - rowData.push(msg); - break; - case "responsetime": - case "ping": - rowData.push(responseTime); - break; - case "statuscode": - rowData.push(statusCode); - break; - default: - rowData.push(""); - } - }); - } else { - // Default format - rowData = [ - timestamp, - status, - monitorName, - monitorUrl, - msg, - responseTime, - statusCode - ]; - } - - // Prepare the request to Google Sheets API - const spreadsheetId = notification.googleSheetsSpreadsheetId; - const sheetName = notification.googleSheetsSheetName || "Sheet1"; - const range = `${sheetName}!A:Z`; - - // Use Google Sheets API v4 to append data - const apiUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:append`; + // Send data to Google Apps Script webhook + const webhookUrl = notification.googleSheetsWebhookUrl; const config = this.getAxiosConfigWithProxy({ - params: { - valueInputOption: "USER_ENTERED", - insertDataOption: "INSERT_ROWS" - }, headers: { - "Authorization": `Bearer ${notification.googleSheetsAccessToken}`, "Content-Type": "application/json" } }); const data = { - values: [rowData] + timestamp: timestamp, + status: status, + monitorName: monitorName, + monitorUrl: monitorUrl, + message: msg, + responseTime: responseTime, + statusCode: statusCode }; - await axios.post(apiUrl, data, config); + await axios.post(webhookUrl, data, config); return okMsg; } catch (error) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 6d915255a..1c8bd68cb 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -305,7 +305,9 @@ export default { }; // Other Integrations - let other = {}; + let other = { + GoogleSheets: "Google Sheets", + }; // Regional - Not supported in most regions or documentation is not in English let regional = { diff --git a/src/components/notifications/GoogleSheets.vue b/src/components/notifications/GoogleSheets.vue index f4a0d9f8a..1d21cbdeb 100644 --- a/src/components/notifications/GoogleSheets.vue +++ b/src/components/notifications/GoogleSheets.vue @@ -1,111 +1,116 @@