Compare commits
No commits in common. "c5e1bb4c640a1bb5487e23c62f5ac5b5773b9958" and "d10e9bb2c67dd4b3c1b0c55185722fc79c2ae8fb" have entirely different histories.
c5e1bb4c64
...
d10e9bb2c6
15
package-lock.json
generated
15
package-lock.json
generated
@ -10,7 +10,6 @@
|
|||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@influxdata/influxdb-client": "^1.20.0",
|
"@influxdata/influxdb-client": "^1.20.0",
|
||||||
"@influxdata/influxdb-client-apis": "^1.20.0",
|
|
||||||
"log4js": "^6.3.0",
|
"log4js": "^6.3.0",
|
||||||
"luxon": "^2.1.1",
|
"luxon": "^2.1.1",
|
||||||
"string-argv": "^0.3.1"
|
"string-argv": "^0.3.1"
|
||||||
@ -21,14 +20,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.20.0.tgz",
|
||||||
"integrity": "sha512-jaKSI63hmQ5VSkJrFJkYIXaKlhoF+mGd4HmOf7v/X7pmEi69ReHp922Wyx6/OeCrpndRMbsadk+XmGNdd43cFw=="
|
"integrity": "sha512-jaKSI63hmQ5VSkJrFJkYIXaKlhoF+mGd4HmOf7v/X7pmEi69ReHp922Wyx6/OeCrpndRMbsadk+XmGNdd43cFw=="
|
||||||
},
|
},
|
||||||
"node_modules/@influxdata/influxdb-client-apis": {
|
|
||||||
"version": "1.20.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.20.0.tgz",
|
|
||||||
"integrity": "sha512-KMTmXH4rbpS+NWGpqDjxcKTyan2rbiT2IM5AdRElKhH2sHbH96xwLgziaxeC+OCJLeNAdehJgae3I8WiZjbwdg==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@influxdata/influxdb-client": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/date-format": {
|
"node_modules/date-format": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/date-format/-/date-format-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/date-format/-/date-format-3.0.0.tgz",
|
||||||
@ -161,12 +152,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.20.0.tgz",
|
||||||
"integrity": "sha512-jaKSI63hmQ5VSkJrFJkYIXaKlhoF+mGd4HmOf7v/X7pmEi69ReHp922Wyx6/OeCrpndRMbsadk+XmGNdd43cFw=="
|
"integrity": "sha512-jaKSI63hmQ5VSkJrFJkYIXaKlhoF+mGd4HmOf7v/X7pmEi69ReHp922Wyx6/OeCrpndRMbsadk+XmGNdd43cFw=="
|
||||||
},
|
},
|
||||||
"@influxdata/influxdb-client-apis": {
|
|
||||||
"version": "1.20.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.20.0.tgz",
|
|
||||||
"integrity": "sha512-KMTmXH4rbpS+NWGpqDjxcKTyan2rbiT2IM5AdRElKhH2sHbH96xwLgziaxeC+OCJLeNAdehJgae3I8WiZjbwdg==",
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"date-format": {
|
"date-format": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/date-format/-/date-format-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/date-format/-/date-format-3.0.0.tgz",
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@influxdata/influxdb-client": "^1.20.0",
|
"@influxdata/influxdb-client": "^1.20.0",
|
||||||
"@influxdata/influxdb-client-apis": "^1.20.0",
|
|
||||||
"log4js": "^6.3.0",
|
"log4js": "^6.3.0",
|
||||||
"luxon": "^2.1.1",
|
"luxon": "^2.1.1",
|
||||||
"string-argv": "^0.3.1"
|
"string-argv": "^0.3.1"
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
const logger = require.main.require("./helper/logger.js")("influx-checks");
|
|
||||||
|
|
||||||
const { InfluxDB, Point } = require('@influxdata/influxdb-client')
|
|
||||||
const Influx = require('@influxdata/influxdb-client-apis');
|
|
||||||
|
|
||||||
|
|
||||||
function checkHealth(influxDb){
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
new Influx.HealthAPI(influxDb) // Check influx health
|
|
||||||
.getHealth()
|
|
||||||
.catch((err) => {
|
|
||||||
logger.error("Could not communicate with Influx:");
|
|
||||||
logger.error(`Error [${err.code}]:`, err.message);
|
|
||||||
reject();
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
logger.debug("Server healthy.", "Version: ", res.version);
|
|
||||||
resolve(res);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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.error("Could not get bucket:");
|
|
||||||
logger.error(`Error [${err.code}]:`, err.message);
|
|
||||||
reject();
|
|
||||||
}).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..
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkWriteApi(influxDb, options){
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const writeApi = influxDb.getWriteApi(options.org, options.bucket); // Get WriteAPI
|
|
||||||
writeApi.writePoint(new Point("test").tag("ConnectionTest", true).intField("value", 0).timestamp(0)) // Write dummy-point
|
|
||||||
writeApi.close()
|
|
||||||
.catch((err) => {
|
|
||||||
logger.error("Could not get writeApi:");
|
|
||||||
logger.error(`Error [${err.code}]:`, err.message);
|
|
||||||
if(err.code == "not found") logger.fatal("No write-permission?");
|
|
||||||
reject();
|
|
||||||
}).then((res) => {
|
|
||||||
logger.debug("Writing ok");
|
|
||||||
|
|
||||||
// Delete the connection-text-point
|
|
||||||
new Influx.DeleteAPI(influxDb).postDelete({
|
|
||||||
"body": {
|
|
||||||
"start": 0,
|
|
||||||
"end": 1,
|
|
||||||
"predicate": "ConnectionTest==true"
|
|
||||||
},
|
|
||||||
"org": options.org,
|
|
||||||
"bucket": options.bucket
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
logger.error("Could not delete ConnectionTest-Point:");
|
|
||||||
logger.error(`Error [${err.code}]:`, err.message);
|
|
||||||
reject();
|
|
||||||
})
|
|
||||||
.then(resolve())
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Specify exports
|
|
||||||
module.exports = {
|
|
||||||
checkHealth,
|
|
||||||
checkBucket,
|
|
||||||
checkWriteApi,
|
|
||||||
};
|
|
21
src/main.js
21
src/main.js
@ -3,7 +3,6 @@ const logger = require("./helper/logger.js")("main");
|
|||||||
const { requireEnvVars } = require("./helper/env.js");
|
const { requireEnvVars } = require("./helper/env.js");
|
||||||
const { exit } = require("process");
|
const { exit } = require("process");
|
||||||
const { InfluxDB } = require('@influxdata/influxdb-client');
|
const { InfluxDB } = require('@influxdata/influxdb-client');
|
||||||
const InfluxChecks = require('./helper/influx-checks.js');
|
|
||||||
|
|
||||||
/// Setup ENVs
|
/// Setup ENVs
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
@ -26,24 +25,4 @@ if(errorMsg){
|
|||||||
logger.info("Setup Influx..");
|
logger.info("Setup Influx..");
|
||||||
const influxDb = new InfluxDB({url: env.INFLUX_URL, token: env.INFLUX_TOKEN});
|
const influxDb = new InfluxDB({url: env.INFLUX_URL, token: env.INFLUX_TOKEN});
|
||||||
|
|
||||||
await InfluxChecks.checkHealth(influxDb)
|
|
||||||
.then((res) => {return InfluxChecks.checkBucket(influxDb, {
|
|
||||||
org: env.INFLUX_ORG,
|
|
||||||
name: env.INFLUX_BUCKET
|
|
||||||
})})
|
|
||||||
.then((res) => {return InfluxChecks.checkWriteApi(influxDb, {
|
|
||||||
org: env.INFLUX_ORG,
|
|
||||||
name: env.INFLUX_BUCKET
|
|
||||||
})})
|
|
||||||
.catch((err) => {
|
|
||||||
if(err) {
|
|
||||||
logger.error("Error whilst checking influx:");
|
|
||||||
logger.error(err);
|
|
||||||
}
|
|
||||||
logger.fatal("Setup influx failed!");
|
|
||||||
exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info("Influx ok");
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user