Przeglądaj źródła

added url validation when adding data source, Fixes #2043

Torkel Ödegaard 10 lat temu
rodzic
commit
afede880e6

+ 1 - 1
public/app/features/org/partials/datasourceHttpConfig.html

@@ -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>

+ 16 - 0
public/app/plugins/datasource/influxdb/datasource.js

@@ -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();