Search in sources :

Example 1 with ConnectionPoint

use of org.netxms.client.topology.ConnectionPoint in project netxms by netxms.

the class NXCSession method findConnectionPoint.

/**
 * Find connection point (either directly connected or most close known
 * interface on a switch) for given MAC address. Will return null if
 * connection point information cannot be found.
 *
 * @param macAddr MAC address
 * @return connection point information or null
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public ConnectionPoint findConnectionPoint(MacAddress macAddr) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_FIND_MAC_LOCATION);
    msg.setField(NXCPCodes.VID_MAC_ADDR, macAddr.getValue());
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    return response.isFieldPresent(NXCPCodes.VID_CONNECTION_TYPE) ? new ConnectionPoint(response) : null;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Example 2 with ConnectionPoint

use of org.netxms.client.topology.ConnectionPoint in project netxms by netxms.

the class NXCSession method findConnectionPoint.

/**
 * Find connection point (either directly connected or most close known
 * interface on a switch) for given node or interface object. Will return
 * null if connection point information cannot be found.
 *
 * @param objectId Node or interface object ID
 * @return connection point information or null
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public ConnectionPoint findConnectionPoint(long objectId) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_FIND_NODE_CONNECTION);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) objectId);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    return response.isFieldPresent(NXCPCodes.VID_CONNECTION_TYPE) ? new ConnectionPoint(response) : null;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Example 3 with ConnectionPoint

use of org.netxms.client.topology.ConnectionPoint in project netxms by netxms.

the class ConnectionPointLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    ConnectionPoint cp = (ConnectionPoint) element;
    switch(columnIndex) {
        case HostSearchResults.COLUMN_SEQUENCE:
            return Integer.toString((Integer) cp.getData() + 1);
        case HostSearchResults.COLUMN_NODE:
            return getObjectName(cp.getLocalNodeId());
        case HostSearchResults.COLUMN_INTERFACE:
            return getObjectName(cp.getLocalInterfaceId());
        case HostSearchResults.COLUMN_MAC_ADDRESS:
            if (cp.getLocalMacAddress() == null)
                return "n/a";
            else
                return cp.getLocalMacAddress().toString();
        case HostSearchResults.COLUMN_IP_ADDRESS:
            InetAddress addr = cp.getLocalIpAddress();
            if (addr != null)
                return addr.getHostAddress();
            Interface iface = (Interface) session.findObjectById(cp.getLocalInterfaceId(), Interface.class);
            if (iface == null)
                // $NON-NLS-1$
                return "";
            InetAddress a = iface.getFirstUnicastAddress();
            // $NON-NLS-1$
            return (a != null) ? a.getHostAddress() : "";
        case HostSearchResults.COLUMN_SWITCH:
            if ((cp.getNodeId() == 0))
                return "n/a";
            else
                return getObjectName(cp.getNodeId());
        case HostSearchResults.COLUMN_PORT:
            if (cp.getInterfaceId() == 0)
                return "n/a";
            else
                return getObjectName(cp.getInterfaceId());
        case HostSearchResults.COLUMN_TYPE:
            if (cp.getType() == null)
                return "n/a";
            switch(cp.getType()) {
                case DIRECT:
                    return Messages.get().ConnectionPointLabelProvider_Direct;
                case INDIRECT:
                    return Messages.get().ConnectionPointLabelProvider_Indirect;
                case WIRELESS:
                    return Messages.get().ConnectionPointLabelProvider_Wireless;
                default:
                    return Messages.get().ConnectionPointLabelProvider_Unknown;
            }
    }
    return null;
}
Also used : InetAddress(java.net.InetAddress) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) Interface(org.netxms.client.objects.Interface)

Example 4 with ConnectionPoint

use of org.netxms.client.topology.ConnectionPoint in project netxms by netxms.

the class FindConnectionPoint method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if ((objects == null) || (objects.isEmpty()))
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().FindConnectionPoint_JobTitle, wbPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ConnectionPoint[] cps = new ConnectionPoint[objects.size()];
            for (int i = 0; i < objects.size(); i++) {
                AbstractObject object = objects.get(i);
                cps[i] = session.findConnectionPoint(object.getObjectId());
                if (cps[i] == null) {
                    if (object instanceof Node)
                        cps[i] = new ConnectionPoint(object.getObjectId(), 0, false);
                    else
                        cps[i] = new ConnectionPoint(object.getParentIdList()[0], object.getObjectId(), false);
                }
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (cps.length == 1)
                        HostSearchResults.showConnection(cps[0]);
                    else
                        HostSearchResults.showConnection(cps);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().FindConnectionPoint_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) Node(org.netxms.client.objects.Node) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Example 5 with ConnectionPoint

use of org.netxms.client.topology.ConnectionPoint in project netxms by netxms.

the class FindMacAddress method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    EnterMacAddressDlg dlg = new EnterMacAddressDlg(window.getShell());
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final MacAddress macAddr = dlg.getMacAddress();
    new ConsoleJob(String.format(Messages.get().FindMacAddress_JobTitle, macAddr), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ConnectionPoint cp = session.findConnectionPoint(macAddr);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    HostSearchResults.showConnection(cp);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().FindMacAddress_JobError, macAddr);
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) EnterMacAddressDlg(org.netxms.ui.eclipse.topology.dialogs.EnterMacAddressDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MacAddress(org.netxms.base.MacAddress) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Aggregations

ConnectionPoint (org.netxms.client.topology.ConnectionPoint)9 NXCSession (org.netxms.client.NXCSession)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NXCPMessage (org.netxms.base.NXCPMessage)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 InetAddress (java.net.InetAddress)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 Interface (org.netxms.client.objects.Interface)2 Node (org.netxms.client.objects.Node)2 Shell (org.eclipse.swt.widgets.Shell)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 MacAddress (org.netxms.base.MacAddress)1 EnterIpAddressDlg (org.netxms.ui.eclipse.topology.dialogs.EnterIpAddressDlg)1 EnterMacAddressDlg (org.netxms.ui.eclipse.topology.dialogs.EnterMacAddressDlg)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1