use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForService.
/**
* <p>closeOutagesForService</p>
*
* @param closeDate a {@link java.util.Date} object.
* @param eventId a int.
* @param nodeId a int.
* @param ipAddr a {@link java.lang.String} object.
* @param serviceName a {@link java.lang.String} object.
*/
@Override
public void closeOutagesForService(Date closeDate, int eventId, int nodeId, String ipAddr, String serviceName) {
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("monitoredService.serviceType", "serviceType", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
criteria.addRestriction(new EqRestriction("serviceType.name", serviceName));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
outage.setServiceRegainedEvent(m_eventDao.get(eventId));
m_outageDao.update(outage);
LOG.info("Calling closeOutagesForService: {}", outage);
}
}
use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForInterface.
/**
* <p>closeOutagesForInterface</p>
*
* @param closeDate a {@link java.util.Date} object.
* @param eventId a int.
* @param nodeId a int.
* @param ipAddr a {@link java.lang.String} object.
*/
@Override
public void closeOutagesForInterface(Date closeDate, int eventId, int nodeId, String ipAddr) {
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
outage.setServiceRegainedEvent(m_eventDao.get(eventId));
m_outageDao.update(outage);
}
}
use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForUnmanagedServices.
/**
*
*/
@Override
public void closeOutagesForUnmanagedServices() {
Date closeDate = new java.util.Date();
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new AnyRestriction(new EqRestriction("monitoredService.status", "D"), new EqRestriction("monitoredService.status", "F"), new EqRestriction("monitoredService.status", "U")));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
m_outageDao.update(outage);
}
criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new AnyRestriction(new EqRestriction("ipInterface.isManaged", "F"), new EqRestriction("ipInterface.isManaged", "U")));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
m_outageDao.update(outage);
}
}
use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method getSnmpNode.
@Override
public Node getSnmpNode(final int nodeid) {
final Criteria criteria = new Criteria(OnmsNode.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("ipInterfaces", "iface", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE));
criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY));
criteria.addRestriction(new EqRestriction("id", nodeid));
final List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
if (nodes.size() > 0) {
final OnmsNode node = nodes.get(0);
return new Node(node.getId(), node.getPrimaryInterface().getIpAddress(), node.getSysObjectId(), node.getSysName(), node.getLocation() == null ? null : node.getLocation().getLocationName());
} else {
return null;
}
}
use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.
the class Nms8000EnIT method testLldpLinks.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = NMMR1_IP, port = 161, resource = NMMR1_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMR2_IP, port = 161, resource = NMMR2_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMR3_IP, port = 161, resource = NMMR3_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMSW1_IP, port = 161, resource = NMMSW1_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMSW2_IP, port = 161, resource = NMMSW2_SNMP_RESOURCE_2) })
public void testLldpLinks() throws Exception {
m_nodeDao.save(builder.getNMMR1());
m_nodeDao.save(builder.getNMMR2());
m_nodeDao.save(builder.getNMMR3());
m_nodeDao.save(builder.getNMMSW1());
m_nodeDao.save(builder.getNMMSW2());
m_nodeDao.flush();
m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
m_linkdConfig.getConfiguration().setUseLldpDiscovery(true);
m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
assertTrue(m_linkdConfig.useLldpDiscovery());
assertTrue(!m_linkdConfig.useCdpDiscovery());
assertTrue(!m_linkdConfig.useOspfDiscovery());
assertTrue(!m_linkdConfig.useBridgeDiscovery());
assertTrue(!m_linkdConfig.useIsisDiscovery());
final OnmsNode nmmr1 = m_nodeDao.findByForeignId("linkd", NMMR1_NAME);
final OnmsNode nmmr2 = m_nodeDao.findByForeignId("linkd", NMMR2_NAME);
final OnmsNode nmmr3 = m_nodeDao.findByForeignId("linkd", NMMR3_NAME);
final OnmsNode nmmsw1 = m_nodeDao.findByForeignId("linkd", NMMSW1_NAME);
final OnmsNode nmmsw2 = m_nodeDao.findByForeignId("linkd", NMMSW2_NAME);
assertTrue(m_linkd.scheduleNodeCollection(nmmr1.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmr2.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmr3.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmsw1.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmsw2.getId()));
assertTrue(m_linkd.runSingleSnmpCollection(nmmr1.getId()));
assertEquals(3, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmr2.getId()));
assertEquals(6, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmr3.getId()));
assertEquals(8, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmsw1.getId()));
assertEquals(10, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmsw2.getId()));
assertEquals(12, m_lldpLinkDao.countAll());
for (final OnmsNode node : m_nodeDao.findAll()) {
assertNotNull(node.getLldpElement());
printLldpElement(node.getLldpElement());
}
for (LldpLink link : m_lldpLinkDao.findAll()) {
printLldpLink(link);
}
List<LldpLink> allLinks = m_lldpLinkDao.findAll();
int combinedlinkfound = 0;
Set<Integer> parsed = new HashSet<Integer>();
for (LldpLink sourceLink : allLinks) {
System.err.println("loadtopology: parsing lldp link with id " + sourceLink.getId());
if (parsed.contains(sourceLink.getId())) {
continue;
}
parsed.add(sourceLink.getId());
LldpElement sourceElement = m_nodeDao.get(sourceLink.getNode().getId()).getLldpElement();
LldpLink targetLink = null;
for (LldpLink link : allLinks) {
if (parsed.contains(link.getId())) {
continue;
}
LldpElement element = m_nodeDao.get(link.getNode().getId()).getLldpElement();
//Compare the remote data to the targetNode element data
if (!sourceLink.getLldpRemChassisId().equals(element.getLldpChassisId()) || !link.getLldpRemChassisId().equals(sourceElement.getLldpChassisId()))
continue;
boolean bool1 = sourceLink.getLldpRemPortId().equals(link.getLldpPortId()) && link.getLldpRemPortId().equals(sourceLink.getLldpPortId());
boolean bool2 = sourceLink.getLldpRemPortDescr().equals(link.getLldpPortDescr()) && link.getLldpRemPortDescr().equals(sourceLink.getLldpPortDescr());
boolean bool3 = sourceLink.getLldpRemPortIdSubType() == link.getLldpPortIdSubType() && link.getLldpRemPortIdSubType() == sourceLink.getLldpPortIdSubType();
if (bool1 && bool2 && bool3) {
targetLink = link;
parsed.add(targetLink.getId());
System.err.println("loadtopology: lldp link with id " + link.getId() + " is target.");
break;
}
}
if (targetLink == null) {
final org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", sourceLink.getLldpRemSysname()));
List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
if (nodes.size() == 1) {
targetLink = reverseLldpLink(nodes.get(0), sourceLink.getNode().getLldpElement(), sourceLink);
System.err.println("loadtopology: found using sysname: lldp link with id " + targetLink + " is target.");
}
}
if (targetLink == null) {
continue;
}
combinedlinkfound++;
}
assertEquals(6, combinedlinkfound);
}
Aggregations