Search in sources :

Example 6 with SnmpTrap

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

the class NXCSession method getSnmpTrapsConfiguration.

/**
 * Get list of configured SNMP traps
 *
 * @return List of configured SNMP traps.
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<SnmpTrap> getSnmpTrapsConfiguration() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_LOAD_TRAP_CFG);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    List<SnmpTrap> traps = new ArrayList<SnmpTrap>();
    while (true) {
        final NXCPMessage response = waitForMessage(NXCPCodes.CMD_TRAP_CFG_RECORD, msg.getMessageId());
        // end of list
        if (response.getFieldAsInt64(NXCPCodes.VID_TRAP_ID) == 0)
            break;
        traps.add(new SnmpTrap(response));
    }
    return traps;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) SnmpTrap(org.netxms.client.snmp.SnmpTrap)

Example 7 with SnmpTrap

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

the class SnmpTrapEditor method editTrap.

/**
 * Edit selected trap
 */
protected void editTrap() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final SnmpTrap trap = (SnmpTrap) selection.getFirstElement();
    TrapConfigurationDialog dlg = new TrapConfigurationDialog(getViewSite().getShell(), trap);
    if (dlg.open() == Window.OK) {
        new ConsoleJob(Messages.get().SnmpTrapEditor_ModifyJob_Title, this, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.modifySnmpTrapConfiguration(trap);
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TrapConfigurationDialog(org.netxms.ui.eclipse.snmp.dialogs.TrapConfigurationDialog) SnmpTrap(org.netxms.client.snmp.SnmpTrap) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 8 with SnmpTrap

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

the class SnmpTrapEditor method createTrap.

/**
 * Create new trap
 */
protected void createTrap() {
    final SnmpTrap trap = new SnmpTrap();
    // SYS_UNMATCHED_SNMP_TRAP
    trap.setEventCode(500);
    TrapConfigurationDialog dlg = new TrapConfigurationDialog(getViewSite().getShell(), trap);
    if (dlg.open() == Window.OK) {
        new ConsoleJob(Messages.get().SnmpTrapEditor_CreateJob_Title, this, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                trap.setId(session.createSnmpTrapConfiguration());
                session.modifySnmpTrapConfiguration(trap);
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TrapConfigurationDialog(org.netxms.ui.eclipse.snmp.dialogs.TrapConfigurationDialog) SnmpTrap(org.netxms.client.snmp.SnmpTrap) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 9 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 SelectSnmpTrapDialog.COLUMN_OID:
            rc = trap1.getObjectId().compareTo(trap2.getObjectId());
            break;
        case SelectSnmpTrapDialog.COLUMN_EVENT:
            EventObject evo1 = session.findEventObjectByCode(trap1.getEventCode());
            EventObject evo2 = session.findEventObjectByCode(trap2.getEventCode());
            // $NON-NLS-1$ //$NON-NLS-2$
            String name1 = (evo1 != null) ? evo1.getName() : ("[" + Integer.toString(trap1.getEventCode()) + "]");
            // $NON-NLS-1$ //$NON-NLS-2$
            String name2 = (evo2 != null) ? evo2.getName() : ("[" + Integer.toString(trap2.getEventCode()) + "]");
            rc = name1.compareToIgnoreCase(name2);
            break;
        case SelectSnmpTrapDialog.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)

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