Skip to content

Instantly share code, notes, and snippets.

@meyt
Created March 4, 2022 14:23
Show Gist options
  • Save meyt/acf2c43d1afddf31dc438015e1864d3c to your computer and use it in GitHub Desktop.
Save meyt/acf2c43d1afddf31dc438015e1864d3c to your computer and use it in GitHub Desktop.
uptimerobot:webhook > google sheets
function timeConverter(ts){
var a = new Date(ts * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}
function req (e) {
if (typeof e === 'undefined') { e = { parameter: { alertDateTime: '1646388087'} } }
var qs = e.parameter;
// Logger.log(qs);
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheets()[0];
var ts = parseInt(qs.alertDateTime);
if (typeof ts === 'number') {
var row = [
qs.alertTypeFriendlyName,
qs.monitorFriendlyName,
qs.monitorID,
qs.alertDetails,
qs.alertDuration,
timeConverter(ts),
qs.alertDateTime,
];
sheet.appendRow(row);
}
// return ContentService.createTextOutput(JSON.stringify(qs)).setMimeType(ContentService.MimeType.JSON)
}
function doGet (e) {
return req(e)
}
function doPost(e) {
return req(e);
}
@meyt
Copy link
Author

meyt commented Mar 4, 2022

duration seconds to HMS =ARRAYFORMULA(IF(ISBLANK(E2:E), , TEXT(E2:E /86400, "HH:MM:ss")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment