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;
}
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();
}
}
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();
}
}
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;
}
Aggregations