From e1b2a7e016f2200d7d14a0685a73c6664e52ad47 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 26 Nov 2021 18:03:14 +0100 Subject: [PATCH] Added influx checkBucket --- src/helper/influx-checks.js | 16 ++++++++++++++++ src/main.js | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/helper/influx-checks.js b/src/helper/influx-checks.js index b44a0fc..f1858f9 100644 --- a/src/helper/influx-checks.js +++ b/src/helper/influx-checks.js @@ -19,8 +19,24 @@ function checkHealth(influxDb){ }); } +function checkBucket(influxDb, options){ + return new Promise((resolve, reject) => { + new Influx.BucketsAPI(influxDb).getBuckets(options) + .catch((err) => { // Weirdly the influx-Api returns 404 for searches of non-existing buckets + logger.fatal("Could not get bucket:"); + logger.fatal(`Error [${err.code}]:`, err.message); + reject(err); + }).then((res) => { // But an empty list when the bucket exists, but token does not have permission to get details + logger.debug("Bucket found"); + resolve(res); + // Now we know the bucket exists and we have some kind of permission.. but we still dont know if we are able to write to it.. + }); + }); +} + // Specify exports module.exports = { checkHealth, + checkBucket, }; \ No newline at end of file diff --git a/src/main.js b/src/main.js index dec1e82..bb42690 100644 --- a/src/main.js +++ b/src/main.js @@ -26,7 +26,11 @@ if(errorMsg){ const influxDb = new InfluxDB({url: env.INFLUX_URL, token: env.INFLUX_TOKEN}); await InfluxChecks.checkHealth(influxDb) - .catch(exit(1)) - .then((res) => {}); + .then((res) => {return InfluxChecks.checkBucket(influxDb, { + org: env.INFLUX_ORG, + name: env.INFLUX_BUCKET + })}) + .then((res) => {}) + .catch(exit(1)); })();