Last active
January 19, 2017 17:56
-
-
Save voipnorm/9f8c1b646bff24dfb70c4d6aa0df6b6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var config = require('./config.json'); | |
var message = require('./myUtils/sparkMessage'); | |
var botToken = "<Your bot token>"; | |
/* | |
Handles events emitted when a websites stop being monitored | |
@param - (String) website - website url | |
*/ | |
function onStop (website) { | |
var to = config.email; | |
var text = website + ' monitor has stopped'; | |
console.log(JSON.stringify(website)) | |
if(this.webStatus==='up'){ | |
this.webStatus = 'down'; | |
message.newMessage(botToken,text,to); | |
}else{ | |
message.newMessage(botToken,text,to); | |
} | |
}; | |
function onUp (res) { | |
var to = config.email; | |
console.log(JSON.stringify(res)) | |
var text = res.website + ' monitor is up'; | |
text += '<p>Time: ' + res.time; | |
text += '</p><p>Website: ' + res.website; | |
text += '</p><p>Message: ' + res.statusMessage + '</p>'; | |
if(this.webStatus==='down'){ | |
this.webStatus = 'up'; | |
message.newMessage(botToken,text,to); | |
}else{ | |
return console.log(this.webStatus); | |
} | |
}; | |
/* | |
Handles events emitted when a website is down | |
@param - (Object) res - response object return by the Node Monitor object | |
*/ | |
function onDown (res) { | |
var text = ''; | |
var to = config.email; | |
text += '<p>Time: ' + res.time; | |
text += '</p><p>Website: ' + res.website; | |
text += '</p><p>Message: ' + res.statusMessage + '</p>'; | |
if(this.webStatus==='up'){ | |
this.webStatus = 'down'; | |
message.newMessage(botToken,text,to); | |
}else{ | |
this.webStatus = 'down'; | |
message.newMessage(botToken,text,to); | |
} | |
}; | |
/* | |
Handles events emitted when aa error occurs | |
@param - (String) msg - response message | |
*/ | |
function onError (msg) { | |
console.log(msg); | |
} | |
module.exports.onStop = onStop; | |
module.exports.onDown = onDown; | |
module.exports.onError = onError; | |
module.exports.onUp = onUp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment