From cf73f37a5d64f39cb71468134791ba4caf782bb3 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Fri, 4 Nov 2022 12:29:36 -0700 Subject: [PATCH] Added await-to-js for error checking added for lookup --- config/dev.yaml | 4 ++-- index.js | 14 +++++++++++++- package.json | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config/dev.yaml b/config/dev.yaml index b0b8487..c2332c7 100644 --- a/config/dev.yaml +++ b/config/dev.yaml @@ -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 diff --git a/index.js b/index.js index faaf43f..c43ca82 100644 --- a/index.js +++ b/index.js @@ -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) diff --git a/package.json b/package.json index 75e6925..1634e7b 100644 --- a/package.json +++ b/package.json @@ -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",