Search in sources :

Example 11 with OnmsAlarm

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with OnmsAlarm

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 13 with OnmsAlarm

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());
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test)

Example 14 with OnmsAlarm

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 15 with OnmsAlarm

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7