Search in sources :

Example 71 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Parm(org.opennms.netmgt.xml.event.Parm) Criteria(org.opennms.core.criteria.Criteria) NodeDao(org.opennms.netmgt.dao.api.NodeDao) EventDao(org.opennms.netmgt.dao.api.EventDao) Value(org.opennms.netmgt.xml.event.Value) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Event(org.opennms.netmgt.xml.event.Event) OnmsEvent(org.opennms.netmgt.model.OnmsEvent)

Example 72 with CriteriaBuilder

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));
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Date(java.util.Date) AbstractTestEnvironment(org.opennms.test.system.api.AbstractTestEnvironment) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) LoggerFactory(org.slf4j.LoggerFactory) MINUTES(java.util.concurrent.TimeUnit.MINUTES) EventConstants(org.opennms.netmgt.events.api.EventConstants) DaoUtils(org.opennms.smoketest.utils.DaoUtils) NodeDaoHibernate(org.opennms.netmgt.dao.hibernate.NodeDaoHibernate) DockerClient(com.spotify.docker.client.DockerClient) NullTestEnvironment(org.opennms.smoketest.NullTestEnvironment) EventDaoHibernate(org.opennms.netmgt.dao.hibernate.EventDaoHibernate) Timeout(org.junit.rules.Timeout) Assume(org.junit.Assume) OnmsNode(org.opennms.netmgt.model.OnmsNode) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) ContainerAlias(org.opennms.test.system.api.NewTestEnvironment.ContainerAlias) Before(org.junit.Before) PrintStream(java.io.PrintStream) DockerException(com.spotify.docker.client.exceptions.DockerException) SshClient(org.opennms.test.system.api.utils.SshClient) Logger(org.slf4j.Logger) TestEnvironment(org.opennms.test.system.api.TestEnvironment) Awaitility.await(com.jayway.awaitility.Awaitility.await) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) TimeUnit(java.util.concurrent.TimeUnit) MinionDaoHibernate(org.opennms.netmgt.dao.hibernate.MinionDaoHibernate) Rule(org.junit.Rule) OnmsMonitoringSystem(org.opennms.netmgt.model.OnmsMonitoringSystem) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenNMSSeleniumTestCase(org.opennms.smoketest.OpenNMSSeleniumTestCase) Matchers.is(org.hamcrest.Matchers.is) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) TestEnvironmentBuilder(org.opennms.test.system.api.TestEnvironmentBuilder) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion) InetSocketAddress(java.net.InetSocketAddress) Date(java.util.Date) Test(org.junit.Test)

Example 73 with CriteriaBuilder

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;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) ArrayList(java.util.ArrayList) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 74 with CriteriaBuilder

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));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) OnmsNode(org.opennms.netmgt.model.OnmsNode) RestClient(org.opennms.smoketest.utils.RestClient) Date(java.util.Date) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 75 with CriteriaBuilder

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);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4