add host name to multiple text metrics
This commit is contained in:
26
dist/datasource-zabbix/datasource.js
vendored
26
dist/datasource-zabbix/datasource.js
vendored
@@ -74,19 +74,6 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return replacedTarget;
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
var extractPattern = new RegExp(pattern);
|
||||
var extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}
|
||||
|
||||
// Apply function one by one:
|
||||
// sequence([a(), b(), c()]) = c(b(a()));
|
||||
function sequence(funcsArray) {
|
||||
@@ -255,8 +242,6 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
var useTrendsRange = Math.ceil(utils.parseInterval(this.trendsRange) / 1000);
|
||||
var useTrends = this.trends && (timeFrom <= useTrendsFrom || timeTo - timeFrom >= useTrendsRange);
|
||||
|
||||
console.log(useTrends);
|
||||
|
||||
// Get alerts for current panel
|
||||
if (this.alertingEnabled) {
|
||||
this.alertQuery(options).then(function (alert) {
|
||||
@@ -442,16 +427,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||
if (items.length) {
|
||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.convertHistory(history, items, false, function (point) {
|
||||
var value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [value, point.clock * 1000 + Math.round(point.ns / 1000000)];
|
||||
});
|
||||
return responseHandler.handleText(history, items, target);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve([]);
|
||||
|
||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
42
dist/datasource-zabbix/responseHandler.js
vendored
42
dist/datasource-zabbix/responseHandler.js
vendored
@@ -55,7 +55,34 @@ System.register(['lodash'], function (_export, _context) {
|
||||
return convertHistory(history, items, addHostName, convertPointCallback);
|
||||
}
|
||||
|
||||
function handleSLAResponse(itservice, slaProperty, slaObject) {
|
||||
function handleText(history, items, target) {
|
||||
var addHostName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
||||
|
||||
var convertTextCallback = _.partial(convertText, target);
|
||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||
}function convertText(target, point) {
|
||||
var value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [value, point.clock * 1000 + Math.round(point.ns / 1000000)];
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
var extractPattern = new RegExp(pattern);
|
||||
var extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}function handleSLAResponse(itservice, slaProperty, slaObject) {
|
||||
var targetSLA = slaObject[itservice.serviceid].sla[0];
|
||||
if (slaProperty.property === 'status') {
|
||||
var targetStatus = parseInt(slaObject[itservice.serviceid].status);
|
||||
@@ -69,12 +96,12 @@ System.register(['lodash'], function (_export, _context) {
|
||||
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 + Math.round(point.ns / 1000000)];
|
||||
}
|
||||
|
||||
function convertTrendPoint(valueType, point) {
|
||||
function convertHistoryPoint(point) {
|
||||
// Value must be a number for properly work
|
||||
return [Number(point.value), point.clock * 1000 + Math.round(point.ns / 1000000)];
|
||||
}function convertTrendPoint(valueType, point) {
|
||||
var value;
|
||||
switch (valueType) {
|
||||
case "min":
|
||||
@@ -97,7 +124,9 @@ System.register(['lodash'], function (_export, _context) {
|
||||
}
|
||||
|
||||
return [Number(value), point.clock * 1000];
|
||||
}return {
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}],
|
||||
@@ -106,6 +135,7 @@ System.register(['lodash'], function (_export, _context) {
|
||||
handleHistory: handleHistory,
|
||||
convertHistory: convertHistory,
|
||||
handleTrends: handleTrends,
|
||||
handleText: handleText,
|
||||
handleSLAResponse: handleSLAResponse
|
||||
});
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
26
dist/test/datasource-zabbix/datasource.js
vendored
26
dist/test/datasource-zabbix/datasource.js
vendored
@@ -113,8 +113,6 @@ var ZabbixAPIDatasource = function () {
|
||||
var useTrendsRange = Math.ceil(utils.parseInterval(this.trendsRange) / 1000);
|
||||
var useTrends = this.trends && (timeFrom <= useTrendsFrom || timeTo - timeFrom >= useTrendsRange);
|
||||
|
||||
console.log(useTrends);
|
||||
|
||||
// Get alerts for current panel
|
||||
if (this.alertingEnabled) {
|
||||
this.alertQuery(options).then(function (alert) {
|
||||
@@ -300,16 +298,7 @@ var ZabbixAPIDatasource = function () {
|
||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||
if (items.length) {
|
||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.convertHistory(history, items, false, function (point) {
|
||||
var value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [value, point.clock * 1000 + Math.round(point.ns / 1000000)];
|
||||
});
|
||||
return _responseHandler2.default.handleText(history, items, target);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve([]);
|
||||
@@ -623,19 +612,6 @@ function replaceTemplateVars(templateSrv, target, scopedVars) {
|
||||
return replacedTarget;
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
var extractPattern = new RegExp(pattern);
|
||||
var extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}
|
||||
|
||||
// Apply function one by one:
|
||||
// sequence([a(), b(), c()]) = c(b(a()));
|
||||
function sequence(funcsArray) {
|
||||
|
||||
32
dist/test/datasource-zabbix/responseHandler.js
vendored
32
dist/test/datasource-zabbix/responseHandler.js
vendored
@@ -62,6 +62,37 @@ function handleTrends(history, items, valueType) {
|
||||
return convertHistory(history, items, addHostName, convertPointCallback);
|
||||
}
|
||||
|
||||
function handleText(history, items, target) {
|
||||
var addHostName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
||||
|
||||
var convertTextCallback = _lodash2.default.partial(convertText, target);
|
||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||
}
|
||||
|
||||
function convertText(target, point) {
|
||||
var value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [value, point.clock * 1000 + Math.round(point.ns / 1000000)];
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
var extractPattern = new RegExp(pattern);
|
||||
var extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}
|
||||
|
||||
function handleSLAResponse(itservice, slaProperty, slaObject) {
|
||||
var targetSLA = slaObject[itservice.serviceid].sla[0];
|
||||
if (slaProperty.property === 'status') {
|
||||
@@ -112,6 +143,7 @@ exports.default = {
|
||||
handleHistory: handleHistory,
|
||||
convertHistory: convertHistory,
|
||||
handleTrends: handleTrends,
|
||||
handleText: handleText,
|
||||
handleSLAResponse: handleSLAResponse
|
||||
};
|
||||
|
||||
|
||||
@@ -68,8 +68,6 @@ class ZabbixAPIDatasource {
|
||||
(timeTo - timeFrom >= useTrendsRange)
|
||||
);
|
||||
|
||||
console.log(useTrends);
|
||||
|
||||
// Get alerts for current panel
|
||||
if (this.alertingEnabled) {
|
||||
this.alertQuery(options).then(alert => {
|
||||
@@ -246,19 +244,7 @@ class ZabbixAPIDatasource {
|
||||
if (items.length) {
|
||||
return this.zabbix.getHistory(items, timeFrom, timeTo)
|
||||
.then(history => {
|
||||
return responseHandler.convertHistory(history, items, false, (point) => {
|
||||
let value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [
|
||||
value,
|
||||
point.clock * 1000 + Math.round(point.ns / 1000000)
|
||||
];
|
||||
});
|
||||
return responseHandler.handleText(history, items, target);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve([]);
|
||||
@@ -558,19 +544,6 @@ function replaceTemplateVars(templateSrv, target, scopedVars) {
|
||||
return replacedTarget;
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
let extractPattern = new RegExp(pattern);
|
||||
let extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}
|
||||
|
||||
// Apply function one by one:
|
||||
// sequence([a(), b(), c()]) = c(b(a()));
|
||||
function sequence(funcsArray) {
|
||||
|
||||
@@ -47,6 +47,38 @@ function handleTrends(history, items, valueType, addHostName = true) {
|
||||
return convertHistory(history, items, addHostName, convertPointCallback);
|
||||
}
|
||||
|
||||
function handleText(history, items, target, addHostName = true) {
|
||||
let convertTextCallback = _.partial(convertText, target);
|
||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||
}
|
||||
|
||||
function convertText(target, point) {
|
||||
let value = point.value;
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
value = extractText(point.value, target.textFilter, target.useCaptureGroups);
|
||||
}
|
||||
|
||||
return [
|
||||
value,
|
||||
point.clock * 1000 + Math.round(point.ns / 1000000)
|
||||
];
|
||||
}
|
||||
|
||||
function extractText(str, pattern, useCaptureGroups) {
|
||||
let extractPattern = new RegExp(pattern);
|
||||
let extractedValue = extractPattern.exec(str);
|
||||
if (extractedValue) {
|
||||
if (useCaptureGroups) {
|
||||
extractedValue = extractedValue[1];
|
||||
} else {
|
||||
extractedValue = extractedValue[0];
|
||||
}
|
||||
}
|
||||
return extractedValue;
|
||||
}
|
||||
|
||||
function handleSLAResponse(itservice, slaProperty, slaObject) {
|
||||
var targetSLA = slaObject[itservice.serviceid].sla[0];
|
||||
if (slaProperty.property === 'status') {
|
||||
@@ -108,6 +140,7 @@ export default {
|
||||
handleHistory: handleHistory,
|
||||
convertHistory: convertHistory,
|
||||
handleTrends: handleTrends,
|
||||
handleText: handleText,
|
||||
handleSLAResponse: handleSLAResponse
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user