Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comands for JSON/Simple-JSON Grafana Plugin added #20

Merged
merged 15 commits into from
Jul 2, 2019

Conversation

marcokaminski
Copy link
Contributor

Some commands have been added to visualize data in Grafana without having to create SQL queries.
For Grafana there are 2 plugins working with the new commands.

In the forum there is a post about it https://forum.iobroker.net/topic/23033/aufruf-modifikation-simpleapi-adapter-iobroker-als-datenquelle-f%C3%BCr-grafana
Issue #17 is then processed.

I had upgraded to version 2.0.3 and adopted the changes from 2.0.4 and 2.0.5.
I have left my changes as version 2.0.3, I hope that's okay.

@GermanBluefox
Copy link
Contributor

GermanBluefox commented Jun 29, 2019

Very interesting case. Thank you!
Only one improvement could be done: the iteration via all instances with common.getHistory flag set will return all instances that support "history" and there is no need to iterate sql, influx... extra.

function getHistoryInstances() {
    socket.emit('getObjectView', 'system', 'instance', {startkey: 'system.adapter.', endkey: 'system.adapter.' + '.\u9999'}, function (err, doc) {
        if (err) {
            console.error(err);
        } else {
            if (doc.rows.length) {
                var result = [];
                for (var i = 0; i < doc.rows.length; i++) {
                    result.push(doc.rows[i].value);
                }
                result = result.filter(function (adp) {
                    return adp && adp.common && adp.getHistory;
                });
                
                var text = '';
                for (var r = 0; r < result.length; r++) {
                    var name = result[r]._id.substring('system.adapter.'.length);
                    text += '<option value="' + name + '" ' + (settings.dataSource === name ? 'selected' : '') + '>' + name + '</option>';
                }
                $('#dataSource').append(text).select();
                showHideSettings();
            }
        }
        
    });
}

@marcokaminski
Copy link
Contributor Author

I had searched for such a function, a very good idea. I will implement that today or tomorrow.

@marcokaminski
Copy link
Contributor Author

I tried to install the function. But I get an empty rows-array when calling

socket.emit('getObjectView', 'system', 'instance', {startkey: 'system.adapter.', endkey: 'system.adapter.' + '.\u9999'}, function (err, doc)

There are instances of adapter history and influxdb.

index.html.txt

@GermanBluefox
Copy link
Contributor

There are two errors fixed:

function getHistoryInstances(settings) {
    socket.emit('getObjectView', 'system', 'instance', {startkey: 'system.adapter.', endkey: 'system.adapter.\u9999'}, function (err, doc) {
        if (err) {
            console.error(err);
        } else {
            if (doc.rows.length) {
                var result = [];
                for (var i = 0; i < doc.rows.length; i++) {
                    result.push(doc.rows[i].value);
                }
                result = result.filter(function (adp) {
                    return adp && adp.common && adp.common.getHistory;
                });
                
                var text = '';
                for (var r = 0; r < result.length; r++) {
                    var name = result[r]._id.substring('system.adapter.'.length);
                    text += '<option value="' + name + '" ' + (settings.dataSource === name ? 'selected' : '') + '>' + name + '</option>';
                }
                $('#dataSource').append(text).select();
                showHideSettings();
            }
        }
    });
}

@GermanBluefox GermanBluefox merged commit a314878 into ioBroker:master Jul 2, 2019
@Apollon77
Copy link
Contributor

Apollon77 commented Jul 3, 2019

@marcokaminski Could you please add infos about these new possibilities also to README nd maybe update the Forum thread?

@Apollon77
Copy link
Contributor

PS: We still need to do a 2.1.0 with these new features once verified working (e.g. via Forum check?)

@marcokaminski
Copy link
Contributor Author

@Apollon77 For the new commands (search, query) I had already adapted the README.md.
The feature proposed by Bluefox has just eliminated adapter customization for other adapters with history data.
I will announce in the forum post mentioned above, that the changes are now entered in the ioBroker repository and now this repository should be used.

@Apollon77
Copy link
Contributor

Finalization comments:

  • I changed it to get published as 2.1.0
  • enhancing tests for the new methods would be great :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants