mirror of
https://github.com/bellingcat/google-apps-script.git
synced 2026-06-11 12:58:35 +03:00
update readme
This commit is contained in:
34
monitor-sheet/Monitor.gs
Normal file
34
monitor-sheet/Monitor.gs
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
const ERROR_MESSAGE = "NOT_FOUND"
|
||||
const SHEET_TO_MONITOR = "your-sheet-name"
|
||||
const ALERT = "Custom alert message for this error"
|
||||
|
||||
function main() {
|
||||
console.time("full");
|
||||
{
|
||||
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_TO_MONITOR);
|
||||
assert(!findInSheet(sheet, ERROR_MESSAGE), ALERT)
|
||||
}
|
||||
console.timeEnd("full");
|
||||
}
|
||||
|
||||
function findInSheet(sheet, SEARCH_FOR) {
|
||||
let rows = sheet.getDataRange().getValues();
|
||||
for (const row of rows) {
|
||||
for (const cell of row) {
|
||||
if (cell == SEARCH_FOR) {
|
||||
console.log(`"${SEARCH_FOR}" FOUND in "${sheet.getSheetName()}"`)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(`"${SEARCH_FOR}" NOT FOUND in "${sheet.getSheetName()}"`)
|
||||
return false;
|
||||
}
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
console.error(message);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
9
monitor-sheet/README.md
Normal file
9
monitor-sheet/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
### Goal
|
||||
This script can be added to any sheet and then used in conjunction with the Timed executions + immediate email notification to have an alert in case the content of a sheet shows a given error message.
|
||||
|
||||
### Features:
|
||||
* monitors a sheet for any string value
|
||||
* throws an error when a given string is found/not-found
|
||||
|
||||
### How
|
||||
Use the gsheets formulas to detect errors/bugs and write something like `NOT_FOUND` when an error occurs (see [IFERROR](https://support.google.com/docs/answer/3093304?hl=en) method), then set up recurrent triggers and automated alerts for the sheet being monitored and you will get an email if something breaks in the sheet.
|
||||
Reference in New Issue
Block a user