@Override
 public void onTestSkipped(ITestResult iTestResult) {
   super.onTestSkipped(iTestResult);
   testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Skipped: " + testMethodName, iTestResult.getThrowable());
   write2LogFile(iTestResult, DumpUtils.createTestFolder(testMethodName, suiteName));
 }
 @Override
 public void onTestFailure(ITestResult iTestResult) {
   if (suiteName.toLowerCase().contains("webui")) {
     if (testInvocationCounter < maxCount) {
       testInvocationCounter++;
       iTestResult.setAttribute("retry", true);
     } else {
       LogUtils.log("Number of retries expired.");
       iTestResult.setStatus(ITestResult.FAILURE);
       // reset count
       testInvocationCounter = 1;
       testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
       LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
       File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
       write2LogFile(iTestResult, testFolder);
       write2ErrorTxtFile(iTestResult, testFolder);
     }
   } else {
     testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
     LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
     File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
     write2LogFile(iTestResult, testFolder);
     write2ErrorTxtFile(iTestResult, testFolder);
   }
   super.onTestFailure(iTestResult);
 }
 @Override
 public void onTestStart(ITestResult iTestResult) {
   super.onTestStart(iTestResult);
   String testName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Start: " + testName);
   if (enableLogstash) {
     initLogstash(testName);
   }
 }
 @Override
 public void onTestSuccess(ITestResult iTestResult) {
   super.onTestSuccess(iTestResult);
   if (suiteName.toLowerCase().contains("webui")) {
     testInvocationCounter = 1;
   }
   testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Passed: " + testMethodName);
   write2LogFile(iTestResult, DumpUtils.createTestFolder(testMethodName, suiteName));
 }
  @Override
  public void onConfigurationFailure(ITestResult iTestResult) {
    super.onConfigurationFailure(iTestResult);
    String testName = iTestResult.getTestClass().getName();
    String configurationName = iTestResult.getMethod().toString().split("\\(|\\)")[0];
    if (!enableLogstash && isAfter(iTestResult)) {
      DumpUtils.copyBeforeConfigurationsLogToTestDir(testName, suiteName);
      testName = testMethodName;
    }
    if (suiteName
        == null) { // this is in case the suite has a @BeforeSuite method. which is invoked before
                   // the onStart is.
      suiteName = System.getProperty("iTests.suiteName", "sgtest");
    }
    LogUtils.log("Configuration Failed: " + configurationName, iTestResult.getThrowable());

    if (enableLogstash && iTestResult.getMethod().isBeforeClassConfiguration()) {
      initLogstash2(iTestResult);
    }

    String newmanTestFolder = System.getProperty("newman.test.path");
    if (newmanTestFolder != null) {
      File testFolder = new File(newmanTestFolder);
      ZipUtils.unzipArchive(testFolder);
      try {
        copyAllFilesToLogDir(testFolder, testFolder);
      } catch (IOException e) {
        LogUtils.log("Failed to copy all log files");
      }
    } else {
      ZipUtils.unzipArchive(testMethodName, suiteName);
    }

    if (enableLogstash
        && isAfter(iTestResult)
        && !iTestResult.getMethod().isAfterClassConfiguration()
        && !iTestResult.getMethod().isAfterSuiteConfiguration()) {
      testName = testMethodName;
    }
    File testFolder = DumpUtils.createTestFolder(testName, suiteName);
    write2LogFile(iTestResult, testFolder);
    write2ErrorTxtFile(iTestResult, testFolder);

    if (isAfter(iTestResult)) {
      if (enableLogstash) {
        if (process != null) {
          killLogstashAgent(1, logstashLogPath);
        }
        if (process2 != null && iTestResult.getMethod().isAfterClassConfiguration()) {
          killLogstashAgent(2, logstashLogPath2);
        }
      }
    }
  }
 @Override
 public void onFinish(ITestContext testContext) {
   super.onFinish(testContext);
   if (suiteName == null) suiteName = System.getProperty("iTests.suiteName", "sgtest");
   LogUtils.log("Finishing Suite: " + suiteName.toLowerCase());
   if (suiteName.toLowerCase().contains("webui")) {
     onFinishWebUITests(testContext);
   }
   try {
     SGTestNGReporter.reset();
   } catch (Exception e) {
     // ignore
   }
 }
 @Override
 public void beforeConfiguration(ITestResult tr) {
   if (enableLogstash) {
     super.beforeConfiguration(tr);
     if (suiteName
         == null) { // this is in case the suite has a @BeforeSuite method. which is invoked before
                    // the onStart is.
       suiteName = System.getProperty("iTests.suiteName", "sgtest");
       buildNumber = System.getProperty("iTests.buildNumber");
       LogUtils.log("build number is now - " + buildNumber);
       version = System.getProperty("cloudifyVersion");
     }
   }
 }