use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class DefaultAckServiceIT method processAck.
@Test
public void processAck() {
OnmsNode dbNode = m_nodeDao.get(m_populator.getNode1().getId());
OnmsEvent event = getEvent(dbNode);
OnmsNotification notif = getNotification(event);
// OnmsUserNotification un = getUserNotification(notif);
Assert.assertTrue(m_notifDao.countAll() > 0);
List<OnmsNotification> notifs = m_notifDao.findAll();
Assert.assertTrue((notifs.contains(notif)));
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setRefId(notif.getNotifyId());
ack.setAckType(AckType.NOTIFICATION);
m_ackDao.processAck(ack);
List<Acknowledgeable> ackables = m_ackDao.findAcknowledgables(ack);
Assert.assertEquals(1, ackables.size());
Acknowledgeable ackable = ackables.get(0);
Assert.assertEquals("admin", ackable.getAckUser());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class DatabasePopulator method doPopulateDatabase.
private void doPopulateDatabase() {
LOG.debug("==== DatabasePopulator Starting ====");
final NetworkBuilder builder = new NetworkBuilder();
final OnmsNode node1 = buildNode1(builder);
getNodeDao().save(node1);
getNodeDao().flush();
OnmsNode node2 = buildNode2(builder);
getNodeDao().save(node2);
getNodeDao().flush();
setNode2(node2);
OnmsNode node3 = buildNode3(builder);
getNodeDao().save(node3);
getNodeDao().flush();
setNode3(node3);
OnmsNode node4 = buildNode4(builder);
getNodeDao().save(node4);
getNodeDao().flush();
setNode4(node4);
OnmsNode node5 = buildNode5(builder);
getNodeDao().save(node5);
getNodeDao().flush();
setNode5(node5);
OnmsNode node6 = buildNode6(builder);
getNodeDao().save(node6);
getNodeDao().flush();
setNode6(node6);
final OnmsEvent event = buildEvent(builder.getDistPoller());
event.setEventCreateTime(new Date(1436881548292L));
event.setEventTime(new Date(1436881548292L));
getEventDao().save(event);
getEventDao().flush();
final OnmsNotification notif = buildTestNotification(builder, event);
getNotificationDao().save(notif);
getNotificationDao().flush();
final OnmsUserNotification userNotif = buildTestUserNotification(notif);
getUserNotificationDao().save(userNotif);
getUserNotificationDao().flush();
final OnmsUserNotification userNotif2 = buildTestUser2Notification(notif);
getUserNotificationDao().save(userNotif2);
getUserNotificationDao().flush();
final OnmsMonitoredService svc = getMonitoredServiceDao().get(node1.getId(), InetAddressUtils.addr("192.168.1.1"), "SNMP");
final OnmsOutage resolved = new OnmsOutage(new Date(1436881548292L), new Date(1436881548292L), event, event, svc, null, null);
getOutageDao().save(resolved);
getOutageDao().flush();
final OnmsOutage unresolved = new OnmsOutage(new Date(1436881548292L), event, svc);
getOutageDao().save(unresolved);
getOutageDao().flush();
final OnmsAlarm alarm = buildAlarm(event);
getAlarmDao().save(alarm);
getAlarmDao().flush();
final OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setAckTime(new Date(1437073152156L));
ack.setAckType(AckType.UNSPECIFIED);
ack.setAckAction(AckAction.UNSPECIFIED);
ack.setAckUser("admin");
getAcknowledgmentDao().save(ack);
getAcknowledgmentDao().flush();
final OnmsMonitoringLocation def = new OnmsMonitoringLocation();
def.setLocationName("RDU");
def.setMonitoringArea("East Coast");
def.setPollingPackageNames(Collections.singletonList("example1"));
def.setCollectionPackageNames(Collections.singletonList("example1"));
def.setGeolocation("Research Triangle Park, NC");
def.setLatitude(35.715751f);
def.setLongitude(-79.16262f);
def.setPriority(1L);
def.setTags(Collections.singletonList("blah"));
m_monitoringLocationDao.save(def);
LOG.debug("= DatabasePopulatorExtension Populate Starting =");
for (Extension eachExtension : extensions) {
DaoSupport daoSupport = eachExtension.getDaoSupport();
OnmsDao<?, ?> dao = daoSupport != null ? daoSupport.getDao() : null;
Class<? super OnmsDao<?, ?>> daoClass = daoSupport != null ? daoSupport.getDaoClass() : null;
registerDao(daoClass, dao);
dao = lookupDao(daoClass);
eachExtension.onPopulate(this, dao);
if (dao != null) {
dao.flush();
}
}
LOG.debug("= DatabasePopulatorExtension Populate Finished =");
LOG.debug("==== DatabasePopulator Finished ====");
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AcknowledgmentRestServiceIT method testAcknowlegeAlarm.
@Test
@JUnitTemporaryDatabase
public void testAcknowlegeAlarm() throws Exception {
final Pattern p = Pattern.compile("^.*<ackTime>(.*?)</ackTime>.*$", Pattern.DOTALL & Pattern.MULTILINE);
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=ack", 200);
// Try to fetch a non-existent ack, get 404 Not Found
String xml = sendRequest(GET, "/acks/999999", 404);
xml = sendRequest(GET, "/acks/count", 200);
// {@link DatabasePopulator} adds one ack so we have 2 total
assertEquals("2", xml);
Integer newAckId = null;
for (OnmsAcknowledgment ack : getXmlObject(JaxbUtils.getContextFor(OnmsAcknowledgmentCollection.class), "/acks", 200, OnmsAcknowledgmentCollection.class).getObjects()) {
if (AckType.UNSPECIFIED.equals(ack.getAckType())) {
// Ack from DatabasePopulator
assertEquals(AckAction.UNSPECIFIED, ack.getAckAction());
assertEquals("admin", ack.getAckUser());
} else if (AckType.ALARM.equals(ack.getAckType())) {
// Ack that we just created
assertEquals(new Integer(1), ack.getRefId());
assertEquals(AckAction.ACKNOWLEDGE, ack.getAckAction());
newAckId = ack.getId();
} else {
fail("Unrecognized alarm type: " + ack.getAckType().toString());
}
}
if (newAckId == null) {
fail("Couldn't determine ID of new ack");
}
xml = sendRequest(GET, "/acks/" + newAckId, 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
Matcher m = p.matcher(xml);
assertTrue(m.matches());
assertTrue(m.group(1).length() > 0);
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=unack", 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
m = p.matcher(xml);
assertFalse(m.matches());
// POST with no argument, this will ack by default
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1", 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
m = p.matcher(xml);
assertTrue(m.matches());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AlarmRepositoryIT method testAcknowledgements.
@Test
@JUnitTemporaryDatabase
public void testAcknowledgements() {
m_alarmRepo.acknowledgeAlarms(new int[] { 1 }, "agalue", new Date());
List<OnmsAcknowledgment> acks = m_alarmRepo.getAcknowledgments(1);
Assert.assertNotNull(acks);
Assert.assertEquals(1, acks.size());
Assert.assertEquals("agalue", acks.get(0).getAckUser());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AcknowledgmentDaoIT method testSaveUnspecified.
@Test
@Transactional
public void testSaveUnspecified() {
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setAckTime(new Date());
ack.setAckType(AckType.UNSPECIFIED);
ack.setAckAction(AckAction.UNSPECIFIED);
ack.setAckUser("not-admin");
getAcknowledgmentDao().save(ack);
getAcknowledgmentDao().flush();
Integer id = new Integer(ack.getId());
ack = null;
OnmsAcknowledgment ack2 = getAcknowledgmentDao().get(id);
assertNotNull(ack2);
assertEquals(id, ack2.getId());
assertFalse("admin".equals(ack2.getAckUser()));
assertEquals("not-admin", ack2.getAckUser());
}
Aggregations