Add dist/ directory to repo to correspond development guide.

http://docs.grafana.org/plugins/development/
This commit is contained in:
Alexander Zobnin
2017-02-02 11:33:54 +03:00
parent 658e436198
commit 0b3f537341
88 changed files with 11482 additions and 1 deletions

View File

@@ -0,0 +1,113 @@
'use strict';
System.register(['lodash'], function (_export, _context) {
"use strict";
var _;
/**
* Convert Zabbix API history.get response to Grafana format
*
* @return {Array} Array of timeseries in Grafana format
* {
* target: "Metric name",
* datapoints: [[<value>, <unixtime>], ...]
* }
*/
function convertHistory(history, items, addHostName, convertPointCallback) {
/**
* Response should be in the format:
* data: [
* {
* target: "Metric name",
* datapoints: [[<value>, <unixtime>], ...]
* }, ...
* ]
*/
// Group history by itemid
var grouped_history = _.groupBy(history, 'itemid');
var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate
return _.map(grouped_history, function (hist, itemid) {
var item = _.find(items, { 'itemid': itemid });
var alias = item.name;
if (_.keys(hosts).length > 1 && addHostName) {
//only when actual multi hosts selected
var host = _.find(hosts, { 'hostid': item.hostid });
alias = host.name + ": " + alias;
}
return {
target: alias,
datapoints: _.map(hist, convertPointCallback)
};
});
}
function handleHistory(history, items) {
var addHostName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return convertHistory(history, items, addHostName, convertHistoryPoint);
}function handleTrends(history, items, valueType) {
var addHostName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
var convertPointCallback = _.partial(convertTrendPoint, valueType);
return convertHistory(history, items, addHostName, convertPointCallback);
}
function handleSLAResponse(itservice, slaProperty, slaObject) {
var targetSLA = slaObject[itservice.serviceid].sla[0];
if (slaProperty.property === 'status') {
var targetStatus = parseInt(slaObject[itservice.serviceid].status);
return {
target: itservice.name + ' ' + slaProperty.name,
datapoints: [[targetStatus, targetSLA.to * 1000]]
};
} else {
return {
target: itservice.name + ' ' + slaProperty.name,
datapoints: [[targetSLA[slaProperty.property], targetSLA.from * 1000], [targetSLA[slaProperty.property], targetSLA.to * 1000]]
};
}
}function convertHistoryPoint(point) {
// Value must be a number for properly work
return [Number(point.value), point.clock * 1000];
}
function convertTrendPoint(valueType, point) {
var value;
switch (valueType) {
case "min":
value = point.value_min;
break;
case "max":
value = point.value_max;
break;
case "avg":
value = point.value_avg;
break;
default:
value = point.value_avg;
}
return [Number(value), point.clock * 1000];
}return {
setters: [function (_lodash) {
_ = _lodash.default;
}],
execute: function () {
_export('default', {
handleHistory: handleHistory,
convertHistory: convertHistory,
handleTrends: handleTrends,
handleSLAResponse: handleSLAResponse
});
// Fix for backward compatibility with lodash 2.4
if (!_.uniqBy) {
_.uniqBy = _.uniq;
}
}
};
});
//# sourceMappingURL=responseHandler.js.map