@Test public void testVirtualHostBadBehaviorForWordpressPlugin() throws Exception { m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/\" port=\"80\" successMatch=\"Get the Network to Work\" user-agent=\"Jakarta Commons-HttpClient/3.0.1\" virtual-host=\"www.opennms.com\"/>\n" + "</page-sequence>\n"); PollStatus status = m_monitor.poll(getHttpService("www.opennms.com"), m_params); assertTrue("Expected unavailable but was "+status+": reason = "+status.getReason(), status.isDown()); }
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap) { DefaultHttpClient client = null; PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); Map<String,Number> responseTimes = new LinkedHashMap<String,Number>(); SequenceTracker tracker = new SequenceTracker(parameterMap, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for(tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt() ) { try { PageSequenceMonitorParameters parms = PageSequenceMonitorParameters.get(parameterMap); client = parms.createHttpClient(); tracker.startAttempt(); responseTimes.put("response-time", Double.NaN); parms.getPageSequence().execute(client, svc, responseTimes); double responseTime = tracker.elapsedTimeInMillis(); serviceStatus = PollStatus.available(); responseTimes.put("response-time", responseTime); serviceStatus.setProperties(responseTimes); } catch (PageSequenceMonitorException e) { serviceStatus = PollStatus.unavailable(e.getMessage()); serviceStatus.setProperties(responseTimes); } catch (IllegalArgumentException e) { log().error("Invalid parameters to monitor: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); serviceStatus.setProperties(responseTimes); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } } return serviceStatus; }
PageSequenceMonitor extends AbstractServiceMonitor { public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap) { DefaultHttpClient client = null; PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); Map<String,Number> responseTimes = new LinkedHashMap<String,Number>(); SequenceTracker tracker = new SequenceTracker(parameterMap, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for(tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt() ) { try { PageSequenceMonitorParameters parms = PageSequenceMonitorParameters.get(parameterMap); client = parms.createHttpClient(); tracker.startAttempt(); responseTimes.put("response-time", Double.NaN); parms.getPageSequence().execute(client, svc, responseTimes); double responseTime = tracker.elapsedTimeInMillis(); serviceStatus = PollStatus.available(); responseTimes.put("response-time", responseTime); serviceStatus.setProperties(responseTimes); } catch (PageSequenceMonitorException e) { serviceStatus = PollStatus.unavailable(e.getMessage()); serviceStatus.setProperties(responseTimes); } catch (IllegalArgumentException e) { log().error("Invalid parameters to monitor: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); serviceStatus.setProperties(responseTimes); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } } return serviceStatus; } }
PageSequenceMonitor extends AbstractServiceMonitor { public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap) { DefaultHttpClient client = null; PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); Map<String,Number> responseTimes = new LinkedHashMap<String,Number>(); SequenceTracker tracker = new SequenceTracker(parameterMap, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for(tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt() ) { try { PageSequenceMonitorParameters parms = PageSequenceMonitorParameters.get(parameterMap); client = parms.createHttpClient(); tracker.startAttempt(); responseTimes.put("response-time", Double.NaN); parms.getPageSequence().execute(client, svc, responseTimes); double responseTime = tracker.elapsedTimeInMillis(); serviceStatus = PollStatus.available(); responseTimes.put("response-time", responseTime); serviceStatus.setProperties(responseTimes); } catch (PageSequenceMonitorException e) { serviceStatus = PollStatus.unavailable(e.getMessage()); serviceStatus.setProperties(responseTimes); } catch (IllegalArgumentException e) { log().error("Invalid parameters to monitor: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); serviceStatus.setProperties(responseTimes); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } } return serviceStatus; }  }
PageSequenceMonitor extends AbstractServiceMonitor { public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap) { DefaultHttpClient client = null; PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); Map<String,Number> responseTimes = new LinkedHashMap<String,Number>(); SequenceTracker tracker = new SequenceTracker(parameterMap, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for(tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt() ) { try { PageSequenceMonitorParameters parms = PageSequenceMonitorParameters.get(parameterMap); client = parms.createHttpClient(); tracker.startAttempt(); responseTimes.put("response-time", Double.NaN); parms.getPageSequence().execute(client, svc, responseTimes); double responseTime = tracker.elapsedTimeInMillis(); serviceStatus = PollStatus.available(); responseTimes.put("response-time", responseTime); serviceStatus.setProperties(responseTimes); } catch (PageSequenceMonitorException e) { serviceStatus = PollStatus.unavailable(e.getMessage()); serviceStatus.setProperties(responseTimes); } catch (IllegalArgumentException e) { log().error("Invalid parameters to monitor: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); serviceStatus.setProperties(responseTimes); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } } return serviceStatus; }  PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap); }
PageSequenceMonitor extends AbstractServiceMonitor { public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap) { DefaultHttpClient client = null; PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); Map<String,Number> responseTimes = new LinkedHashMap<String,Number>(); SequenceTracker tracker = new SequenceTracker(parameterMap, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for(tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt() ) { try { PageSequenceMonitorParameters parms = PageSequenceMonitorParameters.get(parameterMap); client = parms.createHttpClient(); tracker.startAttempt(); responseTimes.put("response-time", Double.NaN); parms.getPageSequence().execute(client, svc, responseTimes); double responseTime = tracker.elapsedTimeInMillis(); serviceStatus = PollStatus.available(); responseTimes.put("response-time", responseTime); serviceStatus.setProperties(responseTimes); } catch (PageSequenceMonitorException e) { serviceStatus = PollStatus.unavailable(e.getMessage()); serviceStatus.setProperties(responseTimes); } catch (IllegalArgumentException e) { log().error("Invalid parameters to monitor: " + e.getMessage(), e); serviceStatus = PollStatus.unavailable("Invalid parameter to monitor: " + e.getMessage() + ". See log for details."); serviceStatus.setProperties(responseTimes); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } } return serviceStatus; }  PollStatus poll(final MonitoredService svc, final Map<String, Object> parameterMap);  }