Search in sources :

Example 1 with EventInfo

use of org.netxms.client.events.EventInfo in project netxms by netxms.

the class EventTreeComparator 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 o1, Object o2) {
    TreeColumn sortColumn = ((TreeViewer) viewer).getTree().getSortColumn();
    if (sortColumn == null)
        return 0;
    EventInfo e1 = (EventInfo) o1;
    EventInfo e2 = (EventInfo) o2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) sortColumn.getData("ID")) {
        case AlarmDetails.EV_COLUMN_MESSAGE:
            result = e1.getMessage().compareToIgnoreCase(e2.getMessage());
            break;
        case AlarmDetails.EV_COLUMN_NAME:
            result = e1.getName().compareToIgnoreCase(e2.getName());
            break;
        case AlarmDetails.EV_COLUMN_SEVERITY:
            result = e1.getSeverity() - e2.getSeverity();
            break;
        case AlarmDetails.EV_COLUMN_SOURCE:
            result = session.getObjectName(e1.getSourceObjectId()).compareToIgnoreCase(session.getObjectName(e2.getSourceObjectId()));
            break;
        case AlarmDetails.EV_COLUMN_TIMESTAMP:
            result = e1.getTimeStamp().compareTo(e2.getTimeStamp());
            break;
        default:
            result = 0;
            break;
    }
    return (((TreeViewer) viewer).getTree().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : EventInfo(org.netxms.client.events.EventInfo) TreeColumn(org.eclipse.swt.widgets.TreeColumn) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Example 2 with EventInfo

use of org.netxms.client.events.EventInfo in project netxms by netxms.

the class AlarmTest method testGetEvents.

// NOTE: server must have at least 1 active alarm for this test.
public void testGetEvents() throws Exception {
    final NXCSession session = connect();
    HashMap<Long, Alarm> list = session.getAlarms();
    if (list.size() > 0) {
        final Long alarmId = list.keySet().iterator().next();
        List<EventInfo> events = session.getAlarmEvents(alarmId);
        for (EventInfo e : events) {
            System.out.println(e.getTimeStamp() + " " + e.getName() + " " + e.getMessage());
        }
    }
    session.disconnect();
}
Also used : EventInfo(org.netxms.client.events.EventInfo) Alarm(org.netxms.client.events.Alarm)

Example 3 with EventInfo

use of org.netxms.client.events.EventInfo in project netxms by netxms.

the class NXCSession method getAlarmEvents.

/**
 * Get information about events related to single active alarm. Information for terminated alarms cannot be accessed with this call.
 * User must have "view alarms" permission on alarm's source node and "view event log" system-wide access.
 *
 * @param alarmId alarm ID
 * @return list of related events
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<EventInfo> getAlarmEvents(long alarmId) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_ALARM_EVENTS);
    msg.setFieldInt32(NXCPCodes.VID_ALARM_ID, (int) alarmId);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
    List<EventInfo> list = new ArrayList<EventInfo>(count);
    long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
    for (int i = 0; i < count; i++) {
        EventInfo parent = null;
        long rootId = response.getFieldAsInt64(varId + 1);
        if (rootId != 0) {
            for (EventInfo e : list) {
                if (e.getId() == rootId) {
                    parent = e;
                    break;
                }
            }
        }
        list.add(new EventInfo(response, varId, parent));
        varId += 10;
    }
    return list;
}
Also used : EventInfo(org.netxms.client.events.EventInfo) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Aggregations

EventInfo (org.netxms.client.events.EventInfo)3 ArrayList (java.util.ArrayList)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 NXCPMessage (org.netxms.base.NXCPMessage)1 Alarm (org.netxms.client.events.Alarm)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1