หน้าเว็บ

วันพฤหัสบดีที่ 22 กุมภาพันธ์ พ.ศ. 2561

การ Ping Server แจ้งผ่านทาง Line Notify


Website uptime Event Emitter


Ping-monitor (Node-Monitor) is a tool for monitoring your website's uptime. If the website is up or down an event is emitted. This module is extracted from Node Ping, an uptime app I wrote recently.

Installation

npm install ping-monitor

How to use

var Monitor = require('ping-monitor');
 
var myWebsite = new Monitor(options);
 
myWebsite.on(event, callback(response) {
    // Do something with the response 
});

Options

  • website (* required) - The url of the website to be monitored.
  • interval (defaults to 15) - time interval(in minutes) for checking website availability.

Emitted Events

  • up - All is good website is up.
  • down - Not good, website is down.
  • error - Bad, http request module cannot load website.
  • stop - Fired when the monitor has stopped.

response object

  • object.website - website being monitored.
  • object.time - time in milliseconds.
  • object.responseCode - http response code.
  • object.responseMessage - http response code message.

Example


var Monitor = require('ping-monitor');
var request = require('request'); 
const token = 'Line Token';

var headers = {
    'User-Agent':       'Super Agent/0.0.1',
    'Content-Type':     'application/x-www-form-urlencoded'
}
// Configure the request
var options = {
    'url': 'https://notify-api.line.me/api/notify',
    'method': 'POST',
    'headers': headers,
'auth': {
       'bearer': token
},
'form': {
       'message': ''
}
}

var myWebsite = new Monitor({
    website: 'http://www.tapee.ac.th',
    interval: 1
});


myWebsite.on('error', function (msg) {
    console.log(msg);
    options.form.message = 'http://www.tapee.ac.th  is error! ';
    request(options);
});


myWebsite.on('up', function (res) {
    console.log('Yay!! ' + res.website + ' is up.');
});


myWebsite.on('down', function (res) {
    options.form.message = 'http://www.tapee.ac.th  is down! ';
    request(options);
    console.log( res.website + ' is down! ' + res.statusMessage);
});

1 ความคิดเห็น:

  1. Slot machines review - Lucky Club Live
    With a casino site offering a wide range of slots to choose luckyclub.live from, you're always looking for something with a better gaming experience. Read about our unbiased  Rating: 4.5 · ‎Review by LuckyClub

    ตอบลบ