use of org.opennms.netmgt.model.OnmsUserNotification in project opennms by OpenNMS.
the class DatabasePopulator method buildTestUser2Notification.
private OnmsUserNotification buildTestUser2Notification(final OnmsNotification notif) {
final OnmsUserNotification userNotif2 = new OnmsUserNotification();
userNotif2.setUserId("TestUser2");
userNotif2.setNotification(notif);
return userNotif2;
}
use of org.opennms.netmgt.model.OnmsUserNotification in project opennms by OpenNMS.
the class DatabasePopulator method doResetDatabase.
private void doResetDatabase() {
LOG.debug("==== DatabasePopulator Reset ====");
for (final OnmsOutage outage : m_outageDao.findAll()) {
m_outageDao.delete(outage);
}
for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
m_userNotificationDao.delete(not);
}
for (final OnmsNotification not : m_notificationDao.findAll()) {
m_notificationDao.delete(not);
}
for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
m_alarmDao.delete(alarm);
}
for (final OnmsEvent event : m_eventDao.findAll()) {
m_eventDao.delete(event);
}
for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
eachIf.setSnmpInterface(null);
snmpIface.getNode().getIpInterfaces().remove(eachIf);
}
snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
m_snmpInterfaceDao.delete(snmpIface);
}
for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
iface.setSnmpInterface(null);
iface.getNode().getIpInterfaces().remove(iface);
m_ipInterfaceDao.delete(iface);
}
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
m_serviceTypeDao.delete(service);
}
for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
// Don't delete the default localhost monitoring location
if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
m_monitoringLocationDao.delete(location);
}
}
for (final OnmsCategory category : m_categoryDao.findAll()) {
m_categoryDao.delete(category);
}
LOG.debug("= DatabasePopulatorExtension Reset Starting =");
for (Extension eachExtension : extensions) {
DaoSupport daoSupport = eachExtension.getDaoSupport();
OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
eachExtension.onShutdown(this, dao);
if (dao != null) {
dao.flush();
}
}
LOG.debug("= DatabasePopulatorExtension Reset Finished =");
m_outageDao.flush();
m_userNotificationDao.flush();
m_notificationDao.flush();
m_alarmDao.flush();
m_eventDao.flush();
m_snmpInterfaceDao.flush();
m_ipInterfaceDao.flush();
m_nodeDao.flush();
m_serviceTypeDao.flush();
LOG.debug("==== DatabasePopulator Reset Finished ====");
}
use of org.opennms.netmgt.model.OnmsUserNotification 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.OnmsUserNotification in project opennms by OpenNMS.
the class DatabasePopulator method buildTestUserNotification.
private OnmsUserNotification buildTestUserNotification(final OnmsNotification notif) {
final OnmsUserNotification userNotif = new OnmsUserNotification();
userNotif.setUserId("TestUser");
userNotif.setNotification(notif);
return userNotif;
}
use of org.opennms.netmgt.model.OnmsUserNotification in project opennms by OpenNMS.
the class UserNotificationDaoIT method testSaveUserNotification.
@Test
@Transactional
public void testSaveUserNotification() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/UserNotificationDaoTest");
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
event.setIpAddr(iface.getIpAddress());
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/UserNotificationDaoTest", newEvent.getEventUei());
OnmsNotification notification = new OnmsNotification();
notification.setEvent(newEvent);
notification.setTextMsg("Tests are fun!");
m_notificationDao.save(notification);
OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
assertEquals("uei://org/opennms/test/UserNotificationDaoTest", newNotification.getEvent().getEventUei());
OnmsUserNotification userNotif = new OnmsUserNotification();
userNotif.setNotification(notification);
userNotif.setNotifyTime(new Date());
userNotif.setUserId("OpenNMS User");
userNotif.setMedia("E-mail");
userNotif.setContactInfo("test@opennms.org");
m_userNotificationDao.save(userNotif);
assertNotNull(userNotif.getNotification());
assertEquals(userNotif.getUserId(), "OpenNMS User");
}
Aggregations