Created
November 7, 2020 14:35
-
-
Save fbslo/3feaaf0ddc6a0c55902cca24c515f5df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var ping = require('ping'); | |
var hive = require("@hiveio/hive-js") | |
var host = "ipAddress" | |
var fromNumber = "+1..." | |
var toNumber = "+1..." | |
var accountSid = 'TwillioSID'; | |
var authToken = 'TwillioAPISecret'; | |
var owner = 'fbslo' | |
var privateSignigKey = "5J..." | |
var props = { | |
"key": "youCurrentsigninkePublicKey", | |
"new_signing_key": "STM1111111111111111111111111111111114T1Anm" | |
} | |
let count = 0 | |
let disabled = false | |
setInterval(() => { | |
ping() | |
}, 1000 * 10) | |
function ping(){ | |
ping.sys.probe(host, function(isAlive){ | |
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; | |
if (!isAlive) count += 1 | |
if (!isAlive && count >= 3 && disabled == false) disableAndAlert() | |
}); | |
} | |
function disableAndAlert(){ | |
const client = require('twilio')(accountSid, authToken); | |
const witnessOps = hive.utils.buildWitnessUpdateOp(owner, props); | |
hive.broadcast.witnessSetProperties(privateSigningKey, owner, witnessOps[1].props, [], function(err, result) { | |
console.log(err, result); | |
disabled = true | |
}); | |
client.messages | |
.create({ | |
body: 'Your witness server is OFFLINE! Response: '+JSON.stringify(fetchResult), | |
from: fromNumber, | |
to: yourNumber | |
}) | |
.then(message => { | |
console.log(message.sid) | |
console.log("SMS sent!") | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment