use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NotificationDaoIT method testNotificationSave.
@Test
@Transactional
public void testNotificationSave() {
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/NotificationDaoTest");
// OnmsAlarm alarm = new OnmsAlarm();
// event.setAlarm(alarm);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = 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/NotificationDaoTest", 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/NotificationDaoTest", newNotification.getEvent().getEventUei());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class MockNodeDao method updateSubObjects.
private void updateSubObjects(final OnmsNode node) {
node.getAssetRecord().setNode(node);
getAssetRecordDao().saveOrUpdate(node.getAssetRecord());
for (final OnmsCategory cat : node.getCategories()) {
getCategoryDao().saveOrUpdate(cat);
}
/* not sure if this is necessary */
/*
getMonitoringLocationDao().saveOrUpdate(node.getLocation());
*/
/**
* delete any interfaces that were removed compared to the database *
*/
final OnmsNode dbNode = node.getId() == null ? null : get(node.getId());
if (dbNode != null) {
for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) {
if (!node.getSnmpInterfaces().contains(iface)) {
getSnmpInterfaceDao().delete(iface);
}
}
for (final OnmsIpInterface iface : dbNode.getIpInterfaces()) {
if (!node.getIpInterfaces().contains(iface)) {
getIpInterfaceDao().delete(iface);
}
}
}
for (final OnmsSnmpInterface iface : node.getSnmpInterfaces()) {
iface.setNode(node);
getSnmpInterfaceDao().saveOrUpdate(iface);
}
for (final OnmsIpInterface iface : node.getIpInterfaces()) {
iface.setNode(node);
getIpInterfaceDao().saveOrUpdate(iface);
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class IpInterfaceDaoHibernate method findPrimaryInterfaceByNodeId.
/**
* This function should be kept similar to {@link OnmsNode#getPrimaryInterface()}.
*/
@Override
public OnmsIpInterface findPrimaryInterfaceByNodeId(final Integer nodeId) {
Assert.notNull(nodeId, "nodeId cannot be null");
// SELECT ipaddr FROM ipinterface WHERE nodeid = ? AND issnmpprimary = 'P'
List<OnmsIpInterface> primaryInterfaces = find("from OnmsIpInterface as ipInterface where ipInterface.node.id = ? and ipInterface.isSnmpPrimary = 'P' order by ipLastCapsdPoll desc", nodeId);
if (primaryInterfaces.size() < 1) {
return null;
} else {
OnmsIpInterface retval = primaryInterfaces.iterator().next();
if (primaryInterfaces.size() > 1) {
LOG.warn("Multiple primary SNMP interfaces for node {}, returning most recently scanned interface: {}", nodeId, retval.getInterfaceId());
}
return retval;
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class LocationMonitorDaoHibernate method findStatusChangesForNodeForUniqueMonitorAndInterface.
/**
* {@inheritDoc}
*/
@Override
public Collection<LocationMonitorIpInterface> findStatusChangesForNodeForUniqueMonitorAndInterface(final int nodeId) {
@SuppressWarnings("unchecked") final List<Object[]> l = (List<Object[]>) getHibernateTemplate().find("select distinct status.locationMonitor, status.monitoredService.ipInterface from OnmsLocationSpecificStatus as status " + "where status.monitoredService.ipInterface.node.id = ?", nodeId);
final HashSet<LocationMonitorIpInterface> ret = new HashSet<>();
for (Object[] tuple : l) {
OnmsLocationMonitor mon = (OnmsLocationMonitor) tuple[0];
OnmsIpInterface ip = (OnmsIpInterface) tuple[1];
ret.add(new LocationMonitorIpInterface(mon, ip));
}
return ret;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DistributedStatusResourceType method getResourcesForParent.
/**
* {@inheritDoc}
*/
@Override
public List<OnmsResource> getResourcesForParent(OnmsResource parent) {
if (!NodeResourceType.isNode(parent)) {
return Collections.emptyList();
}
final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
final List<OnmsResource> resources = Lists.newLinkedList();
final Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId());
for (LocationMonitorIpInterface status : statuses) {
String definitionName = status.getLocationMonitor().getLocation();
String id = status.getLocationMonitor().getId();
final OnmsIpInterface ipInterface = status.getIpInterface();
String ipAddr = InetAddressUtils.str(ipInterface.getIpAddress());
if (m_resourceStorageDao.exists(getRelativeInterfacePath(id, ipAddr), 0)) {
resources.add(createResource(definitionName, id, ipAddr));
}
}
return OnmsResource.sortIntoResourceList(resources);
}
Aggregations