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