Search in sources :

Example 1 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class NXCSession method findNodesByHostname.

/**
 * Find all nodes that contain the primary hostname
 *
 * @param zoneId zone ID
 * @param hostname Hostname to find
 * @return List of nodes found
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<AbstractNode> findNodesByHostname(int zoneId, String hostname) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_FIND_HOSTNAME_LOCATION);
    msg.setFieldInt32(NXCPCodes.VID_ZONE_UIN, zoneId);
    msg.setField(NXCPCodes.VID_HOSTNAME, hostname);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
    long base = NXCPCodes.VID_ELEMENT_LIST_BASE;
    List<AbstractNode> nodes = new ArrayList<AbstractNode>();
    for (int i = 0; i < count; i++) {
        nodes.add((AbstractNode) findObjectById(response.getFieldAsInt32(base++)));
    }
    return nodes;
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 2 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class TakeScreenshot method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if ((obj instanceof AbstractNode) && ((AbstractNode) obj).hasAgent()) {
            action.setEnabled(true);
            node = ((AbstractObject) obj);
        } else {
            action.setEnabled(false);
            node = null;
        }
    } else {
        action.setEnabled(false);
        node = null;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ObjectStatusRadialWidget method paint.

public void paint(GC gc) {
    gc.setAdvanced(true);
    if (!gc.getAdvanced()) {
        gc.drawText("Advanced graphics not supported", 30, 30, true);
        return;
    }
    objectMap.clear();
    leafObjectCount = calculateMaxLVLAndObjCount(rootObject, 1);
    leafObjectSize = 360 / (float) leafObjectCount;
    Rectangle rect = getClientArea();
    rect.width--;
    rect.height--;
    gc.setAntialias(SWT.ON);
    gc.setTextAntialias(SWT.ON);
    gc.setForeground(SharedColors.getColor(SharedColors.TEXT_NORMAL, getDisplay()));
    gc.setLineWidth(1);
    // calculate values
    int rectSide = Math.min(rect.width, rect.height);
    diameter = rectSide / (maxLvl + 1);
    centerX = rect.x + (rectSide / 2);
    centerY = rect.y + (rectSide / 2);
    // draw objects
    drawParts(gc, rootObject, 2, 0);
    // draw general oval with
    // draw white oval
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    gc.setAlpha(255);
    gc.fillOval(centerX - diameter / 2 - 3, centerY - diameter / 2 - 3, diameter + 6, diameter + 6);
    gc.setBackground(StatusDisplayInfo.getStatusColor(rootObject.getStatus()));
    gc.setAlpha(255);
    gc.fillOval(centerX - diameter / 2, centerY - diameter / 2, diameter, diameter);
    final String text = (rootObject instanceof AbstractNode) ? // $NON-NLS-1$
    (rootObject.getObjectName() + "\n" + ((AbstractNode) rootObject).getPrimaryIP().getHostAddress()) : rootObject.getObjectName();
    gc.setClipping(rect);
    int h = gc.textExtent(text, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER).y;
    int l = gc.textExtent(text, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER).x;
    gc.setForeground(ColorConverter.selectTextColorByBackgroundColor(StatusDisplayInfo.getStatusColor(rootObject.getStatus()), cCache));
    gc.drawText(text, rect.x + (rectSide / 2) - l / 2, rect.y + (rectSide / 2) - h / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
    objectMap.add(new ObjectPosition(0, 360, 1, rootObject));
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 4 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class CreateInterfraceDci method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final CreateInterfaceDciDialog dlg = new CreateInterfaceDciDialog(shell, (objects.size() == 1) ? objects.get(0) : null);
    if (dlg.open() == Window.OK) {
        final List<Interface> ifaces = new ArrayList<Interface>(objects);
        // Get set of nodes
        final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
        for (Interface iface : ifaces) {
            AbstractNode node = iface.getParentNode();
            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)));
        }
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().CreateInterfraceDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                InterfaceDciInfo[] dciInfo = dlg.getDciInfo();
                monitor.beginTask(Messages.get(getDisplay()).CreateInterfraceDci_TaskName, ifaces.size() * dciInfo.length);
                for (int i = 0; i < ifaces.size(); i++) {
                    for (int j = 0; j < dciInfo.length; j++) {
                        if (dciInfo[j].enabled) {
                            createInterfaceDci(session, ifaces.get(i), j, dciInfo[j], dlg.getPollingInterval(), dlg.getRetentionTime(), ifaces.size() > 1, 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) CreateInterfaceDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateInterfaceDciDialog) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Interface(org.netxms.client.objects.Interface) HashSet(java.util.HashSet)

Example 5 with AbstractNode

use of org.netxms.client.objects.AbstractNode 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)

Aggregations

AbstractNode (org.netxms.client.objects.AbstractNode)47 AbstractObject (org.netxms.client.objects.AbstractObject)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 NXCSession (org.netxms.client.NXCSession)13 ArrayList (java.util.ArrayList)12 Cluster (org.netxms.client.objects.Cluster)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Composite (org.eclipse.swt.widgets.Composite)6 PartInitException (org.eclipse.ui.PartInitException)6 MobileDevice (org.netxms.client.objects.MobileDevice)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 NXCException (org.netxms.client.NXCException)5 Interface (org.netxms.client.objects.Interface)5 Sensor (org.netxms.client.objects.Sensor)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)4 Subnet (org.netxms.client.objects.Subnet)4 ISelection (org.eclipse.jface.viewers.ISelection)3