|
@@ -19,6 +19,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
this.username = datasource.username;
|
|
this.username = datasource.username;
|
|
|
this.password = datasource.password;
|
|
this.password = datasource.password;
|
|
|
this.name = datasource.name;
|
|
this.name = datasource.name;
|
|
|
|
|
+ this.basicAuth = datasource.basicAuth;
|
|
|
|
|
|
|
|
this.saveTemp = _.isUndefined(datasource.save_temp) ? true : datasource.save_temp;
|
|
this.saveTemp = _.isUndefined(datasource.save_temp) ? true : datasource.save_temp;
|
|
|
this.saveTempTTL = _.isUndefined(datasource.save_temp_ttl) ? '30d' : datasource.save_temp_ttl;
|
|
this.saveTempTTL = _.isUndefined(datasource.save_temp_ttl) ? '30d' : datasource.save_temp_ttl;
|
|
@@ -63,7 +64,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
InfluxDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
|
|
InfluxDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
|
|
|
var timeFilter = getTimeFilter({ range: rangeUnparsed });
|
|
var timeFilter = getTimeFilter({ range: rangeUnparsed });
|
|
|
var query = annotation.query.replace('$timeFilter', timeFilter);
|
|
var query = annotation.query.replace('$timeFilter', timeFilter);
|
|
|
- query = templateSrv.replace(annotation.query);
|
|
|
|
|
|
|
+ query = templateSrv.replace(query);
|
|
|
|
|
|
|
|
return this._seriesQuery(query).then(function(results) {
|
|
return this._seriesQuery(query).then(function(results) {
|
|
|
return new InfluxSeries({ seriesList: results, annotation: annotation }).getAnnotations();
|
|
return new InfluxSeries({ seriesList: results, annotation: annotation }).getAnnotations();
|
|
@@ -170,6 +171,11 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
inspect: { type: 'influxdb' },
|
|
inspect: { type: 'influxdb' },
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ options.headers = options.headers || {};
|
|
|
|
|
+ if (_this.basicAuth) {
|
|
|
|
|
+ options.headers.Authorization = 'Basic ' + _this.basicAuth;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return $http(options).success(function (data) {
|
|
return $http(options).success(function (data) {
|
|
|
deferred.resolve(data);
|
|
deferred.resolve(data);
|
|
|
});
|
|
});
|
|
@@ -182,34 +188,46 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
var tags = dashboard.tags.join(',');
|
|
var tags = dashboard.tags.join(',');
|
|
|
var title = dashboard.title;
|
|
var title = dashboard.title;
|
|
|
var temp = dashboard.temp;
|
|
var temp = dashboard.temp;
|
|
|
|
|
+ var id = kbn.slugifyForUrl(title);
|
|
|
if (temp) { delete dashboard.temp; }
|
|
if (temp) { delete dashboard.temp; }
|
|
|
|
|
|
|
|
var data = [{
|
|
var data = [{
|
|
|
- name: 'grafana.dashboard_' + btoa(title),
|
|
|
|
|
- columns: ['time', 'sequence_number', 'title', 'tags', 'dashboard'],
|
|
|
|
|
- points: [[1000000000000, 1, title, tags, angular.toJson(dashboard)]]
|
|
|
|
|
|
|
+ name: 'grafana.dashboard_' + btoa(id),
|
|
|
|
|
+ columns: ['time', 'sequence_number', 'title', 'tags', 'dashboard', 'id'],
|
|
|
|
|
+ points: [[1000000000000, 1, title, tags, angular.toJson(dashboard), id]]
|
|
|
}];
|
|
}];
|
|
|
|
|
|
|
|
if (temp) {
|
|
if (temp) {
|
|
|
- return this._saveDashboardTemp(data, title);
|
|
|
|
|
|
|
+ return this._saveDashboardTemp(data, title, id);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
|
|
+ var self = this;
|
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
|
|
- return { title: title, url: '/dashboard/db/' + title };
|
|
|
|
|
|
|
+ self._removeUnslugifiedDashboard(title, false);
|
|
|
|
|
+ return { title: title, url: '/dashboard/db/' + id };
|
|
|
}, function(err) {
|
|
}, function(err) {
|
|
|
throw 'Failed to save dashboard to InfluxDB: ' + err.data;
|
|
throw 'Failed to save dashboard to InfluxDB: ' + err.data;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- InfluxDatasource.prototype._saveDashboardTemp = function(data, title) {
|
|
|
|
|
- data[0].name = 'grafana.temp_dashboard_' + btoa(title);
|
|
|
|
|
|
|
+ InfluxDatasource.prototype._removeUnslugifiedDashboard = function(id, isTemp) {
|
|
|
|
|
+ var self = this;
|
|
|
|
|
+ self._getDashboardInternal(id, isTemp).then(function(dashboard) {
|
|
|
|
|
+ if (dashboard !== null) {
|
|
|
|
|
+ self.deleteDashboard(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ InfluxDatasource.prototype._saveDashboardTemp = function(data, title, id) {
|
|
|
|
|
+ data[0].name = 'grafana.temp_dashboard_' + btoa(id);
|
|
|
data[0].columns.push('expires');
|
|
data[0].columns.push('expires');
|
|
|
data[0].points[0].push(this._getTempDashboardExpiresDate());
|
|
data[0].points[0].push(this._getTempDashboardExpiresDate());
|
|
|
|
|
|
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
|
|
var baseUrl = window.location.href.replace(window.location.hash,'');
|
|
var baseUrl = window.location.href.replace(window.location.hash,'');
|
|
|
- var url = baseUrl + "#dashboard/temp/" + title;
|
|
|
|
|
|
|
+ var url = baseUrl + "#dashboard/temp/" + id;
|
|
|
return { title: title, url: url };
|
|
return { title: title, url: url };
|
|
|
}, function(err) {
|
|
}, function(err) {
|
|
|
throw 'Failed to save shared dashboard to InfluxDB: ' + err.data;
|
|
throw 'Failed to save shared dashboard to InfluxDB: ' + err.data;
|
|
@@ -236,7 +254,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
return expires;
|
|
return expires;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- InfluxDatasource.prototype.getDashboard = function(id, isTemp) {
|
|
|
|
|
|
|
+ InfluxDatasource.prototype._getDashboardInternal = function(id, isTemp) {
|
|
|
var queryString = 'select dashboard from "grafana.dashboard_' + btoa(id) + '"';
|
|
var queryString = 'select dashboard from "grafana.dashboard_' + btoa(id) + '"';
|
|
|
|
|
|
|
|
if (isTemp) {
|
|
if (isTemp) {
|
|
@@ -245,15 +263,34 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
|
|
|
|
|
return this._seriesQuery(queryString).then(function(results) {
|
|
return this._seriesQuery(queryString).then(function(results) {
|
|
|
if (!results || !results.length) {
|
|
if (!results || !results.length) {
|
|
|
- throw "Dashboard not found";
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var dashCol = _.indexOf(results[0].columns, 'dashboard');
|
|
var dashCol = _.indexOf(results[0].columns, 'dashboard');
|
|
|
var dashJson = results[0].points[0][dashCol];
|
|
var dashJson = results[0].points[0][dashCol];
|
|
|
|
|
|
|
|
return angular.fromJson(dashJson);
|
|
return angular.fromJson(dashJson);
|
|
|
|
|
+ }, function() {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ InfluxDatasource.prototype.getDashboard = function(id, isTemp) {
|
|
|
|
|
+ var self = this;
|
|
|
|
|
+ return this._getDashboardInternal(id, isTemp).then(function(dashboard) {
|
|
|
|
|
+ if (dashboard !== null) {
|
|
|
|
|
+ return dashboard;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // backward compatible load for unslugified ids
|
|
|
|
|
+ var slug = kbn.slugifyForUrl(id);
|
|
|
|
|
+ if (slug !== id) {
|
|
|
|
|
+ return self.getDashboard(slug, isTemp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ throw "Dashboard not found";
|
|
|
}, function(err) {
|
|
}, function(err) {
|
|
|
- return "Could not load dashboard, " + err.data;
|
|
|
|
|
|
|
+ throw "Could not load dashboard, " + err.data;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -264,12 +301,12 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
}
|
|
}
|
|
|
return id;
|
|
return id;
|
|
|
}, function(err) {
|
|
}, function(err) {
|
|
|
- return "Could not delete dashboard, " + err.data;
|
|
|
|
|
|
|
+ throw "Could not delete dashboard, " + err.data;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
InfluxDatasource.prototype.searchDashboards = function(queryString) {
|
|
InfluxDatasource.prototype.searchDashboards = function(queryString) {
|
|
|
- var influxQuery = 'select title, tags from /grafana.dashboard_.*/ where ';
|
|
|
|
|
|
|
+ var influxQuery = 'select * from /grafana.dashboard_.*/ where ';
|
|
|
|
|
|
|
|
var tagsOnly = queryString.indexOf('tags!:') === 0;
|
|
var tagsOnly = queryString.indexOf('tags!:') === 0;
|
|
|
if (tagsOnly) {
|
|
if (tagsOnly) {
|
|
@@ -294,15 +331,21 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
|
|
|
return hits;
|
|
return hits;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var dashCol = _.indexOf(results[0].columns, 'title');
|
|
|
|
|
- var tagsCol = _.indexOf(results[0].columns, 'tags');
|
|
|
|
|
-
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
+ var dashCol = _.indexOf(results[i].columns, 'title');
|
|
|
|
|
+ var tagsCol = _.indexOf(results[i].columns, 'tags');
|
|
|
|
|
+ var idCol = _.indexOf(results[i].columns, 'id');
|
|
|
|
|
+
|
|
|
var hit = {
|
|
var hit = {
|
|
|
id: results[i].points[0][dashCol],
|
|
id: results[i].points[0][dashCol],
|
|
|
title: results[i].points[0][dashCol],
|
|
title: results[i].points[0][dashCol],
|
|
|
tags: results[i].points[0][tagsCol].split(",")
|
|
tags: results[i].points[0][tagsCol].split(",")
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ if (idCol !== -1) {
|
|
|
|
|
+ hit.id = results[i].points[0][idCol];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
hit.tags = hit.tags[0] ? hit.tags : [];
|
|
hit.tags = hit.tags[0] ? hit.tags : [];
|
|
|
hits.dashboards.push(hit);
|
|
hits.dashboards.push(hit);
|
|
|
}
|
|
}
|