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)); })();