Skip to main content

Website Monitor with Google Scripts Easy Guide!

Use Google Apps Script to monitors website domains and send SMS text alerts when any of these sites are down or inaccessible. Thus, enabling you in Website Monitor with Google Scripts.

Code for Website Monitor with Google Scripts:

function init() {
  if (ScriptApp.getScriptTriggers().length == 0) {
    // Set up a monitor that triggers every 5 minutes
    ScriptApp.newTrigger('websiteMonitor').timeBased().everyMinutes(5).create();
  }
}

function websiteMonitor() {
  var response, error, code, urls;

  // The script can monitor multiple website URLs (comma separated)
  urls = SpreadsheetApp.getActiveSheet().getRange('B2').getValue();
  urls = urls.replace(/\s/g, '').split(',');

  for (var i = 0; i < urls.length; i++) {
    var url = urls[i];

    if (!ScriptProperties.getProperty(url)) {
      ScriptProperties.setProperty(url, 200);
    }

    // Trying to connect to the website URL
    try {
      response = UrlFetchApp.fetch(url);
    } catch (error) {
      // If URLFetchApp fails, the site is probably down
      updateLog(url, -1);
      continue;
    }

    code = response.getResponseCode();
    updateLog(url, code);
  }
}

function updateLog(url, code) {
  if (ScriptProperties.getProperty(url) == code) return;

  ScriptProperties.setProperty(url, code);

  var sheet = SpreadsheetApp.getActiveSheet();

  var row = sheet.getLastRow() + 1;
  var time = new Date();
  var msg = 'Down';

  if (code == 200) msg = 'Up';

  msg = 'Website is ' + msg + '  ' + url;

  sheet.getRange(row, 1).setValue(time);
  sheet.getRange(row, 2).setValue(msg);

  // Send an email notification when the site status changes
  var email = sheet.getRange('B3').getValue();
  MailApp.sendEmail(email, msg, url);

  var now = new Date(time.getTime() + 10000);

  // Create an event in Google Calendar with an SMS reminder
  if (sheet.getRange('B4').getValue().toLowerCase() == 'yes') CalendarApp.createEvent(msg, now, now).addSmsReminder(0);
}


from thetechxp https://ift.tt/PdUVTsz
via IFTTT

Comments

Popular posts from this blog

किस महानगर में मिल रहा सबसे सस्ता पेट्रोल? जानें तेल का नया भाव https://ift.tt/zKAj5k6

रोज की तरह आज यानि 9 दिसंबर को भी तेल के नए रेट जारी कर दिए गए हैं. जिसके अनुसार, पेट्रोल-डीजल की कीमतों में कोई बदलाव नहीं किया गया है. सभी राज्यों में वाहन ईंधन की कीमतें जस की तस हैं. आइये जानते हैं, किस महानगर में सबसे कम कीमत पर पेट्रोल मिल रहा है और देश के किस इलाके में सबसे सस्ता और सबसे महंगा पेट्रोल मिल रहा है. from आज तक https://ift.tt/o9nAWyY via IFTTT

Best Website For Finding Government Jobs

  Online Sarkari Job Find   is a reliable and comprehensive online platform dedicated to providing the latest information on job opportunities. Our mission is to assist job seekers in finding their ideal positions by offering timely alerts and notifications on the latest job openings, Sarkari Results, Sarkari Exams, Sarkari jobs, Sarkari networks, and Sarkari Naukri. Our team of dedicated professionals is committed to keeping you informed about the most recent developments in the employment sector. With our user-friendly interface and up-to-date content, we strive to ensure that you have access to accurate and reliable information regarding various government job vacancies. Website Link -  Online Sarkari Job Find

IPL: कप्तान बाहर, दिग्गज भी निकले... रिटेंशन ने कैसे बदल दिया टीमों का गणित https://ift.tt/L7Adk8F

आईपीएल के अगले सीजन के लिए 23 दिसंबर को कोच्चि में मिनी ऑक्शन का आयोजन होना है. इस नीलामी से पहले सभी 10 टीमों की ओर से रिटेंशन लिस्ट जारी कर दी गई. from आज तक https://ift.tt/LK4D2kX via IFTTT