use of org.netxms.client.datacollection.DciSummaryTableColumn in project netxms by netxms.
the class DataCollectionTest method testAdHocDciSummaryTables.
public void testAdHocDciSummaryTables() throws Exception {
final NXCSession session = connect();
// single instance
List<DciSummaryTableColumn> columns = new ArrayList<DciSummaryTableColumn>();
columns.add(new DciSummaryTableColumn("Usage", "System.CPU.Usage", 0, ";"));
columns.add(new DciSummaryTableColumn("I/O Wait", "System.CPU.IOWait", 0, ";"));
Table result = session.queryAdHocDciSummaryTable(2, columns, AggregationFunction.AVERAGE, new Date(System.currentTimeMillis() - 86400000), new Date(), false);
printTable(result);
// multi instance
columns.clear();
columns.add(new DciSummaryTableColumn("Free %", "FileSystem\\.FreePerc\\(.*\\)", DciSummaryTableColumn.REGEXP_MATCH, ";"));
columns.add(new DciSummaryTableColumn("Free bytes", "FileSystem\\.Free\\(.*\\)", DciSummaryTableColumn.REGEXP_MATCH, ";"));
result = session.queryAdHocDciSummaryTable(2, columns, AggregationFunction.LAST, null, null, true);
printTable(result);
session.disconnect();
}
use of org.netxms.client.datacollection.DciSummaryTableColumn in project netxms by netxms.
the class SummaryTableAdHoc method create.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#create(org.json.JSONObject)
*/
@Override
protected Object create(JSONObject data) throws Exception {
NXCSession session = getSession();
if (!session.isObjectsSynchronized())
session.syncObjects();
String objectFilter = JsonTools.getStringFromJson(data, "baseObject", null);
log.debug("POST adhoc summaryTable: baseObject = " + objectFilter);
JSONArray columnFilter = JsonTools.getJsonArrayFromJson(data, "columns", null);
if (objectFilter == null || objectFilter.isEmpty() || columnFilter == null) {
log.warn("POST adhoc summaryTable: no DciSummaryTableColumn table or no value for BaseObject");
return createErrorResponse(RCC.INVALID_ARGUMENT);
}
long baseObjectId;
try {
baseObjectId = Long.parseLong(objectFilter);
} catch (NumberFormatException ex) {
AbstractObject obj = session.findObjectByName(objectFilter);
if (obj != null)
baseObjectId = obj.getObjectId();
else
baseObjectId = 0;
}
List<DciSummaryTableColumn> columns = new ArrayList<DciSummaryTableColumn>();
for (int i = 0; i < columnFilter.length(); i++) {
JSONObject obj = columnFilter.getJSONObject(i);
columns.add(new DciSummaryTableColumn(JsonTools.getStringFromJson(obj, "columnName", ""), JsonTools.getStringFromJson(obj, "dciName", ""), JsonTools.getBooleanFromJson(obj, "isRegexp", false) ? DciSummaryTableColumn.REGEXP_MATCH : 0));
}
AggregationFunction agrFunc = JsonTools.getEnumFromJson(data, AggregationFunction.class, "aggregationFunction", null);
Date startDate;
Date endDate;
long date = JsonTools.getLongFromJson(data, "startDate", -1);
startDate = date > 0 ? new Date(date * 1000) : null;
date = JsonTools.getLongFromJson(data, "endDate", -1);
endDate = date > 0 ? new Date(date * 1000) : null;
// end date
boolean multiInstance = JsonTools.getBooleanFromJson(data, "multiInstance", true);
Table table = session.queryAdHocDciSummaryTable(baseObjectId, columns, agrFunc, startDate, endDate, multiInstance);
// create json
JSONObject root = new JSONObject();
JSONArray columnList = new JSONArray();
JSONArray rowList = new JSONArray();
String[] names = table.getColumnDisplayNames();
for (int i = 0; i < names.length; i++) columnList.put(names[i]);
root.put("columns", columnList);
TableRow[] rows = table.getAllRows();
for (int i = 0; i < rows.length; i++) {
JSONArray row = new JSONArray();
for (int j = 0; j < rows[i].size(); j++) row.put(rows[i].get(j).getValue());
rowList.put(row);
}
root.put("rows", rowList);
return new ResponseContainer("table", root);
}
use of org.netxms.client.datacollection.DciSummaryTableColumn in project netxms by netxms.
the class SummaryTableColumns method moveDown.
/**
* Move currently selected element down
*/
private void moveDown() {
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() == 1) {
final DciSummaryTableColumn column = (DciSummaryTableColumn) selection.getFirstElement();
int index = columns.indexOf(column);
if ((index < columns.size() - 1) && (index >= 0)) {
Collections.swap(columns, index + 1, index);
viewer.setInput(columns.toArray());
viewer.setSelection(new StructuredSelection(column));
}
}
}
use of org.netxms.client.datacollection.DciSummaryTableColumn in project netxms by netxms.
the class SummaryTableColumns method importColumns.
/**
* Import Columns from node
*/
private void importColumns() {
final SelectDciDialog dialog = new SelectDciDialog(getShell(), 0);
dialog.setAllowTemplateItems(true);
dialog.setEnableEmptySelection(false);
if (dialog.open() == Dialog.OK) {
final List<DciValue> selection = dialog.getSelection();
List<DciSummaryTableColumn> select = new ArrayList<DciSummaryTableColumn>();
for (DciValue item : selection) {
DciSummaryTableColumn column = new DciSummaryTableColumn(item.getDescription(), item.getName(), 0, ";");
select.add(column);
columns.add(column);
}
viewer.setInput(columns.toArray());
viewer.setSelection(new StructuredSelection(select));
}
}
use of org.netxms.client.datacollection.DciSummaryTableColumn in project netxms by netxms.
the class DataCollectionTest method testDciSummaryTables.
public void testDciSummaryTables() throws Exception {
final NXCSession session = connect();
DciSummaryTable t = new DciSummaryTable("test", "Test Table");
t.getColumns().add(new DciSummaryTableColumn("Idle", "System.CPU.Idle"));
t.getColumns().add(new DciSummaryTableColumn("I/O Wait", "System.CPU.IOWait"));
int id = session.modifyDciSummaryTable(t);
System.out.println("Assigned ID: " + id);
t.setId(id);
t.getColumns().add(new DciSummaryTableColumn("System", "^System\\.CPU\\.Sys.*", DciSummaryTableColumn.REGEXP_MATCH));
session.modifyDciSummaryTable(t);
List<DciSummaryTableDescriptor> list = session.listDciSummaryTables();
for (DciSummaryTableDescriptor d : list) System.out.println(d.getId() + ": " + d.getMenuPath() + " " + d.getTitle());
session.getDciSummaryTable(id);
session.deleteDciSummaryTable(id);
try {
session.getDciSummaryTable(id);
assertTrue(false);
} catch (NXCException e) {
if (e.getErrorCode() != RCC.INVALID_SUMMARY_TABLE_ID)
throw e;
}
session.disconnect();
}
Aggregations