Support table mode for text data

This commit is contained in:
Alexander Zobnin
2017-12-27 14:44:06 +03:00
parent a8b2e3c88c
commit 9eeb4fe468
14 changed files with 92 additions and 22 deletions

View File

@@ -54,6 +54,29 @@ function handleText(history, items, target, addHostName = true) {
return convertHistory(history, items, addHostName, convertTextCallback);
}
function handleHistoryAsTable(history, items) {
let table = new TableModel();
table.addColumn({text: 'Host'});
table.addColumn({text: 'Item'});
table.addColumn({text: 'Key'});
table.addColumn({text: 'Last value'});
let grouped_history = _.groupBy(history, 'itemid');
_.each(items, (item) => {
let itemHistory = grouped_history[item.itemid] || [];
let lastPoint = _.last(itemHistory);
let lastValue = lastPoint ? lastPoint.value : null;
let host = _.first(item.hosts);
host = host ? host.name : "";
table.rows.push([
host, item.name, item.key_, lastValue
]);
});
return table;
}
function convertText(target, point) {
let value = point.value;
@@ -182,6 +205,7 @@ export default {
convertHistory: convertHistory,
handleTrends: handleTrends,
handleText: handleText,
handleHistoryAsTable: handleHistoryAsTable,
handleSLAResponse: handleSLAResponse,
handleTriggersResponse: handleTriggersResponse
};