Search in sources :

Example 1 with SshClient

use of org.opennms.test.system.api.utils.SshClient in project opennms by OpenNMS.

the class AbstractSyslogTestCase method installFeaturesOnOpenNMS.

protected static void installFeaturesOnOpenNMS(InetSocketAddress opennmsSshAddr, InetSocketAddress kafkaAddress, InetSocketAddress zookeeperAddress) throws Exception {
    try (final SshClient sshClient = new SshClient(opennmsSshAddr, "admin", "admin")) {
        PrintStream pipe = sshClient.openShell();
        // Configure and install the Elasticsearch REST event forwarder
        pipe.println("config:edit org.opennms.plugin.elasticsearch.rest.forwarder");
        pipe.println("config:property-set logAllEvents true");
        pipe.println("config:property-set batchSize 500");
        pipe.println("config:property-set batchInterval 500");
        pipe.println("config:property-set timeout 5000");
        // Retry enough times that all events are eventually sent
        // even if transient ES outages occur
        pipe.println("config:property-set retries 200");
        pipe.println("config:update");
        pipe.println("feature:install opennms-es-rest");
        pipe.println("feature:list -i");
        // Set the log level to INFO
        pipe.println("log:set INFO");
        pipe.println("logout");
        try {
            await().atMost(2, MINUTES).until(sshClient.isShellClosedCallable());
        } finally {
            LOG.info("Karaf output:\n{}", sshClient.getStdout());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) SshClient(org.opennms.test.system.api.utils.SshClient)

Example 2 with SshClient

use of org.opennms.test.system.api.utils.SshClient in project opennms by OpenNMS.

the class CollectorListIT method listAndVerifyCollectors.

public List<String> listAndVerifyCollectors(InetSocketAddress sshAddr, Set<String> expectedCollectors) throws Exception {
    List<String> unmatchedCollectors = new ArrayList<>();
    try (final SshClient sshClient = new SshClient(sshAddr, "admin", "admin")) {
        // List the collectors
        PrintStream pipe = sshClient.openShell();
        pipe.println("collection:list-collectors");
        pipe.println("logout");
        await().atMost(1, MINUTES).until(sshClient.isShellClosedCallable());
        // Parse the output
        String shellOutput = CommandTestUtils.stripAnsiCodes(sshClient.getStdout());
        shellOutput = StringUtils.substringAfter(shellOutput, "collection:list-collectors");
        LOG.info("Collectors output: {}", shellOutput);
        Set<String> collectors = new HashSet<>();
        for (String collector : shellOutput.split("\\r?\\n")) {
            if (StringUtils.isNotBlank(collector)) {
                collectors.add(collector);
            }
        }
        LOG.info("Found collectors: {}", collectors);
        // Verify
        for (String expectedCollector : expectedCollectors) {
            if (!collectors.contains(expectedCollector)) {
                unmatchedCollectors.add(expectedCollector);
            }
        }
    }
    return unmatchedCollectors;
}
Also used : PrintStream(java.io.PrintStream) SshClient(org.opennms.test.system.api.utils.SshClient) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with SshClient

use of org.opennms.test.system.api.utils.SshClient in project opennms by OpenNMS.

the class DetectorsCommandIT method listAndVerifyDetectors.

public List<String> listAndVerifyDetectors(String host, InetSocketAddress sshAddr) throws Exception {
    List<String> unmatchedDetectors = new ArrayList<>();
    try (final SshClient sshClient = new SshClient(sshAddr, "admin", "admin")) {
        // List the detectors
        PrintStream pipe = sshClient.openShell();
        pipe.println("provision:list-detectors");
        pipe.println("logout");
        await().atMost(1, MINUTES).until(sshClient.isShellClosedCallable());
        // Parse the output
        String shellOutput = CommandTestUtils.stripAnsiCodes(sshClient.getStdout());
        shellOutput = StringUtils.substringAfter(shellOutput, "provision:list-detectors");
        LOG.info("Detectors output: {}", shellOutput);
        Map<String, String> detectorMap = new HashMap<String, String>();
        for (String detector : shellOutput.split("\\r?\\n")) {
            if (StringUtils.isNotBlank(detector)) {
                String[] detectorSet = detector.split(":");
                if (detectorSet.length >= 2) {
                    detectorMap.put(detectorSet[0], detectorSet[1]);
                }
            }
        }
        LOG.info("Found detectors: {}", detectorMap);
        // Verify
        for (String detectorName : expectedDetectors.keySet()) {
            if (!detectorMap.containsKey(detectorName)) {
                unmatchedDetectors.add(detectorName);
            }
        }
    }
    return unmatchedDetectors;
}
Also used : PrintStream(java.io.PrintStream) SshClient(org.opennms.test.system.api.utils.SshClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 4 with SshClient

use of org.opennms.test.system.api.utils.SshClient in project opennms by OpenNMS.

the class MinionHeartbeatOutageIT method installFeaturesOnOpenNMS.

protected static void installFeaturesOnOpenNMS(InetSocketAddress opennmsSshAddr) throws Exception {
    try (final SshClient sshClient = new SshClient(opennmsSshAddr, "admin", "admin")) {
        PrintStream pipe = sshClient.openShell();
        pipe.println("feature:list -i");
        // Set the log level to INFO
        // 
        pipe.println("log:set INFO");
        pipe.println("logout");
        try {
            await().atMost(2, MINUTES).until(sshClient.isShellClosedCallable());
        } finally {
            getLogger().info("Karaf output:\n{}", sshClient.getStdout());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) SshClient(org.opennms.test.system.api.utils.SshClient)

Example 5 with SshClient

use of org.opennms.test.system.api.utils.SshClient in project opennms by OpenNMS.

the class MinionHeartbeatOutageIT method installFeaturesOnMinion.

/**
 * Install the Kafka features on Minion.
 *
 * @param minionSshAddr
 * @param kafkaAddress
 * @throws Exception
 */
protected static void installFeaturesOnMinion(InetSocketAddress minionSshAddr) throws Exception {
    try (final SshClient sshClient = new SshClient(minionSshAddr, "admin", "admin")) {
        PrintStream pipe = sshClient.openShell();
        pipe.println("feature:list -i");
        pipe.println("list");
        // Set the log level to INFO
        pipe.println("log:set INFO");
        pipe.println("logout");
        try {
            await().atMost(2, MINUTES).until(sshClient.isShellClosedCallable());
        } finally {
            getLogger().info("Karaf output:\n{}", sshClient.getStdout());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) SshClient(org.opennms.test.system.api.utils.SshClient)

Aggregations

PrintStream (java.io.PrintStream)12 SshClient (org.opennms.test.system.api.utils.SshClient)12 ArrayList (java.util.ArrayList)3 InetSocketAddress (java.net.InetSocketAddress)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1