Search in sources :

Example 1 with DciSummaryTableColumn

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();
}
Also used : DciSummaryTable(org.netxms.client.datacollection.DciSummaryTable) ArrayList(java.util.ArrayList) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) Date(java.util.Date)

Example 2 with DciSummaryTableColumn

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);
}
Also used : NXCSession(org.netxms.client.NXCSession) Table(org.netxms.client.Table) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Date(java.util.Date) AggregationFunction(org.netxms.client.constants.AggregationFunction) JSONObject(org.json.JSONObject) AbstractObject(org.netxms.client.objects.AbstractObject) TableRow(org.netxms.client.TableRow) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) ResponseContainer(org.netxms.websvc.json.ResponseContainer)

Example 3 with DciSummaryTableColumn

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));
        }
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with DciSummaryTableColumn

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));
    }
}
Also used : DciValue(org.netxms.client.datacollection.DciValue) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) SelectDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.SelectDciDialog)

Example 5 with DciSummaryTableColumn

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();
}
Also used : DciSummaryTable(org.netxms.client.datacollection.DciSummaryTable) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor)

Aggregations

DciSummaryTableColumn (org.netxms.client.datacollection.DciSummaryTableColumn)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 ArrayList (java.util.ArrayList)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 DciSummaryTable (org.netxms.client.datacollection.DciSummaryTable)3 Date (java.util.Date)2 EditDciSummaryTableColumnDlg (org.netxms.ui.eclipse.datacollection.dialogs.EditDciSummaryTableColumnDlg)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1