Add options for table
This commit is contained in:
@@ -56,9 +56,15 @@ function handleText(history, items, target, addHostName = true) {
|
||||
|
||||
function handleHistoryAsTable(history, items, target) {
|
||||
let table = new TableModel();
|
||||
table.addColumn({text: 'Host'});
|
||||
table.addColumn({text: 'Item'});
|
||||
table.addColumn({text: 'Key'});
|
||||
if(target.table.host) {
|
||||
table.addColumn({text: 'Host'});
|
||||
}
|
||||
if(target.table.item) {
|
||||
table.addColumn({text: 'Item'});
|
||||
}
|
||||
if(target.table.key) {
|
||||
table.addColumn({text: 'Key'});
|
||||
}
|
||||
table.addColumn({text: 'Last value'});
|
||||
|
||||
let grouped_history = _.groupBy(history, 'itemid');
|
||||
@@ -67,6 +73,10 @@ function handleHistoryAsTable(history, items, target) {
|
||||
let lastPoint = _.last(itemHistory);
|
||||
let lastValue = lastPoint ? lastPoint.value : null;
|
||||
|
||||
if(target.table.skipEmptyValues && (!lastValue || lastValue === '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||
@@ -75,9 +85,19 @@ function handleHistoryAsTable(history, items, target) {
|
||||
let host = _.first(item.hosts);
|
||||
host = host ? host.name : "";
|
||||
|
||||
table.rows.push([
|
||||
host, item.name, item.key_, lastValue
|
||||
]);
|
||||
let row = [];
|
||||
if(target.table.host) {
|
||||
row.push(host);
|
||||
}
|
||||
if(target.table.item) {
|
||||
row.push(item.name);
|
||||
}
|
||||
if(target.table.key) {
|
||||
row.push(item.key_);
|
||||
}
|
||||
row.push(lastValue);
|
||||
|
||||
table.rows.push(row);
|
||||
});
|
||||
|
||||
return table;
|
||||
|
||||
Reference in New Issue
Block a user