Search in sources :

Example 1 with SnmpValue

use of org.netxms.client.snmp.SnmpValue in project netxms by netxms.

the class CreateSnmpDci method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    if (objects.size() == 0)
        return;
    MibObject mibObject = MibCache.findObject(objects.get(0).getName(), false);
    String description = (mibObject != null) ? mibObject.getName() : objects.get(0).getName();
    if (objects.size() > 1)
        // $NON-NLS-1$
        description += " @@instance@@";
    final CreateSnmpDciDialog dlg = new CreateSnmpDciDialog(shell, description);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final List<SnmpValue> values = new ArrayList<SnmpValue>(objects);
    // Get set of nodes
    final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
    for (SnmpValue v : values) {
        AbstractNode node = (AbstractNode) session.findObjectById(v.getNodeId(), AbstractNode.class);
        if (node != null) {
            nodes.add(node);
        }
    }
    // Check what nodes requires DCI list lock
    final Map<Long, Boolean> lockRequired = new HashMap<Long, Boolean>(nodes.size());
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (AbstractNode n : nodes) {
        IViewReference ref = page.findViewReference(DataCollectionEditor.ID, Long.toString(n.getObjectId()));
        lockRequired.put(n.getObjectId(), !((ref != null) && (ref.getView(false) != null)));
    }
    new ConsoleJob(Messages.get().CreateSnmpDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().CreateSnmpDci_ErrorMessage;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).CreateSnmpDci_TaskTitle, values.size());
            for (SnmpValue v : values) {
                // $NON-NLS-1$
                final String description = dlg.getDescription().replaceAll("@@instance@@", Long.toString(v.getObjectId().getIdFromPos(v.getObjectId().getLength() - 1)));
                createDci(session, v, description, dlg.getPollingInterval(), dlg.getRetentionTime(), dlg.getDeltaCalculation(), lockRequired);
                monitor.worked(1);
            }
            monitor.done();
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnmpValue(org.netxms.client.snmp.SnmpValue) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MibObject(org.netxms.client.snmp.MibObject) CreateSnmpDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateSnmpDciDialog) HashSet(java.util.HashSet)

Example 2 with SnmpValue

use of org.netxms.client.snmp.SnmpValue in project netxms by netxms.

the class MibSelectionDialog method doWalk.

/**
 * Do SNMP walk
 */
private void doWalk() {
    try {
        final SnmpObjectId root = SnmpObjectId.parseSnmpObjectId(oid.getText());
        MibWalkDialog dlg = new MibWalkDialog(getShell(), nodeId, root);
        if (dlg.open() == Window.OK) {
            SnmpValue v = dlg.getValue();
            if (v != null) {
                oid.setText(v.getName());
            }
        }
    } catch (SnmpObjectIdFormatException e) {
        MessageDialogHelper.openError(getShell(), Messages.get().MibSelectionDialog_Error, Messages.get().MibSelectionDialog_OIDParseError);
    }
}
Also used : SnmpValue(org.netxms.client.snmp.SnmpValue) SnmpObjectIdFormatException(org.netxms.client.snmp.SnmpObjectIdFormatException) SnmpObjectId(org.netxms.client.snmp.SnmpObjectId)

Example 3 with SnmpValue

use of org.netxms.client.snmp.SnmpValue in project netxms by netxms.

the class NXCSession method snmpWalk.

/**
 * Do SNMP walk. Operation will start at given root object, and callback will
 * be called one or more times as data will come from server. This method
 * will exit only when walk operation is complete.
 *
 * @param nodeId   node object ID
 * @param rootOid  root SNMP object ID (as text)
 * @param listener listener
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void snmpWalk(long nodeId, String rootOid, SnmpWalkListener listener) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_START_SNMP_WALK);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_SNMP_OID, rootOid);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    while (true) {
        final NXCPMessage response = waitForMessage(NXCPCodes.CMD_SNMP_WALK_DATA, msg.getMessageId());
        final int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_VARIABLES);
        final List<SnmpValue> data = new ArrayList<SnmpValue>(count);
        long varId = NXCPCodes.VID_SNMP_WALKER_DATA_BASE;
        for (int i = 0; i < count; i++) {
            final String name = response.getFieldAsString(varId++);
            final int type = response.getFieldAsInt32(varId++);
            final String value = response.getFieldAsString(varId++);
            data.add(new SnmpValue(name, type, value, nodeId));
        }
        listener.onSnmpWalkData(data);
        if (response.isEndOfSequence())
            break;
    }
}
Also used : SnmpValue(org.netxms.client.snmp.SnmpValue) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Aggregations

SnmpValue (org.netxms.client.snmp.SnmpValue)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IViewReference (org.eclipse.ui.IViewReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 NXCPMessage (org.netxms.base.NXCPMessage)1 NXCException (org.netxms.client.NXCException)1 NXCSession (org.netxms.client.NXCSession)1 AbstractNode (org.netxms.client.objects.AbstractNode)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 MibObject (org.netxms.client.snmp.MibObject)1 SnmpObjectId (org.netxms.client.snmp.SnmpObjectId)1 SnmpObjectIdFormatException (org.netxms.client.snmp.SnmpObjectIdFormatException)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1 CreateSnmpDciDialog (org.netxms.ui.eclipse.datacollection.dialogs.CreateSnmpDciDialog)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1