Search in sources :

Example 16 with Alarm

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

the class ExpansionTest method testNodeAndAlarmExpanssion.

public void testNodeAndAlarmExpanssion() throws Exception {
    final NXCSession session = connect();
    session.syncObjects();
    final AbstractNode object = (AbstractNode) session.findObjectById(TestConstants.NODE_ID);
    final Map<Long, Alarm> alarms = session.getAlarms();
    final Map<String, String> inputValues = new HashMap<String, String>();
    final Alarm alarm = alarms.values().iterator().next();
    inputValues.put("Key1", "Value1");
    inputValues.put("Key2", "Value2");
    final List<String> stringsToExpand = new ArrayList<String>();
    stringsToExpand.add("%%%a%A");
    stringsToExpand.add("%g%I");
    stringsToExpand.add("%K%n%U");
    stringsToExpand.add("%(Key1)%(Key2)");
    final List<String> expandedStrings = session.substitureMacross(new ObjectContextBase(object, alarm), stringsToExpand, inputValues);
    assertEquals("%" + object.getPrimaryIP().getHostAddress().toString() + alarm.getMessage(), expandedStrings.get(0));
    assertEquals(object.getGuid().toString() + object.getObjectId(), expandedStrings.get(1));
    assertEquals(alarm.getKey() + object.getObjectName() + session.getUserName(), expandedStrings.get(2));
    session.disconnect();
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) ObjectContextBase(org.netxms.client.objecttools.ObjectContextBase) Alarm(org.netxms.client.events.Alarm) ArrayList(java.util.ArrayList)

Example 17 with Alarm

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

the class NXCSession method getAlarms.

/**
 * Get list of active alarms. For accessing terminated alarms log view API should be used.
 *
 * @return Hash map containing alarms
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public HashMap<Long, Alarm> getAlarms() throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_ALL_ALARMS);
    final long rqId = msg.getMessageId();
    sendMessage(msg);
    final HashMap<Long, Alarm> alarmList = new HashMap<Long, Alarm>(0);
    while (true) {
        msg = waitForMessage(NXCPCodes.CMD_ALARM_DATA, rqId);
        long alarmId = msg.getFieldAsInt32(NXCPCodes.VID_ALARM_ID);
        if (alarmId == 0)
            // ALARM_ID == 0 indicates end of list
            break;
        alarmList.put(alarmId, new Alarm(msg));
    }
    return alarmList;
}
Also used : HashMap(java.util.HashMap) Alarm(org.netxms.client.events.Alarm) NXCPMessage(org.netxms.base.NXCPMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 18 with Alarm

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

the class ClientConnectorService method onConnect.

/**
 * Called by connect task after successful connection
 *
 * @param session
 *           new session object
 */
public void onConnect(NXCSession session, Map<Long, Alarm> alarms) {
    synchronized (mutex) {
        if (session != null) {
            schedule(ACTION_DISCONNECT);
            this.session = session;
            this.alarms = alarms;
            session.addListener(this);
            setConnectionStatus(ConnectionStatus.CS_CONNECTED, session.getServerAddress());
            statusNotification(ConnectionStatus.CS_CONNECTED, session.getServerAddress());
            if (alarms != null) {
                long id = -1;
                Alarm alarm = null;
                // Find the newest alarm received when we were offline
                for (Alarm itAlarm : alarms.values()) if (itAlarm.getId() > id) {
                    alarm = itAlarm;
                    id = itAlarm.getId();
                }
                if (alarm != null && alarm.getId() > lastAlarmIdNotified)
                    processAlarmChange(alarm);
            }
        }
    }
}
Also used : Alarm(org.netxms.client.events.Alarm)

Example 19 with Alarm

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

the class AlarmsFragment method getAlarmsSelection.

/**
 * Get list of selected alarms
 */
private ArrayList<Long> getAlarmsSelection(MenuItem item) {
    ArrayList<Long> idList = new ArrayList<Long>();
    final SparseBooleanArray positions = lv.getCheckedItemPositions();
    if (positions != null && positions.size() > 0)
        for (int i = 0; i < adapter.getCount(); i++) if (positions.get(i)) {
            Alarm al = (Alarm) adapter.getItem(i);
            if (al != null)
                idList.add(al.getId());
        }
    if (// Get last item highlighted
    idList.size() == 0) {
        Alarm al = (Alarm) adapter.getItem(lastPosition);
        if (al != null)
            idList.add(al.getId());
    }
    return idList;
}
Also used : Alarm(org.netxms.client.events.Alarm) ArrayList(java.util.ArrayList) SparseBooleanArray(android.util.SparseBooleanArray)

Example 20 with Alarm

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

the class AlarmComments method refresh.

/**
 * Refresh view
 */
private void refresh() {
    new ConsoleJob(Messages.get().AlarmComments_GetComments, 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);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    updateAlarmDetails(alarm);
                    for (AlarmCommentsEditor e : editors.values()) e.dispose();
                    for (AlarmComment c : comments) editors.put(c.getId(), createEditor(c));
                    updateLayout();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AlarmComments_GetError;
        }
    }.start();
}
Also used : AlarmCommentsEditor(org.netxms.ui.eclipse.alarmviewer.widgets.AlarmCommentsEditor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AlarmComment(org.netxms.client.events.AlarmComment) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

Alarm (org.netxms.client.events.Alarm)25 AbstractObject (org.netxms.client.objects.AbstractObject)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 PartInitException (org.eclipse.ui.PartInitException)8 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)3 NXCException (org.netxms.client.NXCException)3 NXCSession (org.netxms.client.NXCSession)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 NXCPMessage (org.netxms.base.NXCPMessage)2 AlarmComment (org.netxms.client.events.AlarmComment)2 AbstractNode (org.netxms.client.objects.AbstractNode)2 ZoneMember (org.netxms.client.objects.ZoneMember)2 AbstractUserObject (org.netxms.client.users.AbstractUserObject)2 SuppressLint (android.annotation.SuppressLint)1