use of org.opennms.netmgt.provision.support.ssh.InsufficientParametersException in project opennms by OpenNMS.
the class SshClient method connect.
/** {@inheritDoc} */
@Override
public void connect(final InetAddress address, final int port, final int timeout) throws Exception {
Map<String, ?> emptyMap = Collections.emptyMap();
TimeoutTracker tracker = new TimeoutTracker(emptyMap, SshClient.DEFAULT_RETRY, timeout);
String banner = m_banner;
String match = m_match;
String clientBanner = m_clientBanner;
PollStatus ps = PollStatus.unavailable();
Ssh ssh = new Ssh(address, port, tracker.getConnectionTimeout());
ssh.setClientBanner(clientBanner);
Pattern regex = null;
if (match == null && (banner == null || banner.equals("*"))) {
regex = null;
} else if (match != null) {
regex = Pattern.compile(match);
} else if (banner != null) {
regex = Pattern.compile(banner);
}
for (tracker.reset(); tracker.shouldRetry() && !ps.isAvailable(); tracker.nextAttempt()) {
try {
ps = ssh.poll(tracker);
} catch (InsufficientParametersException e) {
LOG.error("Caught InsufficientParametersException: {}", e.getMessage(), e);
break;
}
}
if (regex != null && ps.isAvailable()) {
String response = ssh.getServerBanner();
if (response == null) {
ps = PollStatus.unavailable("server closed connection before banner was recieved.");
}
if (!regex.matcher(response).find()) {
// Got a response but it didn't match... no need to attempt
// retries
LOG.debug("isServer: NON-matching response='{}'", response);
ps = PollStatus.unavailable("server responded, but banner did not match '" + banner + "'");
} else {
LOG.debug("isServer: matching response='{}'", response);
}
}
PollStatus result = ps;
m_isAvailable = result.isAvailable();
}
Aggregations