use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmUpdates.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testAlarmUpdates() throws Exception {
createAlarm(OnmsSeverity.MAJOR);
OnmsAlarm alarm = getLastAlarm();
alarm.setAlarmAckTime(null);
alarm.setAlarmAckUser(null);
getAlarmDao().saveOrUpdate(alarm);
final Integer alarmId = alarm.getId();
sendPut("/alarms", "ack=true&alarmId=" + alarmId, 204);
String xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("ackUser>admin<"));
sendPut("/alarms/" + alarmId, "clear=true", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("severity=\"CLEARED\""));
sendPut("/alarms/" + alarmId, "escalate=true", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("severity=\"NORMAL\""));
sendPut("/alarms/" + alarmId, "ticketId=12345", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("<troubleTicket>12345</troubleTicket>"));
sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
alarm = getLastAlarm();
alarm.setSeverity(OnmsSeverity.MAJOR);
alarm.setAlarmAckTime(null);
alarm.setAlarmAckUser(null);
getAlarmDao().saveOrUpdate(alarm);
// Log in as a normal REST user and attempt to resolve an alarm as a different user.
// This should fail with a 403 forbidden.
setUser("foo", new String[] { "ROLE_REST" });
sendPut("/alarms/" + alarmId, "ack=true&ackUser=bar", 403);
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsUser.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsUser() throws Exception {
setUser("ranger", new String[] { "ROLE_USER" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmStatsRestServiceIT method testNewestAndOldestBySeverity.
@Test
public void testNewestAndOldestBySeverity() throws Exception {
final OnmsAlarm oldestAckedAlarm = createAlarm(OnmsSeverity.WARNING, "admin");
final OnmsAlarm newestAckedAlarm = createAlarm(OnmsSeverity.WARNING, "admin");
final OnmsAlarm oldestUnackedAlarm = createAlarm(OnmsSeverity.WARNING, null);
final OnmsAlarm newestUnackedAlarm = createAlarm(OnmsSeverity.WARNING, null);
final String xml = sendRequest(GET, "/stats/alarms/by-severity", 200);
final String oldestAckedXml = getXml("oldestAcked", xml);
final String newestAckedXml = getXml("newestAcked", xml);
final String oldestUnackedXml = getXml("oldestUnacked", xml);
final String newestUnackedXml = getXml("newestUnacked", xml);
assertXpathMatches("should contain WARNING with ID#" + oldestAckedAlarm.getId(), oldestAckedXml, "//alarm[@severity='WARNING' and @id='" + oldestAckedAlarm.getId() + "']");
assertEquals("oldest acked XML firstEventTime", 1262322000000L, getFirstEventTime(oldestAckedXml).getTimeInMillis());
assertXpathMatches("should contain WARNING with ID#" + newestAckedAlarm.getId(), newestAckedXml, "//alarm[@severity='WARNING' and @id='" + newestAckedAlarm.getId() + "']");
assertEquals("newest acked XML firstEventTime", 1262325600000L, getFirstEventTime(newestAckedXml).getTimeInMillis());
assertXpathMatches("should contain WARNING with ID#" + oldestUnackedAlarm.getId(), oldestUnackedXml, "//alarm[@severity='WARNING' and @id='" + oldestUnackedAlarm.getId() + "']");
assertEquals("oldest unacked XML firstEventTime", 1262329200000L, getFirstEventTime(oldestUnackedXml).getTimeInMillis());
assertXpathMatches("should contain WARNING with ID#" + newestUnackedAlarm.getId(), newestUnackedXml, "//alarm[@severity='WARNING' and @id='" + newestUnackedAlarm.getId() + "']");
assertEquals("newest unacked XML firstEventTime", 1262332800000L, getFirstEventTime(newestUnackedXml).getTimeInMillis());
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsRest.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsRest() throws Exception {
setUser("ranger", new String[] { "ROLE_REST" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsMobile.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsMobile() throws Exception {
setUser("ranger", new String[] { "ROLE_MOBILE" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
Aggregations