use of org.opennms.netmgt.icmp.proxy.PingSummary in project opennms by OpenNMS.
the class PingCommand method execute.
@Override
public Object execute() throws Exception {
LOG.debug("ping:ping {} {}", m_location != null ? "-l " + m_location : "", m_host);
final InetAddress byName = InetAddress.getByName(m_host);
final PingRequestBuilder.Callback callback = (newSequence, summary) -> {
if (m_count > 1) {
if (summary.getSequences().size() == 0) {
System.out.println(PingStringUtils.renderHeader(summary));
}
if (newSequence != null) {
System.out.println(PingStringUtils.renderSequence(summary.getRequest(), newSequence));
}
if (summary.isComplete()) {
System.out.println(PingStringUtils.renderSummary(summary));
}
}
};
final CompletableFuture<PingSummary> future = locationAwarePingClient.ping(byName).withLocation(m_location).withSystemId(m_systemId).withNumberOfRequests(m_count).withProgressCallback(callback).execute();
while (true) {
try {
PingSummary summary = future.get(1, TimeUnit.SECONDS);
// In case of m_count > 1, the callback takes care of the "karaf.log" output.
if (m_count == 1) {
System.out.println(String.format("PING: %s %.3f ms", byName, summary.getSequence(0).getResponse().getRtt()));
}
break;
} catch (TimeoutException e) {
// pass
}
System.out.print(".");
}
return null;
}
use of org.opennms.netmgt.icmp.proxy.PingSummary in project opennms by OpenNMS.
the class DefaultPollContext method testCriticalPath.
private boolean testCriticalPath(CriticalPath criticalPath) {
if (!"ICMP".equalsIgnoreCase(criticalPath.getServiceName())) {
LOG.warn("Critical paths using services other than ICMP are not currently supported." + " ICMP will be used for testing {}.", criticalPath);
}
final InetAddress ipAddress = criticalPath.getIpAddress();
final int retries = OpennmsServerConfigFactory.getInstance().getDefaultCriticalPathRetries();
final int timeout = OpennmsServerConfigFactory.getInstance().getDefaultCriticalPathTimeout();
boolean available = false;
try {
final PingSummary pingSummary = m_locationAwarePingClient.ping(ipAddress).withLocation(criticalPath.getLocationName()).withTimeout(timeout, TimeUnit.MILLISECONDS).withRetries(retries).execute().get();
// We consider the path to be available if any of the requests were successful
available = pingSummary.getSequences().stream().filter(PingSequence::isSuccess).count() > 0;
} catch (InterruptedException e) {
LOG.warn("Interrupted while testing {}. Marking the path as available.", criticalPath);
available = true;
} catch (Throwable e) {
final Throwable cause = e.getCause();
if (cause != null && cause instanceof RequestTimedOutException) {
LOG.warn("No response was received when remotely testing {}." + " Marking the path as available.", criticalPath);
available = true;
} else if (cause != null && cause instanceof RequestRejectedException) {
LOG.warn("Request was rejected when attemtping to test the remote path {}." + " Marking the path as available.", criticalPath);
available = true;
}
LOG.warn("An unknown error occured while testing the critical path: {}." + " Marking the path as unavailable.", criticalPath, e);
available = false;
}
LOG.debug("testCriticalPath: checking {}@{}, available ? {}", criticalPath.getServiceName(), ipAddress, available);
return available;
}
use of org.opennms.netmgt.icmp.proxy.PingSummary in project opennms by OpenNMS.
the class SinglePingExecutionStrategy method execute.
@Override
public CompletableFuture<PingSummary> execute(PingRequestDTO requestDTO) {
return client.execute(requestDTO).thenApply(responseDTO -> {
final PingResponse pingResponse = new PingResponse();
pingResponse.setRtt(responseDTO.getRtt());
PingSummary summary = new PingSummary(requestDTO.toPingRequest(), 1);
summary.addSequence(1, pingResponse);
return summary;
});
}
use of org.opennms.netmgt.icmp.proxy.PingSummary in project opennms by OpenNMS.
the class PingCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
LOG.debug("ping:ping {} {}", m_location != null ? "-l " + m_location : "", m_host);
final InetAddress byName = InetAddress.getByName(m_host);
final PingRequestBuilder.Callback callback = (newSequence, summary) -> {
if (m_count > 1) {
if (summary.getSequences().size() == 0) {
System.out.println(PingStringUtils.renderHeader(summary));
}
if (newSequence != null) {
System.out.println(PingStringUtils.renderSequence(summary.getRequest(), newSequence));
}
if (summary.isComplete()) {
System.out.println(PingStringUtils.renderSummary(summary));
}
}
};
final CompletableFuture<PingSummary> future = locationAwarePingClient.ping(byName).withLocation(m_location).withNumberOfRequests(m_count).withProgressCallback(callback).execute();
while (true) {
try {
PingSummary summary = future.get(1, TimeUnit.SECONDS);
// In case of m_count > 1, the callback takes care of the "karaf.log" output.
if (m_count == 1) {
System.out.println(String.format("PING: %s %.3f ms", byName, summary.getSequence(0).getResponse().getRtt()));
}
break;
} catch (TimeoutException e) {
// pass
}
System.out.print(".");
}
return null;
}
Aggregations