@Test public void testMissingScriptConfiguration() throws Exception { m_configuration.setProperty(AlertScriptDispatcher.SCRIPT_CONFIG_DEFAULT_KEY, null); DispatchCallback callback = EasyMock.createNiceMock(DispatchCallback.class); AlertNotification notification = new AlertNotification(); notification.Callback = callback; notification.CallbackIds = Collections.singletonList(UUID.randomUUID().toString()); callback.onFailure(notification.CallbackIds); EasyMock.expectLastCall().once(); EasyMock.replay(callback); NotificationDispatcher dispatcher = m_dispatchFactory.getDispatcher(TargetType.ALERT_SCRIPT.name()); dispatcher.dispatch(notification); EasyMock.verify(callback); }
@Override public void dispatch(Notification notification) { String scriptKey = getScriptConfigurationKey(notification); String script = m_configuration.getProperty(scriptKey); if (null == script) { LOG.warn( "Unable to dispatch notification because the {} configuration property was not found", scriptKey); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } if (notification.getType() != Notification.Type.ALERT) { LOG.warn("The {} dispatcher is not able to dispatch notifications of type {}", getType(), notification.getType()); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } long timeout = getScriptConfigurationTimeout(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; AlertNotification alertNotification = (AlertNotification) notification; ProcessBuilder processBuilder = getProcessBuilder(script, alertNotification); AlertScriptRunnable runnable = new AlertScriptRunnable(alertNotification, script, processBuilder, timeout, timeUnit); m_executor.execute(runnable); }
AlertScriptDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { String scriptKey = getScriptConfigurationKey(notification); String script = m_configuration.getProperty(scriptKey); if (null == script) { LOG.warn( "Unable to dispatch notification because the {} configuration property was not found", scriptKey); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } if (notification.getType() != Notification.Type.ALERT) { LOG.warn("The {} dispatcher is not able to dispatch notifications of type {}", getType(), notification.getType()); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } long timeout = getScriptConfigurationTimeout(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; AlertNotification alertNotification = (AlertNotification) notification; ProcessBuilder processBuilder = getProcessBuilder(script, alertNotification); AlertScriptRunnable runnable = new AlertScriptRunnable(alertNotification, script, processBuilder, timeout, timeUnit); m_executor.execute(runnable); } }
AlertScriptDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { String scriptKey = getScriptConfigurationKey(notification); String script = m_configuration.getProperty(scriptKey); if (null == script) { LOG.warn( "Unable to dispatch notification because the {} configuration property was not found", scriptKey); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } if (notification.getType() != Notification.Type.ALERT) { LOG.warn("The {} dispatcher is not able to dispatch notifications of type {}", getType(), notification.getType()); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } long timeout = getScriptConfigurationTimeout(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; AlertNotification alertNotification = (AlertNotification) notification; ProcessBuilder processBuilder = getProcessBuilder(script, alertNotification); AlertScriptRunnable runnable = new AlertScriptRunnable(alertNotification, script, processBuilder, timeout, timeUnit); m_executor.execute(runnable); }  }
AlertScriptDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { String scriptKey = getScriptConfigurationKey(notification); String script = m_configuration.getProperty(scriptKey); if (null == script) { LOG.warn( "Unable to dispatch notification because the {} configuration property was not found", scriptKey); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } if (notification.getType() != Notification.Type.ALERT) { LOG.warn("The {} dispatcher is not able to dispatch notifications of type {}", getType(), notification.getType()); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } long timeout = getScriptConfigurationTimeout(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; AlertNotification alertNotification = (AlertNotification) notification; ProcessBuilder processBuilder = getProcessBuilder(script, alertNotification); AlertScriptRunnable runnable = new AlertScriptRunnable(alertNotification, script, processBuilder, timeout, timeUnit); m_executor.execute(runnable); }  String getScriptConfigurationKey( Notification notification ); long getScriptConfigurationTimeout(); @Override final String getType(); @Override final boolean isNotificationContentGenerationRequired(); @Override void dispatch(Notification notification); @Override final boolean isDigestSupported(); @Override final TargetConfigurationResult validateTargetConfig(Map<String, Object> properties); }
AlertScriptDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { String scriptKey = getScriptConfigurationKey(notification); String script = m_configuration.getProperty(scriptKey); if (null == script) { LOG.warn( "Unable to dispatch notification because the {} configuration property was not found", scriptKey); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } if (notification.getType() != Notification.Type.ALERT) { LOG.warn("The {} dispatcher is not able to dispatch notifications of type {}", getType(), notification.getType()); if (null != notification.Callback) { notification.Callback.onFailure(notification.CallbackIds); } return; } long timeout = getScriptConfigurationTimeout(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; AlertNotification alertNotification = (AlertNotification) notification; ProcessBuilder processBuilder = getProcessBuilder(script, alertNotification); AlertScriptRunnable runnable = new AlertScriptRunnable(alertNotification, script, processBuilder, timeout, timeUnit); m_executor.execute(runnable); }  String getScriptConfigurationKey( Notification notification ); long getScriptConfigurationTimeout(); @Override final String getType(); @Override final boolean isNotificationContentGenerationRequired(); @Override void dispatch(Notification notification); @Override final boolean isDigestSupported(); @Override final TargetConfigurationResult validateTargetConfig(Map<String, Object> properties); static final String SCRIPT_CONFIG_DEFAULT_KEY; static final String SCRIPT_CONFIG_TIMEOUT_KEY; static final String DISPATCH_PROPERTY_SCRIPT_CONFIG_KEY; static final Escaper SHELL_ESCAPE; }