Implemented CheckWriteApi by writing and then deleting a TestPoint
This commit is contained in:
parent
ddf39b9433
commit
3c29ed2000
@ -1,5 +1,6 @@
|
||||
const logger = require.main.require("./helper/logger.js")("influx-checks");
|
||||
|
||||
const { InfluxDB, Point } = require('@influxdata/influxdb-client')
|
||||
const Influx = require('@influxdata/influxdb-client-apis');
|
||||
|
||||
|
||||
@ -34,9 +35,43 @@ function checkBucket(influxDb, options){
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
@ -31,6 +31,10 @@ if(errorMsg){
|
||||
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:");
|
||||
|
Loading…
x
Reference in New Issue
Block a user