use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class JtiTelemetryIT method sendnewSuspectEvent.
public static OnmsNode sendnewSuspectEvent(Executor executor, InetSocketAddress opennmsHttp, TestEnvironment m_testEnvironment, boolean isMinion, Date startOfTest) throws ClientProtocolException, IOException {
Event minionEvent = new Event();
minionEvent.setUei("uei.opennms.org/internal/discovery/newSuspect");
minionEvent.setHost(SENDER_IP);
minionEvent.setInterface(SENDER_IP);
minionEvent.setInterfaceAddress(Inet4Address.getByName(SENDER_IP));
minionEvent.setSource("system-test");
minionEvent.setSeverity("4");
if (isMinion) {
Parm parm = new Parm();
parm.setParmName("location");
Value minion = new Value("MINION");
parm.setValue(minion);
List<Parm> parms = new ArrayList<>();
parms.add(parm);
minionEvent.setParmCollection(parms);
}
String xmlString = JaxbUtils.marshal(minionEvent);
executor.execute(Request.Post(String.format("http://%s:%d/opennms/rest/events", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyString(xmlString, ContentType.APPLICATION_XML)).returnContent();
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).eq("ipAddr", Inet4Address.getByName(SENDER_IP)).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
final OnmsNode onmsNode = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("label", SENDER_IP).ge("createTime", startOfTest).toCriteria()), notNullValue());
assertNotNull(onmsNode);
if (isMinion) {
assertThat(onmsNode.getLocation().getLocationName(), is("MINION"));
}
LOG.info(" New suspect event has been sent and node has been created for IP : {}", SENDER_IP);
return onmsNode;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class MinionHeartbeatOutageIT method testHeartbeatOutages.
@Test
public void testHeartbeatOutages() throws Exception {
Date startOfTest = new Date();
InetSocketAddress minionSshAddr = testEnvironment.getServiceAddress(ContainerAlias.MINION, 8201);
InetSocketAddress opennmsSshAddr = testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8101);
installFeaturesOnMinion(minionSshAddr);
installFeaturesOnOpenNMS(opennmsSshAddr);
// Wait for the Minion to show up
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
// Make sure that the node is available
await().atMost(180, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("foreignSource", "Minions").eq("foreignId", "00000000-0000-0000-0000-000000ddba11").toCriteria()), equalTo(1));
// Make sure that the expected events are present
/*
assertEquals(1, DaoUtils.countMatchingCallable(
getDaoFactory().getDao(EventDaoHibernate.class),
new CriteriaBuilder(OnmsEvent.class)
.eq("eventUei", EventConstants.MONITORING_SYSTEM_ADDED_UEI)
.like("eventParms", String.format("%%%s=%s%%", EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION))
.like("eventParms", String.format("%%%s=%s%%", EventConstants.PARAM_MONITORING_SYSTEM_ID, "00000000-0000-0000-0000-000000ddba11"))
.like("eventParms", String.format("%%%s=%s%%", EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, "MINION"))
.toCriteria()
).call().intValue()
);
*/
assertEquals(1, getDaoFactory().getDao(EventDaoHibernate.class).findMatching(new CriteriaBuilder(OnmsEvent.class).alias("eventParameters", "eventParameters").eq("eventUei", EventConstants.MONITORING_SYSTEM_ADDED_UEI).toCriteria()).stream().filter(e -> e.getEventParameters().stream().anyMatch(p -> EventConstants.PARAM_MONITORING_SYSTEM_TYPE.equals(p.getName()) && OnmsMonitoringSystem.TYPE_MINION.equals(p.getValue()))).filter(e -> e.getEventParameters().stream().anyMatch(p -> EventConstants.PARAM_MONITORING_SYSTEM_ID.equals(p.getName()) && "00000000-0000-0000-0000-000000ddba11".equals(p.getValue()))).filter(e -> e.getEventParameters().stream().anyMatch(p -> EventConstants.PARAM_MONITORING_SYSTEM_LOCATION.equals(p.getName()) && "MINION".equals(p.getValue()))).distinct().count());
assertEquals(0, DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.MONITORING_SYSTEM_LOCATION_CHANGED_UEI).toCriteria()).call().intValue());
for (int i = 0; i < 3; i++) {
restartContainer(ContainerAlias.MINION);
// Reset the startOfTest timestamp
startOfTest = new Date();
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
}
for (int i = 0; i < 2; i++) {
restartContainer(ContainerAlias.OPENNMS);
// Reset the startOfTest timestamp
startOfTest = new Date();
await().atMost(240, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
}
for (int i = 0; i < 1; i++) {
restartContainer(ContainerAlias.MINION);
// Reset the startOfTest timestamp
startOfTest = new Date();
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
}
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class NxosTelemetryIT method addRequisition.
public static OnmsNode addRequisition(InetSocketAddress opennmsHttp, boolean isMinion, Date startOfTest) {
RestClient client = new RestClient(opennmsHttp);
Requisition requisition = new Requisition("telemetry");
List<RequisitionInterface> interfaces = new ArrayList<>();
RequisitionInterface requisitionInterface = new RequisitionInterface();
requisitionInterface.setIpAddr("192.168.0.1");
requisitionInterface.setManaged(true);
requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
interfaces.add(requisitionInterface);
RequisitionNode node = new RequisitionNode();
String label = "nexus9k";
node.setNodeLabel(label);
node.setForeignId("nxos");
node.setInterfaces(interfaces);
if (isMinion) {
// For a requisition, foreignId needs to be unique, change foreignId
node.setLocation("MINION");
node.setForeignId("nexus9k");
// Change label so that node matches with foreignId
label = "nxos";
node.setNodeLabel(label);
}
requisition.insertNode(node);
client.addOrReplaceRequisition(requisition);
client.importRequisition("telemetry");
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
final OnmsNode onmsNode = await().atMost(3, MINUTES).pollInterval(30, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).ge("createTime", startOfTest).eq("label", label).toCriteria()), notNullValue());
assertNotNull(onmsNode);
return onmsNode;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class SyslogOverlappingIpAddressIT method testAssociateSyslogsWithNodesWithOverlappingIpAddresses.
/**
* @see https://issues.opennms.org/browse/NMS-8798
*
* @throws Exception
*/
@Test
public void testAssociateSyslogsWithNodesWithOverlappingIpAddresses() throws Exception {
final Date startOfTest = new Date();
final String hostIpAddress = "1.2.3.4";
// Create requisition with two node in different locations but same IP
final RestClient client = new RestClient(testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8980));
final Requisition requisition = new Requisition("overlapping");
final RequisitionNode node1 = new RequisitionNode();
node1.setNodeLabel("node_1");
node1.setLocation("MINION");
final RequisitionInterface interface1 = new RequisitionInterface();
interface1.setIpAddr(hostIpAddress);
interface1.setManaged(true);
interface1.setSnmpPrimary(PrimaryType.PRIMARY);
node1.setInterfaces(ImmutableList.of(interface1));
node1.setForeignId("node_1");
requisition.insertNode(node1);
final RequisitionNode node2 = new RequisitionNode();
node2.setNodeLabel("node_2");
node2.setLocation("BANANA");
final RequisitionInterface interface2 = new RequisitionInterface();
interface2.setIpAddr(hostIpAddress);
interface2.setManaged(true);
interface2.setSnmpPrimary(PrimaryType.PRIMARY);
node2.setInterfaces(ImmutableList.of(interface2));
node2.setForeignId("node_2");
requisition.insertNode(node2);
client.addOrReplaceRequisition(requisition);
client.importRequisition("overlapping");
// Wait for the nodes to be provisioned
final OnmsNode onmsNode1 = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("label", "node_1").toCriteria()), notNullValue());
final OnmsNode onmsNode2 = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("label", "node_2").toCriteria()), notNullValue());
// Sending syslog messages to each node and expect it to appear on the node
sendMessage(ContainerAlias.MINION, hostIpAddress, 1);
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).eq("node", onmsNode1).toCriteria()), is(1));
sendMessage(ContainerAlias.MINION_OTHER_LOCATION, hostIpAddress, 1);
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).eq("node", onmsNode2).toCriteria()), is(1));
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class PollerIT method getOutages.
/**
* Retrieves all of the outages (using DAOs) associated with
* the given service.
*/
private List<OnmsOutage> getOutages(MockService svc) {
OnmsMonitoredService monitoredSvc = m_monitoredServiceDao.get(svc.getNodeId(), svc.getAddress(), svc.getSvcName());
Criteria criteria = new CriteriaBuilder(OnmsOutage.class).eq("monitoredService", monitoredSvc).orderBy("ifLostService").toCriteria();
return m_outageDao.findMatching(criteria);
}
Aggregations