use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private BridgeLinkNode convertFromModel(int nodeid, SharedSegment segment) {
final BridgeLinkNode linknode = new BridgeLinkNode();
for (BridgePort link : segment.getBridgePortsOnSegment()) {
final Integer rempnodeId = link.getNode().getId();
final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
if (link.getNode().getId().intValue() == nodeid) {
if (remiface != null) {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, null, null));
}
linknode.setBridgeLocalVlan(link.getVlan());
continue;
}
final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
if (remiface != null) {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
}
remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
remlinknode.setBridgeRemoteVlan(link.getVlan());
linknode.getBridgeLinkRemoteNodes().add(remlinknode);
}
if (segment.getBridgeBridgeLinks().isEmpty()) {
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
if (link.getNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
break;
}
}
} else {
for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
if (link.getNode().getId().intValue() == nodeid || link.getDesignatedNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeBridgeLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeBridgeLinkLastPollTime()));
break;
}
}
}
Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
for (String shredmac : segment.getMacsOnSegment()) {
sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
}
Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
for (String shredmac : sharedmacs.keySet()) {
if (sharedmacs.get(shredmac).isEmpty()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
if (snmp == null) {
remlinknode.setSharedHost(shredmac + " No ip address found");
} else {
remlinknode.setSharedHost(snmp.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
}
for (String shredmac : sharedhosts.keySet()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
Set<InetAddress> ips = new HashSet<InetAddress>();
if (sharedhosts.get(shredmac).isEmpty()) {
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
ips.add(ipnettomedia.getNetAddress());
}
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
OnmsIpInterface first = null;
boolean multiplenodeids = false;
for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
if (first == null)
first = ip;
if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
multiplenodeids = true;
ips.add(ip.getIpAddress());
}
if (multiplenodeids) {
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
} else {
remlinknode.setSharedHost(first.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
}
remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
if (ips.size() == 1) {
remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
}
return linknode;
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private IsisLinkNode convertFromModel(int nodeid, IsIsLink link) {
IsisLinkNode linknode = new IsisLinkNode();
linknode.setIsisCircIfIndex(link.getIsisCircIfIndex());
linknode.setIsisCircAdminState(IsisAdminState.getTypeString(link.getIsisCircAdminState().getValue()));
IsIsElement isiselement = m_isisElementDao.findByIsIsSysId(link.getIsisISAdjNeighSysID());
if (isiselement != null) {
linknode.setIsisISAdjNeighSysID(getAdjSysIDString(link.getIsisISAdjNeighSysID(), isiselement.getNode().getLabel()));
linknode.setIsisISAdjUrl(getNodeUrl(isiselement.getNode().getId()));
} else {
linknode.setIsisISAdjNeighSysID(link.getIsisISAdjNeighSysID());
}
linknode.setIsisISAdjNeighSysType(IsisISAdjNeighSysType.getTypeString(link.getIsisISAdjNeighSysType().getValue()));
linknode.setIsisISAdjNeighSNPAAddress(link.getIsisISAdjNeighSNPAAddress());
linknode.setIsisISAdjState(IsisISAdjState.get(link.getIsisISAdjState().getValue()).toString());
linknode.setIsisISAdjNbrExtendedCircID(link.getIsisISAdjNbrExtendedCircID());
OnmsSnmpInterface remiface = null;
if (isiselement != null) {
IsIsLink adjLink = m_isisLinkDao.get(isiselement.getNode().getId(), link.getIsisISAdjIndex(), link.getIsisCircIndex());
if (adjLink != null) {
remiface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(isiselement.getNode().getId(), adjLink.getIsisCircIfIndex());
}
}
if (remiface == null) {
remiface = getFromPhysAddress(link.getIsisISAdjNeighSNPAAddress());
}
if (remiface != null) {
linknode.setIsisISAdjNeighPort(getPortString(remiface.getIfIndex(), remiface.getIfName(), remiface.getIfAlias()));
linknode.setIsisISAdjUrl(getSnmpInterfaceUrl(remiface.getNode().getId(), remiface.getIfIndex()));
} else {
linknode.setIsisISAdjNeighPort("(Isis IS Adj Index: " + link.getIsisISAdjIndex() + ")");
}
linknode.setIsisLinkCreateTime(Util.formatDateToUIString(link.getIsisLinkCreateTime()));
linknode.setIsisLinkLastPollTime(Util.formatDateToUIString(link.getIsisLinkLastPollTime()));
return linknode;
}
use of org.opennms.netmgt.model.OnmsSnmpInterface 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.OnmsSnmpInterface in project opennms by OpenNMS.
the class PollerServiceTest method testPoll.
public void testPoll() throws EventProxyException {
final int expectedPolldId = 7;
OnmsServiceType svcType = new OnmsServiceType();
svcType.setId(3);
svcType.setName("HTTP");
OnmsNode node = new OnmsNode();
node.setId(1);
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
iface.setSnmpInterface(snmpIface);
final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
m_eventProxy.send(isA(Event.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Event event = (Event) getCurrentArguments()[0];
assertEquals("Incorrect uei for demandPollService event", EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, event.getUei());
assertEquals("Incorrect nodeid for demandPollService event", monSvc.getNodeId().longValue(), event.getNodeid().longValue());
assertEquals("Incorrect ipadr for demandPollService event", InetAddressUtils.str(monSvc.getIpAddress()), event.getInterface());
assertEquals("Incorrect ifIndex for demandPollService event", monSvc.getIfIndex(), Integer.valueOf(event.getIfIndex()));
assertEquals("Incorrect service for demandPollService event", monSvc.getServiceType().getName(), event.getService());
EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
assertEquals(expectedPolldId, EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
return null;
}
});
replay(m_eventProxy);
m_pollerService.poll(monSvc, expectedPolldId);
verify(m_eventProxy);
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class InterfaceToNodeCacheDaoImplIT method setUp.
@Before
public void setUp() throws Exception {
m_databasePopulator.populateDatabase();
m_cache.dataSourceSync();
OnmsNode n = new OnmsNode(m_databasePopulator.getMonitoringLocationDao().getDefaultLocation(), "my-new-node");
n.setForeignSource("junit");
n.setForeignId("10001");
OnmsIpInterface iface = new OnmsIpInterface(InetAddress.getByName("192.168.1.3"), n);
iface.setIsManaged("M");
iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
OnmsSnmpInterface snmpIf = new OnmsSnmpInterface(n, 1001);
iface.setSnmpInterface(snmpIf);
snmpIf.getIpInterfaces().add(iface);
n.addIpInterface(iface);
m_databasePopulator.getNodeDao().save(n);
m_testNodeId = n.getId();
}
Aggregations