Search in sources :

Example 1 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class ServerJobManager method doJobAction.

/**
 * Do job action: cancel, hold, unhold
 *
 * @param actionName
 * @param actionId
 */
private void doJobAction(final String actionName, final String actionErrorName, final int actionId) {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    new ConsoleJob(String.format(Messages.get().ServerJobManager_ActionJobName, actionName), this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @SuppressWarnings("rawtypes")
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            Iterator it = selection.iterator();
            while (it.hasNext()) {
                Object object = it.next();
                if (object instanceof ServerJob) {
                    final ServerJob jobObject = (ServerJob) object;
                    switch(actionId) {
                        case CANCEL_JOB:
                            session.cancelServerJob(jobObject.getId());
                            break;
                        case HOLD_JOB:
                            session.holdServerJob(jobObject.getId());
                            break;
                        case UNHOLD_JOB:
                            session.unholdServerJob(jobObject.getId());
                            break;
                        default:
                            throw new NXCException(RCC.INTERNAL_ERROR);
                    }
                } else {
                    throw new NXCException(RCC.INTERNAL_ERROR);
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ServerJobManager_ActionJobError, actionErrorName);
        }

        @Override
        protected void jobFinalize() {
            refreshJobList(false);
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerJob(org.netxms.client.server.ServerJob) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 2 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class NetxmsConnector method executeAction.

private boolean executeAction(ConnectorAction action) {
    List<String> servers = settingsManager.getServers();
    String login = settingsManager.getLogin();
    String password = settingsManager.getPassword();
    boolean success = false;
    boolean alarmNotFound = false;
    for (String server : servers) {
        ConnectionDetails connectionDetails = new ConnectionDetails(server).parse();
        String connAddress = connectionDetails.getAddress();
        int connPort = connectionDetails.getPort();
        NXCSession session = new NXCSession(connAddress, connPort, true);
        session.setIgnoreProtocolVersion(true);
        try {
            session.connect();
            session.login(login, password);
            log.debug("Connected to " + server);
            // do stuff
            success = true;
            action.execute(session);
            log.debug("Action executed on " + server);
        } catch (IOException e) {
            log.error("Connection failed", e);
        } catch (NXCException e) {
            if (e.getErrorCode() != RCC.INVALID_ALARM_ID) {
                log.error("Connection failed", e);
            } else {
                alarmNotFound = true;
            }
        }
    }
    return success || alarmNotFound;
}
Also used : NXCSession(org.netxms.client.NXCSession) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 3 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class AlarmDetails method refresh.

/**
 * Refresh view
 */
private void refresh() {
    new ConsoleJob(Messages.get().AlarmDetails_RefreshJobTitle, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Alarm alarm = session.getAlarm(alarmId);
            final List<AlarmComment> comments = session.getAlarmComments(alarmId);
            List<EventInfo> _events = null;
            try {
                _events = session.getAlarmEvents(alarmId);
            } catch (NXCException e) {
                if (e.getErrorCode() != RCC.ACCESS_DENIED)
                    throw e;
            }
            final List<EventInfo> events = _events;
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    updateAlarmDetails(alarm);
                    for (AlarmCommentsEditor e : editors.values()) e.dispose();
                    for (AlarmComment n : comments) editors.put(n.getId(), createEditor(n));
                    if (lastValuesWidget == null) {
                        AbstractObject object = session.findObjectById(alarm.getSourceObjectId());
                        if (object != null) {
                            // $NON-NLS-1$
                            lastValuesWidget = new LastValuesWidget(AlarmDetails.this, dataArea, SWT.BORDER, object, "AlarmDetails.LastValues", null);
                            lastValuesWidget.refresh();
                        }
                    }
                    if (events != null) {
                        eventViewer.setInput(events);
                        eventViewer.expandAll();
                        if (labelAccessDenied != null) {
                            labelAccessDenied.dispose();
                            labelAccessDenied = null;
                        }
                    } else if (labelAccessDenied == null) {
                        labelAccessDenied = new CLabel(eventViewer.getControl().getParent(), SWT.NONE);
                        toolkit.adapt(labelAccessDenied);
                        labelAccessDenied.setImage(StatusDisplayInfo.getStatusImage(Severity.CRITICAL));
                        labelAccessDenied.setText(Messages.get().AlarmDetails_RelatedEvents_AccessDenied);
                        labelAccessDenied.moveAbove(null);
                        labelAccessDenied.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                    }
                    updateLayout();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AlarmDetails_RefreshJobError;
        }
    }.start();
}
Also used : AlarmCommentsEditor(org.netxms.ui.eclipse.alarmviewer.widgets.AlarmCommentsEditor) CLabel(org.eclipse.swt.custom.CLabel) LastValuesWidget(org.netxms.ui.eclipse.datacollection.widgets.LastValuesWidget) AlarmComment(org.netxms.client.events.AlarmComment) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 4 with NXCException

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

Example 5 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class TableColumns method updateColumnsFromAgent.

/**
 * Update columns from real table
 */
private void updateColumnsFromAgent(final String name, final boolean interactive, final AbstractObject queryObject) {
    final NXCSession session = ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().TableColumns_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final org.netxms.client.Table table;
                if (editor.getSourceNode() != 0) {
                    table = session.queryAgentTable(editor.getSourceNode(), name);
                } else {
                    table = session.queryAgentTable((queryObject != null) ? queryObject.getObjectId() : dci.getNodeId(), name);
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        columns.clear();
                        for (int i = 0; i < table.getColumnCount(); i++) {
                            ColumnDefinition c = new ColumnDefinition(table.getColumnName(i), table.getColumnDisplayName(i));
                            c.setDataType(table.getColumnDefinition(i).getDataType());
                            c.setInstanceColumn(table.getColumnDefinition(i).isInstanceColumn());
                            columns.add(c);
                        }
                        columnList.setInput(columns.toArray());
                    }
                });
            } catch (Exception e) {
                Activator.logError("Cannot read table column definition from agent", e);
                if (interactive) {
                    final String msg = (e instanceof NXCException) ? e.getLocalizedMessage() : "Internal error";
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openError(getShell(), "Error", String.format("Cannot read table column definition from agent (%s)", msg));
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return null;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Aggregations

NXCException (org.netxms.client.NXCException)34 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)20 NXCSession (org.netxms.client.NXCSession)16 PartInitException (org.eclipse.ui.PartInitException)13 IOException (java.io.IOException)12 AbstractObject (org.netxms.client.objects.AbstractObject)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 Alarm (org.netxms.client.events.Alarm)3 AbstractNode (org.netxms.client.objects.AbstractNode)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AccessListElement (org.netxms.client.AccessListElement)2 DataCollectionConfiguration (org.netxms.client.datacollection.DataCollectionConfiguration)2 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)2 GraphSettings (org.netxms.client.datacollection.GraphSettings)2 AgentPolicy (org.netxms.client.objects.AgentPolicy)2 Node (org.netxms.client.objects.Node)2