added url validation when adding data source, Fixes #2043

This commit is contained in:
Torkel Ödegaard 2015-06-01 14:02:24 +02:00
parent e2f6633d57
commit afede880e6
2 changed files with 17 additions and 1 deletions

View File

@ -6,7 +6,7 @@
Url
</li>
<li>
<input type="text" class="tight-form-input input-xlarge" ng-model='current.url' placeholder="http://my.server.com:8080" required></input>
<input type="text" class="tight-form-input input-xlarge" ng-model='current.url' placeholder="http://my.server.com:8080" ng-pattern="/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/" required></input>
</li>
<li class="tight-form-item">
Access <tip>Direct = url is used directly from browser, Proxy = Grafana backend will proxy the request</label>

View File

@ -126,6 +126,22 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
return this._influxRequest('GET', '/query', {q: query});
};
InfluxDatasource.prototype.testDatasource = function() {
return this.metricFindQuery('SHOW MEASUREMENTS LIMIT 1').then(function () {
return { status: "success", message: "Data source is working", title: "Success" };
}, function(err) {
var message, title;
if (err.statusText) {
message = err.statusText;
title = "HTTP Error";
} else {
message = err;
title = "Unknown error";
}
return { status: "error", message: message, title: title };
});
};
InfluxDatasource.prototype._influxRequest = function(method, url, data) {
var self = this;
var deferred = $q.defer();