ioBroker / ioBroker.influxdb

Store history data in InfluxDB (not for Windows)
MIT License
36 stars 25 forks source link

Delete command for InfluxDB 2.0 via sendTo #167

Closed swissglider closed 2 years ago

swissglider commented 3 years ago

Would it be possible that you implement the delete command for the InfluxDB so we can used it via sendTo:

function processMessage(adapter, msg) {
    ...
    else if (msg.command === 'delete') {
        deleteInfluxDB2(adapter, msg);
    }
    ...
}

function deleteInfluxDB2(adapter, msg) {
    adapter.log.debug("deleteInfluxDB2");
    try {
        const deleteStruct = {
            body: ... JSON.parse(msg.message.delete) ...,
            org: adapter.config.organization,
            bucket: adapter.config.dbname
        }
        adapter._client.deleteAPI.postDelete(deleteStruct).then(()=>{
            ....
            adapter.sendTo(msg.from, msg.command, {...}, msg.callback);
        });
    } catch(error){
        ...
    }
}


const sendToCommandStruct = {
    start: '1970-08-16T08:00:00Z',
    stop: '2021-09-19T10:00:00Z',
    predicate:`_measurement="netatmo.0.Zuhaus-(Weather-Station).Outdoor-Module.Temperature.Temperature"`
}
sendTo('influxdb.0', 'delete', JSON.stringify(sendToCommandStruct), ...);
Apollon77 commented 3 years ago

Please provide as PR ... but we should also check on the new Admin5 messages that we do not have a collision here because Admin5 also allows several "maintenance" messages

Apollon77 commented 2 years ago

@Excodibur what do you think?

Excodibur commented 2 years ago

It looks like this could be used to delete points from the Influx 2 DB (https://docs.influxdata.com/influxdb/v2.1/write-data/delete-data/). The thing is that it works different in Influx 1 (https://docs.influxdata.com/influxdb/v1.8/query_language/manage-database/#delete-series-with-delete), so we need to find a way for it to work with both version, or have release-specific implementations.

@Apollon77 I could not find a definition of the new Admin5 messages you refered to, but I saw that Bluefox added a similar feature to The SQL Adapter with 1.13: https://github.com/ioBroker/ioBroker.sql#delete-state

Apollon77 commented 2 years ago

Ich denke man sagt per https://github.com/ioBroker/ioBroker.sql/blob/744bf7d527612b3d12e5816e5e697aa39c6774ba/main.js#L885-L887 "was der adapter kann" und dann die relevanten Messages implementieren https://github.com/ioBroker/ioBroker.sql/blob/744bf7d527612b3d12e5816e5e697aa39c6774ba/main.js#L903-L914

(ja ja so könnte man es auch InfluxDB versions-spezifisch machen :-) )

Apollon77 commented 2 years ago

delete All is implemented already