Search in sources :

Example 1 with DataCollectionItem

use of org.netxms.client.datacollection.DataCollectionItem in project netxms by netxms.

the class CreateInterfraceDci method createInterfaceDci.

/**
 * @param iface
 * @param dciType
 * @param dciInfo
 * @throws Exception
 */
private static void createInterfaceDci(NXCSession session, Interface iface, int dciType, InterfaceDciInfo dciInfo, int pollingInterval, int retentionTime, boolean updateDescription, Map<Long, Boolean> lockRequired) throws Exception {
    AbstractNode node = iface.getParentNode();
    if (node == null)
        throw new NXCException(RCC.INTERNAL_ERROR);
    DataCollectionConfiguration dcc;
    if (lockRequired.get(node.getObjectId())) {
        dcc = session.openDataCollectionConfiguration(node.getObjectId());
    } else {
        dcc = new DataCollectionConfiguration(session, node.getObjectId());
    }
    final DataCollectionItem dci = (DataCollectionItem) dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
    dci.setPollingInterval(pollingInterval);
    dci.setRetentionTime(retentionTime);
    if (node.hasAgent()) {
        dci.setOrigin(DataCollectionItem.AGENT);
        if (node.isAgentIfXCountersSupported())
            dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
        else
            dci.setDataType(DataType.COUNTER32);
    } else {
        dci.setOrigin(DataCollectionItem.SNMP);
        if (node.isIfXTableSupported())
            dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
        else
            dci.setDataType(DataType.COUNTER32);
    }
    dci.setStatus(DataCollectionItem.ACTIVE);
    // $NON-NLS-1$
    dci.setDescription(updateDescription ? dciInfo.description.replaceAll("@@ifName@@", iface.getObjectName()) : dciInfo.description);
    dci.setDeltaCalculation(dciInfo.delta ? DataCollectionItem.DELTA_AVERAGE_PER_SECOND : DataCollectionItem.DELTA_NONE);
    if (dci.getOrigin() == DataCollectionItem.AGENT) {
        switch(dciType) {
            case IFDCI_IN_BYTES:
            case IFDCI_IN_BITS:
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesIn64(" : "Net.Interface.BytesIn(") + iface.getIfIndex() + ")");
                break;
            case IFDCI_OUT_BYTES:
            case IFDCI_OUT_BITS:
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesOut64(" : "Net.Interface.BytesOut(") + iface.getIfIndex() + ")");
                break;
            case IFDCI_IN_PACKETS:
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsIn64(" : "Net.Interface.PacketsIn(") + iface.getIfIndex() + ")");
                break;
            case IFDCI_OUT_PACKETS:
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsOut64(" : "Net.Interface.PacketsOut(") + iface.getIfIndex() + ")");
                break;
            case IFDCI_IN_ERRORS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName("Net.Interface.InErrors(" + iface.getIfIndex() + ")");
                break;
            case IFDCI_OUT_ERRORS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName("Net.Interface.OutErrors(" + iface.getIfIndex() + ")");
                break;
        }
    } else {
        switch(dciType) {
            case IFDCI_IN_BYTES:
            case IFDCI_IN_BITS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.6" : ".1.3.6.1.2.1.2.2.1.10") + getInterfaceInstance(iface));
                break;
            case IFDCI_OUT_BYTES:
            case IFDCI_OUT_BITS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.10" : ".1.3.6.1.2.1.2.2.1.16") + getInterfaceInstance(iface));
                break;
            case IFDCI_IN_PACKETS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.7" : ".1.3.6.1.2.1.2.2.1.11") + getInterfaceInstance(iface));
                break;
            case IFDCI_OUT_PACKETS:
                // $NON-NLS-1$ //$NON-NLS-2$
                dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.11" : ".1.3.6.1.2.1.2.2.1.17") + getInterfaceInstance(iface));
                break;
            case IFDCI_IN_ERRORS:
                // $NON-NLS-1$
                dci.setName(".1.3.6.1.2.1.2.2.1.14" + getInterfaceInstance(iface));
                break;
            case IFDCI_OUT_ERRORS:
                // $NON-NLS-1$
                dci.setName(".1.3.6.1.2.1.2.2.1.20" + getInterfaceInstance(iface));
                break;
        }
    }
    if ((dciType == IFDCI_IN_BITS) || (dciType == IFDCI_OUT_BITS)) {
        // $NON-NLS-1$
        dci.setTransformationScript("return $1 * 8;");
    }
    dcc.modifyObject(dci);
    if (lockRequired.get(node.getObjectId())) {
        dcc.close();
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) NXCException(org.netxms.client.NXCException) DataCollectionConfiguration(org.netxms.client.datacollection.DataCollectionConfiguration)

Example 2 with DataCollectionItem

use of org.netxms.client.datacollection.DataCollectionItem in project netxms by netxms.

the class Transformation method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = (Composite) super.createContents(parent);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    if (editor.getObject() instanceof DataCollectionItem) {
        deltaCalculation = WidgetHelper.createLabeledCombo(dialogArea, SWT.BORDER | SWT.READ_ONLY, Messages.get().Transformation_Step1, WidgetHelper.DEFAULT_LAYOUT_DATA);
        deltaCalculation.add(Messages.get().Transformation_DeltaNone);
        deltaCalculation.add(Messages.get().Transformation_DeltaSimple);
        deltaCalculation.add(Messages.get().Transformation_DeltaAvgPerSec);
        deltaCalculation.add(Messages.get().Transformation_DeltaAvgPerMin);
        deltaCalculation.select(editor.getObjectAsItem().getDeltaCalculation());
    }
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.widthHint = 0;
    gd.heightHint = 0;
    final WidgetFactory factory = new WidgetFactory() {

        @Override
        public Control createControl(Composite parent, int style) {
            return new ScriptEditor(parent, style, SWT.H_SCROLL | SWT.V_SCROLL, true, "Variables:\r\n\t$1\t\t\tvalue to transform (after delta calculation);\r\n\t$dci\t\t\tthis DCI object;\r\n\t$isCluster\ttrue if DCI is on cluster;\r\n\t$node\t\tcurrent node object (null if DCI is not on the node);\r\n\t$object\t\tcurrent object.\r\n\r\nReturn value: transformed DCI value or null to keep original value.");
        }
    };
    transformationScript = (ScriptEditor) WidgetHelper.createLabeledControl(dialogArea, SWT.BORDER, factory, (editor.getObject() instanceof DataCollectionItem) ? Messages.get().Transformation_Step2 : Messages.get().Transformation_Script, gd);
    transformationScript.addFunctions(Arrays.asList(DCI_FUNCTIONS));
    transformationScript.addVariables(Arrays.asList(DCI_VARIABLES));
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    transformationScript.setLayoutData(gd);
    transformationScript.setText(editor.getObject().getTransformationScript());
    if (editor.getObject() instanceof DataCollectionItem) {
        testScriptButton = new Button(transformationScript.getParent(), SWT.PUSH);
        testScriptButton.setText(Messages.get().Transformation_Test);
        gd = new GridData();
        gd.horizontalAlignment = SWT.RIGHT;
        gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
        testScriptButton.setLayoutData(gd);
        testScriptButton.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TestTransformationDlg dlg = new TestTransformationDlg(getShell(), editor.getObject().getNodeId(), transformationScript.getText());
                dlg.open();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    return dialogArea;
}
Also used : TestTransformationDlg(org.netxms.ui.eclipse.datacollection.dialogs.TestTransformationDlg) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) WidgetFactory(org.netxms.ui.eclipse.tools.WidgetFactory) Button(org.eclipse.swt.widgets.Button) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with DataCollectionItem

use of org.netxms.client.datacollection.DataCollectionItem in project netxms by netxms.

the class DataCollectionEditor method createItem.

/**
 * Create new data collection item
 */
private void createItem() {
    DataCollectionItem dci = new DataCollectionItem(dciConfig, 0);
    if ((object instanceof AbstractNode) && !((AbstractNode) object).hasAgent()) {
        if (((AbstractNode) object).hasSnmpAgent()) {
            dci.setOrigin(DataCollectionObject.SNMP);
        } else {
            dci.setOrigin(DataCollectionObject.INTERNAL);
        }
    }
    viewer.add(dci);
    viewer.setSelection(new StructuredSelection(dci), true);
    actionEdit.run();
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 4 with DataCollectionItem

use of org.netxms.client.datacollection.DataCollectionItem in project netxms by netxms.

the class ShowDataComparisonChart method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (currentSelection != null) {
        // $NON-NLS-1$
        String id = Long.toString(uniqueId++) + "&" + Integer.toString(getChartType());
        for (int i = 0; i < currentSelection.length; i++) {
            long dciId = 0, nodeId = 0;
            int source = 0;
            DataType dataType = DataType.INT32;
            String name = null, description = null;
            try {
                if (currentSelection[i] instanceof DciValue) {
                    dciId = ((DciValue) currentSelection[i]).getId();
                    nodeId = ((DciValue) currentSelection[i]).getNodeId();
                    source = ((DciValue) currentSelection[i]).getSource();
                    dataType = ((DciValue) currentSelection[i]).getDataType();
                    // $NON-NLS-1$
                    name = URLEncoder.encode(((DciValue) currentSelection[i]).getName(), "UTF-8");
                    // $NON-NLS-1$
                    description = URLEncoder.encode(((DciValue) currentSelection[i]).getDescription(), "UTF-8");
                } else if (currentSelection[i] instanceof DataCollectionItem) {
                    dciId = ((DataCollectionItem) currentSelection[i]).getId();
                    nodeId = ((DataCollectionItem) currentSelection[i]).getNodeId();
                    source = ((DataCollectionItem) currentSelection[i]).getOrigin();
                    dataType = ((DataCollectionItem) currentSelection[i]).getDataType();
                    // $NON-NLS-1$
                    name = URLEncoder.encode(((DataCollectionItem) currentSelection[i]).getName(), "UTF-8");
                    // $NON-NLS-1$
                    description = URLEncoder.encode(((DataCollectionItem) currentSelection[i]).getDescription(), "UTF-8");
                }
            } catch (UnsupportedEncodingException e) {
                description = Messages.get().ShowDataComparisonChart_DescriptionUnavailable;
            }
            id += // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            "&" + Long.toString(nodeId) + "@" + Long.toString(dciId) + "@" + Integer.toString(source) + "@" + Integer.toString(dataType.getValue()) + "@" + name + "@" + // $NON-NLS-1$ //$NON-NLS-2$
            description;
        }
        try {
            window.getActivePage().showView(DataComparisonView.ID, id, IWorkbenchPage.VIEW_ACTIVATE);
        } catch (PartInitException e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ShowDataComparisonChart_Error, String.format(Messages.get().ShowDataComparisonChart_ErrorOpeningView, e.getMessage()));
        } catch (IllegalArgumentException e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ShowDataComparisonChart_14, String.format(Messages.get().ShowDataComparisonChart_15, e.getMessage()));
        }
    }
}
Also used : DciValue(org.netxms.client.datacollection.DciValue) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) DataType(org.netxms.client.constants.DataType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with DataCollectionItem

use of org.netxms.client.datacollection.DataCollectionItem in project netxms by netxms.

the class DataCollectionTest method testGetThresholds.

public void testGetThresholds() throws Exception {
    final NXCSession session = connect();
    DataCollectionConfiguration dc = session.openDataCollectionConfiguration(TestConstants.NODE_ID);
    final long dciId = dc.createItem(null);
    DataCollectionItem dci = (DataCollectionItem) dc.findItem(dciId, DataCollectionItem.class);
    dci.setName("TEST");
    dci.getThresholds().add(new Threshold());
    dc.modifyObject(dciId);
    Threshold[] thresholds = session.getThresholds(TestConstants.NODE_ID, dciId);
    assertNotNull(thresholds);
    assertEquals(1, thresholds.length);
    dc.deleteObject(dciId);
    dc.close();
    session.disconnect();
}
Also used : DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) DataCollectionConfiguration(org.netxms.client.datacollection.DataCollectionConfiguration) Threshold(org.netxms.client.datacollection.Threshold)

Aggregations

DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)8 AbstractNode (org.netxms.client.objects.AbstractNode)4 DataCollectionConfiguration (org.netxms.client.datacollection.DataCollectionConfiguration)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 NXCException (org.netxms.client.NXCException)2 Threshold (org.netxms.client.datacollection.Threshold)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Group (org.eclipse.swt.widgets.Group)1 PartInitException (org.eclipse.ui.PartInitException)1 NXCSession (org.netxms.client.NXCSession)1 DataType (org.netxms.client.constants.DataType)1 DataCollectionObject (org.netxms.client.datacollection.DataCollectionObject)1