1414import org .apache .http .HttpStatus ;
1515import org .apache .http .entity .ContentType ;
1616import org .apache .http .nio .entity .NStringEntity ;
17+ import org .apache .jmeter .JMeter ;
1718import org .apache .jmeter .assertions .AssertionResult ;
1819import org .apache .jmeter .config .Arguments ;
1920import org .apache .jmeter .samplers .SampleResult ;
2021import org .apache .jmeter .threads .JMeterContextService ;
22+ import org .apache .jmeter .threads .JMeterVariables ;
2123import org .apache .jmeter .util .JMeterUtils ;
2224import org .apache .jmeter .visualizers .backend .AbstractBackendListenerClient ;
2325import org .apache .jmeter .visualizers .backend .BackendListenerContext ;
@@ -37,7 +39,7 @@ public class ElasticsearchBackend extends AbstractBackendListenerClient {
3739 private static final String ES_TIMEOUT_MS = "es.timout.ms" ;
3840 private static final String ES_SAMPLE_FILTER = "es.sample.filter" ;
3941 private static final String ES_TEST_MODE = "es.test.mode" ;
40- private static final String ES_TRANSPORT_CLIENT = "es.transport.client " ;
42+ private static final String ES_INCLUDE_VARS = "es.include.all.vars " ;
4143 private static final long DEFAULT_TIMEOUT_MS = 200L ;
4244 private static final Logger logger = LoggerFactory .getLogger (ElasticsearchBackend .class );
4345
@@ -61,6 +63,7 @@ public Arguments getDefaultParameters() {
6163 parameters .addArgument (ES_TIMEOUT_MS , Long .toString (DEFAULT_TIMEOUT_MS ));
6264 parameters .addArgument (ES_SAMPLE_FILTER , null );
6365 parameters .addArgument (ES_TEST_MODE , "info" );
66+ parameters .addArgument (ES_INCLUDE_VARS , "false" );
6467 return parameters ;
6568 }
6669
@@ -201,6 +204,7 @@ public Map<String, Object> getElasticData(SampleResult sr, BackendListenerContex
201204 jsonObject .put ("StartTimeInMs" , sr .getStartTime ());
202205 jsonObject .put ("EndTimeInMs" , sr .getEndTime ());
203206 jsonObject .put ("ElapsedTimeInMs" , System .currentTimeMillis () - sr .getStartTime ());
207+ jsonObject .put ("ResponseCode" , (sr .getResponseCode ()));
204208 jsonObject .put (ElasticsearchBackend .BUILD_NUMBER , this .buildNumber );
205209
206210 // Add the details according to the mode that is set
@@ -254,7 +258,35 @@ public Map<String, Object> getElasticData(SampleResult sr, BackendListenerContex
254258 Date elapsedTime = getElapsedTime (false );
255259 if (elapsedTime != null )
256260 jsonObject .put ("ElapsedTime" , elapsedTime );
257- jsonObject .put ("ResponseCode" , (sr .getResponseCode ()));
261+
262+ // //Add all variables (if set to true)
263+ // if(Boolean.parseBoolean(context.getParameter(ES_INCLUDE_VARS))) {
264+ // try {
265+ // System.out.println(JMeterContextService.getContext().getVariables());
266+ //
267+ // JMeterVariables vars = JMeterContextService.getContext().getCurrentSampler().getThreadContext().getVariables();
268+ // if(vars != null) {
269+ // System.out.println("Before foreach");
270+ // for(Map.Entry<String, Object> variable : vars.entrySet()) {
271+ // System.out.println("In foreach");
272+ // jsonObject.put(variable.getKey(), variable.getValue().toString());
273+ // }
274+ // }
275+ // } catch (Exception e) {
276+ // e.printStackTrace();
277+ // }
278+ // }
279+
280+ // Add all custom fields (if any)
281+ Iterator <String > pluginParameters = context .getParameterNamesIterator ();
282+ while (pluginParameters .hasNext ()) {
283+ String parameterName = pluginParameters .next ();
284+
285+ if (!parameterName .contains ("es." ) && !context .getParameter (parameterName ).trim ().equals ("" )) {
286+ jsonObject .put (parameterName , context .getParameter (parameterName ).trim ());
287+ }
288+ }
289+
258290
259291 return jsonObject ;
260292 }
0 commit comments