Search in sources :

Example 1 with RestClient

use of org.opennms.smoketest.utils.RestClient 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 2 with RestClient

use of org.opennms.smoketest.utils.RestClient in project opennms by OpenNMS.

the class DetectorsOnMinionIT method checkServicesDetectedOnMinion.

@Test
public void checkServicesDetectedOnMinion() throws ClientProtocolException, IOException, InterruptedException {
    final InetSocketAddress opennmsHttp = m_testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8980);
    RestClient client = new RestClient(opennmsHttp);
    Requisition requisition = new Requisition("foreignSource");
    List<RequisitionInterface> interfaces = new ArrayList<RequisitionInterface>();
    RequisitionInterface requisitionInterface = new RequisitionInterface();
    requisitionInterface.setIpAddr(LOCALHOST);
    requisitionInterface.setManaged(true);
    requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
    interfaces.add(requisitionInterface);
    RequisitionNode node = new RequisitionNode();
    node.setNodeLabel("label");
    node.setLocation("MINION");
    node.setInterfaces(interfaces);
    node.setForeignId("foreignId");
    requisition.insertNode(node);
    client.addOrReplaceRequisition(requisition);
    client.importRequisition("foreignSource");
    await().atMost(5, MINUTES).pollDelay(0, SECONDS).pollInterval(30, SECONDS).until(getnumberOfServicesDetected(client), greaterThan(0));
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) ArrayList(java.util.ArrayList) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 3 with RestClient

use of org.opennms.smoketest.utils.RestClient in project opennms by OpenNMS.

the class MinionRestServiceIT method verifyMinionRestEndPoint.

@Test
@Ignore
public void verifyMinionRestEndPoint() {
    final InetSocketAddress opennmsHttp = new InetSocketAddress("localhost", 8980);
    RestClient client = new RestClient(opennmsHttp);
    OnmsMinion minion = new OnmsMinion();
    minion.setId(MINION_ID);
    minion.setLocation("minion");
    minion.setType(OnmsMonitoringSystem.TYPE_MINION);
    Response response = client.addMinion(minion);
    assertEquals(201, response.getStatus());
    OnmsMinion minionReturned = client.getMinion(MINION_ID);
    assertEquals(minionReturned.getId(), MINION_ID);
    // Delete minion doesn't work on docker setup otherwise this test can move to docker
    response = client.deleteMinion(MINION_ID);
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 RestClient (org.opennms.smoketest.utils.RestClient)3 InetSocketAddress (java.net.InetSocketAddress)2 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)2 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)2 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Response (javax.ws.rs.core.Response)1 Ignore (org.junit.Ignore)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)1