ElasticsearchPlugin implements ActionPluginListener { protected void writeAlert(Action a) throws Exception { String url = a.getProperties().get(PROP_URL); String index = a.getProperties().get(PROP_INDEX); String type = a.getProperties().get(PROP_TYPE); String[] urls = url.split(","); HttpHost[] hosts = new HttpHost[urls.length]; for (int i=0; i<urls.length; i++) { hosts[i] = HttpHost.create(urls[0]); } RestClient client = RestClient.builder(hosts) .setHttpClientConfigCallback(httpClientBuilder -> { httpClientBuilder.useSystemProperties(); CredentialsProvider credentialsProvider = checkBasicCredentials(a); if (credentialsProvider != null) { httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } return httpClientBuilder; }).build(); HttpEntity document = new NStringEntity(transform(a), ContentType.APPLICATION_JSON); String endpoint = "/" + index + "/" + type; Header[] headers = checkHeaders(a); Response response = headers == null ? client.performRequest("POST", endpoint, Collections.EMPTY_MAP, document) : client.performRequest("POST", endpoint, Collections.EMPTY_MAP, document, headers); log.debugf(response.toString()); client.close(); } ElasticsearchPlugin(); @Override Set<String> getProperties(); @Override Map<String, String> getDefaultProperties(); @Override void process(ActionMessage msg); static final String PLUGIN_NAME; static final String PROP_URL; static final String PROP_INDEX; static final String PROP_TYPE; static final String PROP_TRANSFORM; static final String PROP_USER; static final String PROP_PASS; static final String PROP_FORWARDED_FOR; static final String PROP_PROXY_REMOTE_USER; static final String PROP_TOKEN; }
@Ignore @Test public void writeAlert() throws Exception { ElasticsearchPlugin plugin = new ElasticsearchPlugin(); Alert openAlert = JvmGarbageCollectionData.getOpenAlert(); Action openAction = new Action(openAlert.getTriggerId(), "elastic-search", "action1", openAlert); openAction.setProperties(plugin.getDefaultProperties()); openAction.getProperties().put("url", "https: plugin.writeAlert(openAction); }