/** * <p>down</p> * * @param reason a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.poller.PollStatus} object. */ public static PollStatus down(final String reason) { return unavailable(reason); }
/** * @deprecated We should specify a reason on every PollStatus object. * * @return a {@link org.opennms.netmgt.poller.PollStatus} object. */ public static PollStatus unavailable() { return unavailable(null); }
private String getFailureMessage(Result result, MonitoredService svc) { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Failed: "); for(Failure failure : result.getFailures()) { stringBuilder.append(" " + failure.getMessage() + "\n"); } String reason = "Selenium sequence failed: " + stringBuilder.toString(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); return stringBuilder.toString(); }
private PollStatus qualifyTime(int remoteTime, int localTime, int allowedSkew, PollStatus serviceStatus, double responseTime, boolean persistSkew) { LOG.debug("qualifyTime: checking remote time {} against local time {} with max skew of {}", remoteTime, localTime, allowedSkew); if ((localTime - remoteTime > allowedSkew) || (remoteTime - localTime > allowedSkew)) { String reason = "Remote time is " + (localTime > remoteTime ? ""+(localTime-remoteTime)+" seconds slow" : ""+(remoteTime-localTime)+" seconds fast"); LOG.debug(reason); serviceStatus = PollStatus.unavailable(reason); } if ((localTime > remoteTime) && (localTime - remoteTime > allowedSkew)) { String reason = "Remote time is " + (localTime - remoteTime) + " seconds behind local, more than the allowable " + allowedSkew; LOG.debug(reason); serviceStatus = PollStatus.unavailable(reason); } else if ((remoteTime > localTime) && (remoteTime - localTime > allowedSkew)) { String reason = "Remote time is " + (remoteTime - localTime) + " seconds ahead of local, more than the allowable " + allowedSkew; LOG.debug(reason); serviceStatus = PollStatus.unavailable(reason); } else { serviceStatus = PollStatus.available(); } storeResult(serviceStatus, remoteTime - localTime, responseTime, persistSkew); return serviceStatus; } }
double responseTime = tracker.elapsedTimeInMillis(); PollStatus ps = PollStatus.unavailable(); ps = PollStatus.available(responseTime); } else if (errorMessage.matches("^.*Authentication:.*$")) { ps = PollStatus.unavailable("authentication failed"); } else if (errorMessage.matches("^.*java.net.NoRouteToHostException.*$")) { ps = PollStatus.unavailable("no route to host"); } else if (errorMessage.matches("^.*(timeout: socket is not established|java.io.InterruptedIOException|java.net.SocketTimeoutException).*$")) { ps = PollStatus.unavailable("connection timed out"); } else if (errorMessage.matches("^.*(connection is closed by foreign host|java.net.ConnectException).*$")) { ps = PollStatus.unavailable("connection exception"); } else if (errorMessage.matches("^.*NumberFormatException.*$")) { ps = PollStatus.unavailable("an error occurred parsing the server version number"); } else if (errorMessage.matches("^.*java.io.IOException.*$")) { ps = PollStatus.unavailable("I/O exception");
final double responseTime = tracker.elapsedTimeInMillis(); PollStatus ps = PollStatus.unavailable(); ps = PollStatus.available(responseTime); } else if (SSH_AUTHENTICATION_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("authentication failed"); } else if (SSH_NOROUTETOHOST_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("no route to host"); } else if (SSH_SOCKETERROR_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("connection timed out"); } else if (SSH_CONNECTIONERROR_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("connection exception"); } else if (SSH_NUMBERFORMAT_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("an error occurred parsing the server version number"); } else if (SSH_IOEXCEPTION_PATTERN.matcher(errorMessage).find()) { ps = PollStatus.unavailable("I/O exception");
double responseTime = tracker.elapsedTimeInMillis(); PollStatus ps = PollStatus.unavailable(); ps = PollStatus.available(responseTime); } else if (errorMessage.matches("^.*Authentication:.*$")) { ps = PollStatus.unavailable("authentication failed"); } else if (errorMessage.matches("^.*java.net.NoRouteToHostException.*$")) { ps = PollStatus.unavailable("no route to host"); } else if (errorMessage.matches("^.*(timeout: socket is not established|java.io.InterruptedIOException|java.net.SocketTimeoutException).*$")) { ps = PollStatus.unavailable("connection timed out"); } else if (errorMessage.matches("^.*(connection is closed by foreign host|java.net.ConnectException).*$")) { ps = PollStatus.unavailable("connection exception"); } else if (errorMessage.matches("^.*NumberFormatException.*$")) { ps = PollStatus.unavailable("an error occurred parsing the server version number"); } else if (errorMessage.matches("^.*java.io.IOException.*$")) { ps = PollStatus.unavailable("I/O exception");
@Override public PollStatus handlePollResult(MonitoredService svc, Map<String, Object> parameters, PollStatus status) { if ("true".equals(ParameterMap.getKeyedString(parameters, "invert-status", "false"))) { if (status.isAvailable()) { return PollStatus.unavailable("This is an inverted service and the underlying service has started responding"); } else { return PollStatus.available(); } } return status; } }
PollStatus status = PollStatus.unavailable("Unable to retrieve database catalogs"); ResultSet resultset = null; try status = PollStatus.unavailable(reason);
PollStatus serviceStatus = PollStatus.unavailable(); String reason = "Unknown host exception generated for " + hostAddress + ", reason: " + uhE.getLocalizedMessage(); LOG.debug(reason); serviceStatus = PollStatus.unavailable(reason); } catch (RuntimeException rE) { LOG.debug("Unexpected runtime exception", rE); serviceStatus = PollStatus.unavailable("Unexpected runtime exception"); } catch (Throwable e) { LOG.debug("Unexpected exception", e); serviceStatus = PollStatus.unavailable("Unexpected exception");
@Override public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) { // Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000); // Get the minion to test whereas the minion ID is the nodes foreign ID by convention final OnmsNode node = nodeDao.get().get(svc.getNodeId()); final OnmsMinion minion = minionDao.get().findById(node.getForeignId()); // Calculate the time since the last heartbeat was received final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime(); final PollStatus status; if (lastSeen <= period) { status = PollStatus.available(); } else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) { status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat."); } else { status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0)); } return status; }
PollStatus status = PollStatus.unavailable(); CallableStatement cs = null; try status = PollStatus.unavailable(reason);
PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); serviceStatus = PollStatus.unavailable(e.getMessage()); } catch (IllegalArgumentException e) { LOG.error("Invalid parameters to monitor", e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); } catch (Throwable e) { LOG.error("Unexpected exception: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Unexpected exception: " + e.getMessage()); } finally { serviceStatus.setProperties(responseTimes);
@Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); serviceStatus.setProperties(responseTimes); }else { serviceStatus = PollStatus.unavailable( getFailureMessage( result, svc )); serviceStatus = PollStatus.unavailable("Selenium page sequence attempt on:" + svc.getIpAddr() + " failed : selenium-test compilation error " + e.getMessage()); String reason = "Selenium sequence failed: CompilationFailedException" + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (IOException e) { serviceStatus = PollStatus.unavailable("Selenium page sequence attempt on " + svc.getIpAddr() + " failed: IOException occurred, failed to find selenium-test: " + seleniumTestFilename); String reason = "Selenium sequence failed: IOException: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (Exception e) { serviceStatus = PollStatus.unavailable("Selenium page sequence attempt on " + svc.getIpAddr() + " failed:\n" + e.getMessage()); String reason = "Selenium sequence failed: Exception: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason);
String match = m_match; String clientBanner = m_clientBanner; PollStatus ps = PollStatus.unavailable(); ps = PollStatus.unavailable("server closed connection before banner was recieved."); ps = PollStatus.unavailable("server responded, but banner did not match '" + banner + "'"); } else { LOG.debug("isServer: matching response='{}'", response);
} catch (Throwable e) { LOG.debug("failed to ping {}", host, e); return PollStatus.unavailable(e.getMessage()); } else { return PollStatus.unavailable(null);
/** {@inheritDoc} */ @Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { int retries = ParameterMap.getKeyedInteger(parameters, "retry", PingConstants.DEFAULT_RETRIES); long timeout = ParameterMap.getKeyedLong(parameters, "timeout", PingConstants.DEFAULT_TIMEOUT); Long rtt = null; String phoneNumber = null; try { phoneNumber = phonebook.getTargetForAddress(svc.getIpAddr()); } catch (final PhonebookException e) { LOG.warn("Unable to get phonebook target for {}", svc.getIpAddr(), e); } if (phoneNumber != null) { try { rtt = SmsPinger.ping(phoneNumber, timeout, retries); } catch (final Exception e) { LOG.warn("Unable to ping phone number: {}", phoneNumber, e); } } if (rtt != null) { return PollStatus.available(rtt.doubleValue()); } else { return PollStatus.unavailable(); } } }
HttpMonitor.LOG.debug("checkStatus: Reason: \""+getReason()+"\""); return PollStatus.unavailable(getReason());
/** {@inheritDoc} */ @Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { TimeoutTracker timeoutTracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); for(timeoutTracker.reset(); timeoutTracker.shouldRetry(); timeoutTracker.nextAttempt()) { try { timeoutTracker.startAttempt(); if (svc.getAddress().isReachable(timeoutTracker.getSoTimeout())) { return PollStatus.available(timeoutTracker.elapsedTimeInMillis()); } } catch (IOException e) { LOG.debug("Unable to contact {}", svc.getIpAddr(), e); } } String reason = svc+" failed to respond"; LOG.debug(reason); return PollStatus.unavailable(reason); }
/** * Sends message based on properties and fields configured for the service. * * @param mailParms * @return a PollStatus */ private PollStatus sendTestMessage(final MailTransportParameters mailParms) { PollStatus status = PollStatus.unavailable("Test not completed."); final long interval = mailParms.getSendTestAttemptInterval(); final TimeoutTracker tracker = new TimeoutTracker(mailParms.getParameterMap(), mailParms.getRetries(), mailParms.getTimeout()); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { tracker.startAttempt(); LOG.debug("sendTestMessage: sending mail attempt: {}, elapsed time: {}ms", (tracker.getAttempt() + 1), String.format("%.2f", tracker.elapsedTimeInMillis())); try { final JavaMailer sendMailer = createMailer(mailParms); overRideDefaultProperties(mailParms, sendMailer); sendMailer.mailSend(); status = PollStatus.available(); break; } catch (final JavaMailerException e) { status = PollStatus.unavailable(e.getLocalizedMessage()); } if (tracker.shouldRetry()) { delayTest(status, interval); } } return status; }