Search in sources :

Example 6 with DataCollectionItem

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

the class CreateSnmpDci method createDci.

/**
 * @param session
 * @param value
 * @param description
 * @param pollingInterval
 * @param retentionTime
 * @param deltaCalculation
 * @param lockRequired
 * @throws Exception
 */
private static void createDci(NXCSession session, SnmpValue value, String description, int pollingInterval, int retentionTime, int deltaCalculation, Map<Long, Boolean> lockRequired) throws Exception {
    AbstractNode node = (AbstractNode) session.findObjectById(value.getNodeId(), AbstractNode.class);
    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);
    dci.setOrigin(DataCollectionItem.SNMP);
    dci.setDataType(dciTypeFromAsnType(value.getType()));
    dci.setStatus(DataCollectionItem.ACTIVE);
    dci.setDescription(description);
    dci.setDeltaCalculation(deltaCalculation);
    dci.setName(value.getName());
    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 7 with DataCollectionItem

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

the class DciLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    DataCollectionObject dci = (DataCollectionObject) element;
    switch(columnIndex) {
        case DataCollectionEditor.COLUMN_ID:
            return Long.toString(dci.getId());
        case DataCollectionEditor.COLUMN_ORIGIN:
            return originTexts.get(dci.getOrigin());
        case DataCollectionEditor.COLUMN_DESCRIPTION:
            return dci.getDescription();
        case DataCollectionEditor.COLUMN_PARAMETER:
            return dci.getName();
        case DataCollectionEditor.COLUMN_DATATYPE:
            if (dci instanceof DataCollectionItem)
                return DataCollectionDisplayInfo.getDataTypeName(((DataCollectionItem) dci).getDataType());
            return Messages.get().DciLabelProvider_Table;
        case DataCollectionEditor.COLUMN_INTERVAL:
            if (dci.isUseAdvancedSchedule())
                return Messages.get().DciLabelProvider_CustomSchedule;
            if (dci.getPollingInterval() <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(dci.getPollingInterval());
        case DataCollectionEditor.COLUMN_RETENTION:
            if ((dci.getFlags() & DataCollectionItem.DCF_NO_STORAGE) != 0)
                return Messages.get().DciLabelProvider_None;
            int days = dci.getRetentionTime();
            if (days <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(days) + ((days == 1) ? Messages.get().DciLabelProvider_Day : Messages.get().DciLabelProvider_Days);
        case DataCollectionEditor.COLUMN_STATUS:
            return statusTexts.get(dci.getStatus());
        case DataCollectionEditor.COLUMN_THRESHOLD:
            StringBuilder thresholds = new StringBuilder();
            if ((dci instanceof DataCollectionItem)) {
                ArrayList<Threshold> list = ((DataCollectionItem) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    Threshold tr = list.get(i);
                    int f = tr.getFunction();
                    StringBuilder text = new StringBuilder(ThresholdLabelProvider.FUNCTIONS[f]);
                    text.append(tr.getSampleCount());
                    // $NON-NLS-1$
                    text.append(") ");
                    if (f != Threshold.F_SCRIPT) {
                        text.append(ThresholdLabelProvider.OPERATIONS[tr.getOperation()]);
                        text.append(' ');
                        text.append(tr.getValue());
                    }
                    thresholds.append(text);
                    if (i < list.size() - 1)
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            if ((dci instanceof DataCollectionTable)) {
                List<TableThreshold> list = ((DataCollectionTable) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    thresholds.append(list.get(i).getConditionAsText());
                    if (i + 1 != list.size())
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            return thresholds.toString();
        case DataCollectionEditor.COLUMN_TEMPLATE:
            if (dci.getTemplateId() == 0)
                return null;
            AbstractObject object = session.findObjectById(dci.getTemplateId());
            if (object == null)
                return Messages.get().DciLabelProvider_Unknown;
            if (!(object instanceof Template))
                return object.getObjectName();
            Set<AbstractObject> parents = object.getAllParents(null);
            StringBuilder sb = new StringBuilder();
            for (AbstractObject parent : parents) {
                sb.append(parent.getObjectName());
                // $NON-NLS-1$
                sb.append("/");
            }
            sb.append(object.getObjectName());
            return sb.toString();
    }
    return null;
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) AbstractObject(org.netxms.client.objects.AbstractObject) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) TableThreshold(org.netxms.client.datacollection.TableThreshold) DataCollectionTable(org.netxms.client.datacollection.DataCollectionTable) Threshold(org.netxms.client.datacollection.Threshold) TableThreshold(org.netxms.client.datacollection.TableThreshold) Template(org.netxms.client.objects.Template)

Example 8 with DataCollectionItem

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

the class ClusterOptions 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);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    owner = session.findObjectById(editor.getObject().getNodeId());
    if (owner instanceof Cluster) {
        cluster = (Cluster) owner;
    } else if (owner instanceof AbstractNode) {
        for (AbstractObject o : owner.getParentsAsArray()) {
            if (o instanceof Cluster) {
                cluster = (Cluster) o;
                break;
            }
        }
    }
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    clusterResource = WidgetHelper.createLabeledCombo(dialogArea, SWT.BORDER | SWT.READ_ONLY, Messages.get().General_ClRes, WidgetHelper.DEFAULT_LAYOUT_DATA);
    if (cluster != null) {
        clusterResourceMap = new HashMap<Integer, Long>();
        clusterResourceMap.put(0, 0L);
        clusterResource.add(Messages.get().General_None);
        if (editor.getObject().getResourceId() == 0)
            clusterResource.select(0);
        int index = 1;
        for (ClusterResource r : cluster.getResources()) {
            clusterResource.add(r.getName());
            clusterResourceMap.put(index, r.getId());
            if (editor.getObject().getResourceId() == r.getId())
                clusterResource.select(index);
            index++;
        }
    } else {
        clusterResource.add(Messages.get().General_None);
        clusterResource.select(0);
        clusterResource.setEnabled(false);
    }
    Group aggregationGroup = new Group(dialogArea, SWT.NONE);
    aggregationGroup.setText(Messages.get().ClusterOptions_DataAggregation);
    aggregationGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
    aggregationGroup.setLayout(layout);
    checkAggregate = new Button(aggregationGroup, SWT.CHECK);
    checkAggregate.setText(Messages.get().ClusterOptions_AggregateFromNodes);
    checkAggregate.setSelection(editor.getObject().isAggregateOnCluster());
    checkAggregateWithErrors = new Button(aggregationGroup, SWT.CHECK);
    checkAggregateWithErrors.setText("Use last known value for aggregation in case of data collection error");
    checkAggregateWithErrors.setSelection(editor.getObject().isAggregateWithErrors());
    checkRunScript = new Button(aggregationGroup, SWT.CHECK);
    checkRunScript.setText(Messages.get().ClusterOptions_RunScriptOnAggregatedData);
    checkRunScript.setSelection(editor.getObject().isTransformAggregated());
    if (editor.getObject() instanceof DataCollectionItem) {
        checkAggregate.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                aggregationFunction.setEnabled(checkAggregate.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        aggregationFunction = WidgetHelper.createLabeledCombo(aggregationGroup, SWT.BORDER | SWT.READ_ONLY, Messages.get().ClusterOptions_AggrFunction, WidgetHelper.DEFAULT_LAYOUT_DATA);
        aggregationFunction.add(Messages.get().ClusterOptions_Total);
        aggregationFunction.add(Messages.get().ClusterOptions_Average);
        aggregationFunction.add(Messages.get().ClusterOptions_Min);
        aggregationFunction.add(Messages.get().ClusterOptions_Max);
        aggregationFunction.select(editor.getObjectAsItem().getAggregationFunction());
        aggregationFunction.setEnabled(editor.getObjectAsItem().isAggregateOnCluster());
    }
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) AbstractNode(org.netxms.client.objects.AbstractNode) Cluster(org.netxms.client.objects.Cluster) ClusterResource(org.netxms.client.objects.ClusterResource) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

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