Added await-to-js for error checking added for lookup

master
Kebler Network System Administrator 2022-11-04 12:29:36 -07:00
parent ba0f05436c
commit cf73f37a5d
3 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
network: 'testing kebler network'
domain: 'test.kebler.net'
network: "testing kebler network"
domain: "testing.kebler.net"
dev: true
verbose: v
cron: 1

View File

@ -6,6 +6,8 @@ import { lookup as clookup } from 'dns'
import { promisify } from 'util'
const lookup = promisify(clookup)
import { CronJob } from 'cron'
import to from 'await-to-js'
import { info } from 'console'
const rname = process.argv[2] || opts.domain
if (!rname) {
@ -52,6 +54,7 @@ async function checkIP () {
let ip = curr.split('.')
ip[0] = ip[0] - Math.floor(Math.random() * 10)
curr = ip.join('.')
console.log('development run: generated dummy current ip', curr)
}
const saved = await route53.getZoneRecordValue(rname)
if (opts.debug) notify('checking for change in public ip',timestamp())
@ -69,7 +72,15 @@ async function checkIP () {
notify(msg)
},timeout*1000*(opts.debug ? 10 : 60))
const check = setInterval(async ()=>{
if (curr === (await lookup(rname)).address) {
let [err,info] = await to(lookup(rname))
if (err) {
clearInterval(check)
clearTimeout(fail)
msg=`FATAL Error in lookup of' ${rname}, ${err}, aborting check, human intervention required`
console.log(msg)
notify(msg)
} else {
if (curr === info.address) {
msg=`Update Succeeded, lookup of ${rname} is now ${curr}`
clearInterval(check)
clearTimeout(fail)
@ -82,6 +93,7 @@ async function checkIP () {
console.log(msg)
}
}
}
}
,interval*1000)

View File

@ -26,6 +26,7 @@
"@uci-utils/notify-email-plugin": "^0.1.6",
"@uci-utils/notify-pushsafer-plugin": "^0.1.2",
"@uci-utils/route53": "^0.1.2",
"await-to-js": "^3.0.0",
"config": "^3.3.2",
"cron": "^1.8.2",
"esm": "^3.2.25",