You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Google App script for the website monitor and updates via slack or email
Customizable as per needed
functioninit(){consturls=["URL_1","URL_2",];letstatusResponse=[];varpayloadText=":compass: Today’s status is *here* \n";for(leturlCounter=0;urlCounter<urls.length;urlCounter++){statusResponse[urlCounter]=checkWebsiteStatus(urls[urlCounter]);payloadText+=`:computer: *Domain*: ${statusResponse[urlCounter].url} \n :stopwatch: *Load Time*: ${statusResponse[urlCounter].loadTimeMs}Mili Seconds \n :electric_plug: *Status Code*: ${statusResponse[urlCounter].responseCode} \n \n`;}varpayload={"channel" : "#slackbot-test","username" : "Site Analysis","icon_url" : "https://puu.sh/BQqA9/408cadc2b3.png","text" : "Here’s an Analysis of the production Websites","attachments": [{"text": payloadText,"footer": "<https://test.link|edit script>","mrkdwn_in": ["text"]}]}constwebhook="SLACK_WEB_HOOK";//Paste your webhook URL herevaroptions={"method": "post","contentType": "application/json","muteHttpExceptions": true,"payload": JSON.stringify(payload)};try{UrlFetchApp.fetch(webhook,options);}catch(e){Logger.log(e);}// Send email notification if // if(response.getResponseCode() != 200) {// let email = "EMAIL_ID";// let subject = "[ACTION REQUIRED] Website may be down - " + new Date();// let body = `The URL ${url} may be down. Expected response code 200 but got ${responseCode} instead.`;// MailApp.sendEmail(email, subject,body);// }}functioncheckWebsiteStatus(urlString){leturl=urlString;// Record time so we can track how long the website// takes to load.letstart=newDate();letresponse=UrlFetchApp.fetch(url,{muteHttpExceptions: true});letend=newDate();letresponseCode=response.getResponseCode();letloadTimeMs=end-start;// Record a log of the website's status to the spreadsheet.SpreadsheetApp.getActive().getSheetByName("Data").appendRow([url,start,responseCode,loadTimeMs]);return{
url,
responseCode,
loadTimeMs,}}