Jelajahi Sumber

influxdb: validate database exist when saving data source, fixes #7864

Torkel Ödegaard 8 tahun lalu
induk
melakukan
89a7c2c686

+ 0 - 2
public/app/core/components/query_part/query_part.ts

@@ -119,5 +119,3 @@ export function identityRenderer(part, innerExpr) {
 export function quotedIdentityRenderer(part, innerExpr) {
   return '"' + part.params[0] + '"';
 }
-
-

+ 10 - 1
public/app/plugins/datasource/influxdb/datasource.ts

@@ -193,8 +193,17 @@ export default class InfluxDatasource {
   }
 
   testDatasource() {
-    return this.metricFindQuery('SHOW MEASUREMENTS LIMIT 1').then(() => {
+    return this.metricFindQuery('SHOW DATABASES').then(res => {
+      let found = _.find(res, {text: this.database});
+      if (!found) {
+        return { status: "error", message: "Could not find the specified database name.", title: "DB Not found" };
+      }
       return { status: "success", message: "Data source is working", title: "Success" };
+    }).catch(err => {
+      if (err.data && err.message) {
+        return { status: "error", message: err.data.message, title: "InfluxDB Error" };
+      }
+      return { status: "error", message: err.toString(), title: "InfluxDB Error" };
     });
   }
 

+ 0 - 1
public/app/plugins/datasource/influxdb/query_part.ts

@@ -292,7 +292,6 @@ register({
   renderer: functionRenderer,
 });
 
-debugger;
 register({
   type: 'holt_winters_with_fit',
   addStrategy: addTransformationStrategy,