Search in sources :

Example 6 with Threshold

use of org.netxms.client.datacollection.Threshold 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)

Example 7 with Threshold

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

the class NXCSession method getActiveThresholds.

/**
 * Get active thresholds
 *
 * @param dciConfig Dci config
 * @return list of active thresholds
 * @throws IOException
 * @throws NXCException
 */
public List<Threshold> getActiveThresholds(List<SingleDciConfig> dciConfig) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_ACTIVE_THRESHOLDS);
    long base = NXCPCodes.VID_DCI_VALUES_BASE;
    msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, dciConfig.size());
    for (SingleDciConfig c : dciConfig) {
        c.fillMessage(msg, base);
        base += 10;
    }
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_THRESHOLDS);
    List<Threshold> list = new ArrayList<Threshold>(count);
    base = NXCPCodes.VID_DCI_THRESHOLD_BASE;
    for (int i = 0; i < count; i++, base += 20) {
        list.add(new Threshold(response, base));
    }
    return list;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) SingleDciConfig(org.netxms.client.maps.configs.SingleDciConfig) Threshold(org.netxms.client.datacollection.Threshold)

Example 8 with Threshold

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

the class NXCSession method getThresholds.

/**
 * Get list of thresholds configured for given DCI
 *
 * @param nodeId Node object ID
 * @param dciId  DCI ID
 * @return List of configured thresholds
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public Threshold[] getThresholds(final long nodeId, final long dciId) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_DCI_THRESHOLDS);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setFieldInt32(NXCPCodes.VID_DCI_ID, (int) dciId);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_THRESHOLDS);
    final Threshold[] list = new Threshold[count];
    long varId = NXCPCodes.VID_DCI_THRESHOLD_BASE;
    for (int i = 0; i < count; i++) {
        list[i] = new Threshold(response, varId);
        varId += 20;
    }
    return list;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) Threshold(org.netxms.client.datacollection.Threshold)

Example 9 with Threshold

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

the class ThresholdLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    switch(columnIndex) {
        case Thresholds.COLUMN_OPERATION:
            int f = ((Threshold) element).getFunction();
            StringBuilder text = new StringBuilder(FUNCTIONS[f]);
            text.append(((Threshold) element).getSampleCount());
            // $NON-NLS-1$
            text.append(") ");
            if (f != Threshold.F_SCRIPT) {
                text.append(OPERATIONS[((Threshold) element).getOperation()]);
                text.append(' ');
                text.append(((Threshold) element).getValue());
            }
            return text.toString();
        case Thresholds.COLUMN_EVENT:
            final EventTemplate event = (EventTemplate) session.findEventObjectByCode(((Threshold) element).getFireEvent());
            return eventLabelProvider.getText(event);
    }
    return null;
}
Also used : EventTemplate(org.netxms.client.events.EventTemplate) Threshold(org.netxms.client.datacollection.Threshold)

Example 10 with Threshold

use of org.netxms.client.datacollection.Threshold 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)

Aggregations

Threshold (org.netxms.client.datacollection.Threshold)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PartInitException (org.eclipse.ui.PartInitException)2 NXCPMessage (org.netxms.base.NXCPMessage)2 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)2 DciData (org.netxms.client.datacollection.DciData)2 EventTemplate (org.netxms.client.events.EventTemplate)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)2 EditThresholdDialog (org.netxms.ui.eclipse.datacollection.dialogs.EditThresholdDialog)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1