Search in sources :

Example 1 with SnmpTrap

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

the class SnmpTrapEditor method deleteTraps.

/**
 * Delete selected traps
 */
protected void deleteTraps() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get().SnmpTrapEditor_DeleteJob_Title, this, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                session.deleteSnmpTrapConfiguration(((SnmpTrap) objects[i]).getId());
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnmpTrap(org.netxms.client.snmp.SnmpTrap) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 2 with SnmpTrap

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

the class SnmpTrapComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    TableColumn sortColumn = ((TableViewer) viewer).getTable().getSortColumn();
    if (sortColumn == null)
        return 0;
    int rc;
    SnmpTrap trap1 = (SnmpTrap) e1;
    SnmpTrap trap2 = (SnmpTrap) e2;
    switch(// $NON-NLS-1$
    (Integer) sortColumn.getData("ID")) {
        case SnmpTrapEditor.COLUMN_ID:
            rc = Long.signum(trap1.getId() - trap2.getId());
            break;
        case SnmpTrapEditor.COLUMN_TRAP_OID:
            rc = trap1.getObjectId().compareTo(trap2.getObjectId());
            break;
        case SnmpTrapEditor.COLUMN_EVENT:
            EventObject evo1 = session.findEventObjectByCode(trap1.getEventCode());
            EventObject evo2 = session.findEventObjectByCode(trap2.getEventCode());
            String name1 = (evo1 != null) ? evo1.getName() : Messages.get().SnmpTrapComparator_Unknown;
            String name2 = (evo2 != null) ? evo2.getName() : Messages.get().SnmpTrapComparator_Unknown;
            rc = name1.compareToIgnoreCase(name2);
            break;
        case SnmpTrapEditor.COLUMN_DESCRIPTION:
            rc = trap1.getDescription().compareToIgnoreCase(trap2.getDescription());
            break;
        default:
            rc = 0;
            break;
    }
    int dir = ((TableViewer) viewer).getTable().getSortDirection();
    return (dir == SWT.UP) ? rc : -rc;
}
Also used : SnmpTrap(org.netxms.client.snmp.SnmpTrap) TableColumn(org.eclipse.swt.widgets.TableColumn) EventObject(org.netxms.client.events.EventObject)

Example 3 with SnmpTrap

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

the class ExportFileBuilder method doExport.

/**
 * Do export operation and call completion handler when done
 *
 * @param completionHandler
 */
private void doExport(final ExportCompletionHandler completionHandler) {
    final long[] eventList = new long[events.size()];
    int i = 0;
    for (EventObject o : events.values()) eventList[i++] = o.getCode();
    final long[] templateList = new long[templates.size()];
    i = 0;
    for (Template t : templates.values()) templateList[i++] = t.getObjectId();
    final long[] trapList = new long[traps.size()];
    i = 0;
    for (SnmpTrap t : traps.values()) trapList[i++] = t.getId();
    final UUID[] ruleList = new UUID[rules.size()];
    i = 0;
    for (EventProcessingPolicyRule r : rules.values()) ruleList[i++] = r.getGuid();
    final long[] scriptList = new long[scripts.size()];
    i = 0;
    for (Script s : scripts.values()) scriptList[i++] = s.getId();
    final long[] toolList = new long[tools.size()];
    i = 0;
    for (ObjectTool t : tools.values()) toolList[i++] = t.getId();
    final long[] summaryTableList = new long[summaryTables.size()];
    i = 0;
    for (DciSummaryTableDescriptor t : summaryTables.values()) summaryTableList[i++] = t.getId();
    final long[] actionList = new long[actions.size()];
    i = 0;
    for (ServerAction a : actions.values()) actionList[i++] = a.getId();
    final String descriptionText = description.getText();
    new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList, actionList);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    completionHandler.exportCompleted(xml);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ExportFileBuilder_ExportJobError;
        }
    }.start();
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) Script(org.netxms.client.Script) SnmpTrap(org.netxms.client.snmp.SnmpTrap) EventObject(org.netxms.client.events.EventObject) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) Template(org.netxms.client.objects.Template) EventTemplate(org.netxms.client.events.EventTemplate) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) UUID(java.util.UUID) ServerAction(org.netxms.client.ServerAction) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 4 with SnmpTrap

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

the class ExportFileBuilder method addTraps.

/**
 * Add traps to list
 */
private void addTraps() {
    SelectSnmpTrapDialog dlg = new SelectSnmpTrapDialog(getSite().getShell(), snmpTrapCache);
    if (dlg.open() == Window.OK) {
        final Set<Long> eventCodes = new HashSet<Long>();
        for (SnmpTrap t : dlg.getSelection()) {
            traps.put(t.getId(), t);
            if (t.getEventCode() >= 100000) {
                eventCodes.add((long) t.getEventCode());
            }
        }
        trapViewer.setInput(traps.values().toArray());
        setModified();
        if (eventCodes.size() > 0) {
            for (EventObject o : session.findMultipleEventObjects(eventCodes.toArray(new Long[eventCodes.size()]))) {
                events.put(o.getCode(), o);
            }
            eventViewer.setInput(events.values().toArray());
        }
        ;
    }
}
Also used : SelectSnmpTrapDialog(org.netxms.ui.eclipse.serverconfig.dialogs.SelectSnmpTrapDialog) SnmpTrap(org.netxms.client.snmp.SnmpTrap) EventObject(org.netxms.client.events.EventObject) HashSet(java.util.HashSet)

Example 5 with SnmpTrap

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

the class NXCSession method getSnmpTrapsConfigurationSummary.

/**
 * Get summary of SNMP trap mapping. Trap configurations returned without parameter mapping.
 *
 * @return List of SnmpTrap objects
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<SnmpTrap> getSnmpTrapsConfigurationSummary() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_TRAP_CFG_RO);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_TRAPS);
    List<SnmpTrap> list = new ArrayList<SnmpTrap>(count);
    long varId = NXCPCodes.VID_TRAP_INFO_BASE;
    for (int i = 0; i < count; i++) {
        list.add(new SnmpTrap(response, varId));
        varId += 10;
    }
    return list;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) SnmpTrap(org.netxms.client.snmp.SnmpTrap) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Aggregations

SnmpTrap (org.netxms.client.snmp.SnmpTrap)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 EventObject (org.netxms.client.events.EventObject)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 NXCPMessage (org.netxms.base.NXCPMessage)2 TrapConfigurationDialog (org.netxms.ui.eclipse.snmp.dialogs.TrapConfigurationDialog)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Script (org.netxms.client.Script)1 ServerAction (org.netxms.client.ServerAction)1 DciSummaryTableDescriptor (org.netxms.client.datacollection.DciSummaryTableDescriptor)1 EventProcessingPolicyRule (org.netxms.client.events.EventProcessingPolicyRule)1 EventTemplate (org.netxms.client.events.EventTemplate)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 Template (org.netxms.client.objects.Template)1 ObjectTool (org.netxms.client.objecttools.ObjectTool)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1