diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/case_information.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/case_information.twig new file mode 100644 index 00000000..b18c3e01 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/case_information.twig @@ -0,0 +1,14 @@ +{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.warning || testCase.state.critical || testCase.state.error) %} + , case "{{ testCase.name }}"$whitespace$ + {% if (testCase.state.error) %} + EXCEPTION: {{ errorMessageCreator.exceptionMessageTestCase(testCase) }} + {% else %} + {% if (testCase.state.critical) %} + over runtime ( {{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s) + {% else %} + over runtime ( {{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s) + {% endif %} + {% endif %} + {% endif %} +{% endfor %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary.twig new file mode 100644 index 00000000..83198994 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary.twig @@ -0,0 +1,78 @@ +{# This template renders the detailed summary for the current test suite. #} +{% include 'detailed_summary_css_styles.twig' %} + + + + + {% for testCase in testsuite.testCasesAsSortedSet %} + + + + {% endfor %} +
+ {{ getOutputState(testsuite.state).shortState }} Sakuli suite "{{ testsuite.id }}"$whitespace$ + {% if (testsuite.state.error) %} + {% else %} + {{ testsuite.state.nagiosStateDescription }}$whitespace$ + {% endif %} + {% if (testsuite.state.ok) %} + ({{ format("%.2fs", testsuite.duration) }})$whitespace$ + {% elseif (testsuite.state.name == 'WARNING_IN_SUITE') %} + ({{ format("%.2fs", testsuite.duration) }}/warn at {{ testsuite.warningTime }}s)$whitespace$ + {% elseif (testsuite.state.name == 'CRITICAL_IN_SUITE') %} + ({{ format("%.2fs", testsuite.duration) }}/crit at {{ testsuite.criticalTime }}s)$whitespace$ + {% elseif (testsuite.state.name == 'WARNING_IN_STEP') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.warningInStep) %} + {% for testStep in testCase.steps %} + {% if (testStep.state.warning) %} + , step "{{testStep.id}}" over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s) + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {% elseif (testsuite.state.name == 'WARNING_IN_CASE') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.warning) %} + , case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s) + {% endif %} + {% endfor %} + {% elseif (testsuite.state.name == 'CRITICAL_IN_CASE') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.critical) %} + , case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s) + {% endif %} + {% endfor %} + {% endif %} + {% if (testsuite.state.error) %} + ({{ format("%.2fs", testsuite.duration) }})$whitespace$ + {{ testsuite.state.nagiosStateDescription }}:$whitespace$ + {{ errorMessageCreator.exceptionMessageTestSuite(testsuite) }}.$whitespace$ + {% endif %} + . (Last suite run:$whitespace$ + {% if (empty(testsuite.stopDate)) %} + xx + {% else %} + {{ testsuite.stopDate|date("dd.MM.YY HH:mm:ss") }} + {% endif %}) + {% include 'exception_screenshot.twig' with { testDataEntity: testsuite } %} +
+ {{ getOutputState(testCase.state).shortState }} case "{{ testCase.id }}"$whitespace$ + {% if (testCase.state.ok) %} + ran in {{ format("%.2fs", testCase.duration) }} - {{ testCase.state.nagiosStateDescription }} + {% elseif (testCase.state.warning) %} + over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s) + {% include 'step_information.twig' with { testCase: testCase } %}$whitespace$ + {% elseif (testCase.state.critical) %} + {% set errorMessage = errorMessageCreator.exceptionMessageTestCase(testCase) %} + {% if (empty(errorMessage)) %} + over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s) + {% else %} + EXCEPTION: {{ errorMessageCreator.exceptionMessageTestCase(testCase) }} + {% include 'exception_screenshot.twig' with { testDataEntity: testCase } %} + {% for testStep in testCase.stepsAsSortedSet %} + {% include 'exception_screenshot.twig' with { testDataEntity: testStep } %} + {% endfor %} + {% endif %} + {% endif %} +
diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary_css_styles.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary_css_styles.twig new file mode 100644 index 00000000..0c3d372c --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/detailed_summary_css_styles.twig @@ -0,0 +1,60 @@ + \ No newline at end of file diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/error_message_creator.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/error_message_creator.twig new file mode 100644 index 00000000..2eaafa6b --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/error_message_creator.twig @@ -0,0 +1,42 @@ +{# macro for creating the exception message of a test data entity. If there are any suppressed exception, they will be also listed. #} +{% macro exceptionMessage (testDataEntity) %} + {% if (testDataEntity.exception is not null) %} + {{ testDataEntity.exception.message }} + {# add suppressed exceptions #} + {% for suppressedException in testDataEntity.exception.suppressed %} + $whitespace$-- Suppressed EXCEPTION: {{ suppressedException.message }} + {% endfor %} + {% endif %} +{% endmacro %} + +{# macro for creating the exception message of a test case and all of its test steps. #} +{% macro exceptionMessageTestCase (testCase) %} + {% import 'error_message_creator.twig' as errorMessageCreator %} + {% set testCaseErrorMessage = errorMessageCreator.exceptionMessage(testCase) %} + {{ testCaseErrorMessage }} + {% for testStep in testCase.stepsAsSortedSet %} + {% set stepErrorMessage = errorMessageCreator.exceptionMessage(testStep) %} + {% if (not isBlank(stepErrorMessage)) %} + {% if (not isBlank(testCaseErrorMessage)) %} + $whitespace$-$whitespace$ + {% endif %} + STEP "{{ testStep.id }}": {{ stepErrorMessage }} + {% endif %} + {% endfor %} +{% endmacro %} + +{# macro for creating the exception message of a test suite and all of its test cases. #} +{% macro exceptionMessageTestSuite (testSuite) %} + {% import 'error_message_creator.twig' as errorMessageCreator %} + {% set parentEntityErrorMessage = errorMessageCreator.exceptionMessage(testSuite) %} + {{ parentEntityErrorMessage }} + {% for testCase in testSuite.testCasesAsSortedSet %} + {% set caseErrorMessage = errorMessageCreator.exceptionMessageTestCase(testCase) %} + {% if (not isBlank(caseErrorMessage)) %} + {% if (not isBlank(parentEntityErrorMessage)) %} + $whitespace$--$whitespace$ + {% endif %} + CASE "{{ testCase.id }}": {{ caseErrorMessage }} + {% endif %} + {% endfor %} +{% endmacro %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/exception_screenshot.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/exception_screenshot.twig new file mode 100644 index 00000000..d2583695 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/exception_screenshot.twig @@ -0,0 +1,11 @@ +{% set testScreenshotDiv = extractScreenshot(testDataEntity) %} +{% if (testScreenshotDiv != null) %} +
+
+ Close X + + + +
+
+{% endif %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/main.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/main.twig new file mode 100644 index 00000000..d510a8c7 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/main.twig @@ -0,0 +1,19 @@ +{% spaceless %} +{% import 'error_message_creator.twig' as errorMessageCreator %} +type={{ gearman.serviceType }}$newline$ +host_name= + {% if (not empty(gearman.nagiosHost)) %} + {{ gearman.nagiosHost }} + {% else %} + {{ testsuite.host }} + {% endif %}$newline$ +start_time={{ convertToUnixTimestamp(testsuite.startDate) }}$newline$ +finish_time={{ convertToUnixTimestamp(testsuite.stopDate) }}$newline$ +return_code={{ testsuite.state.nagiosErrorCode }}$newline$ +service_description={{ gearman.nagiosServiceDescription }}$newline$ +output= + {% include 'short_summary.twig' %}\\n + {% include 'detailed_summary.twig' %} + {% include 'performance_data.twig' %} +$whitespace$[{{ gearman.nagiosCheckCommand }}] +{% endspaceless %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/performance_data.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/performance_data.twig new file mode 100644 index 00000000..a3ff1838 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/performance_data.twig @@ -0,0 +1,19 @@ +{# This template renders the performance data for the current test suite. #} +|suite__state={{getOutputState(testsuite.state).errorCode}};;;; +$whitespace$suite__warning={{ testsuite.warningTime }}s;;;;$whitespace$suite__critical={{ testsuite.criticalTime }}s;;;;$whitespace$suite_{{ testsuite.id }}={{getOutputDuration(testsuite)}};{{ testsuite.warningTime }};{{ testsuite.criticalTime }};; +{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% set testCaseIndex = format("%03d", loop.index) %} + $whitespace$c_{{ testCaseIndex }}__state={{getOutputState(testCase.state).errorCode}};;;; + $whitespace$c_{{ testCaseIndex }}__warning={{ testCase.warningTime }}s;;;; + $whitespace$c_{{ testCaseIndex }}__critical={{ testCase.criticalTime }}s;;;; + $whitespace$c_{{ testCaseIndex }}_{{ testCase.id }}={{getOutputDuration(testCase)}};{{ testCase.warningTime }};{{ testCase.criticalTime }};; + {% for testStep in testCase.steps %} + {% set testStepIndex = format("%03d", loop.index) %} + $whitespace$s_{{ testCaseIndex }}_{{ testStepIndex }}_{{testStep.name}}={{getOutputDuration(testStep)}}; + {% set testStepWarningTime = testStep.warningTime %} + {% if (testStepWarningTime > 0) %} + {{testStepWarningTime}} + {% else %} + {% endif %};;; + {% endfor %} +{% endfor %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/short_summary.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/short_summary.twig new file mode 100644 index 00000000..60336d73 --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/short_summary.twig @@ -0,0 +1,38 @@ +{# This template renders the short summary for the current test suite. #} +{{ getOutputState(testsuite.state).shortState }} Sakuli suite "{{testsuite.id}}"$whitespace$ +{% if (testsuite.state.error) %} + {% set exceptionMessages = errorMessageCreator.exceptionMessageTestSuite(testsuite) %} + ({{ format("%.2fs", testsuite.duration) }}) {{testsuite.state.nagiosStateDescription}}: {{abbreviate(exceptionMessages, 200, true)}} +{% else %} + {{testsuite.state.nagiosStateDescription}} + {% if (testsuite.state.ok) %} + $whitespace$({{ format("%.2fs", testsuite.duration) }}) + {% elseif (testsuite.state.name == 'WARNING_IN_SUITE') %} + $whitespace$({{ format("%.2fs", testsuite.duration) }}/warn at {{ testsuite.warningTime }}s) + {% elseif (testsuite.state.name == 'CRITICAL_IN_SUITE') %} + $whitespace$({{ format("%.2fs", testsuite.duration) }}/crit at {{ testsuite.criticalTime }}s) + {% elseif (testsuite.state.name == 'WARNING_IN_STEP') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.warningInStep) %} + {% for testStep in testCase.steps %} + {% if (testStep.state.warning) %} + , step "{{testStep.id}}" over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s) + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {% elseif (testsuite.state.name == 'WARNING_IN_CASE') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.warning) %} + , case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s) + {% endif %} + {% endfor %} + {% elseif (testsuite.state.name == 'CRITICAL_IN_CASE') %} + {% for testCaseId, testCase in testsuite.testCasesAsSortedSet %} + {% if (testCase.state.critical) %} + , case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s) + {% endif %} + {% endfor %} + {% endif %} + .$whitespace$(Last suite run: {% if (empty(testsuite.stopDate)) %}xx{% else %}{{ testsuite.stopDate|date("dd.MM.YY HH:mm:ss") }}{% endif %}) +{% endif %} diff --git a/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/step_information.twig b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/step_information.twig new file mode 100644 index 00000000..614b116c --- /dev/null +++ b/src/common/src/main/resources/org/sakuli/common/config/templates/gearman/step_information.twig @@ -0,0 +1,9 @@ +{% for testStep in testCase.stepsAsSortedSet %} + {% if (testStep.state.error) %} + , step "{{ testStep.name }}"$whitespace$ + EXCEPTION: {{ errorMessageCreator.exceptionMessage(testStep) }} + {% elseif (testStep.state.warning) %} + , step "{{ testStep.name }}"$whitespace$ + over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s) + {% endif %} +{% endfor %} diff --git a/src/core/src/main/java/org/sakuli/services/forwarder/gearman/GearmanTemplateOutputBuilder.java b/src/core/src/main/java/org/sakuli/services/forwarder/gearman/GearmanTemplateOutputBuilder.java new file mode 100644 index 00000000..0b085cfc --- /dev/null +++ b/src/core/src/main/java/org/sakuli/services/forwarder/gearman/GearmanTemplateOutputBuilder.java @@ -0,0 +1,47 @@ +/* + * Sakuli - Testing and Monitoring-Tool for Websites and common UIs. + * + * Copyright 2013 - 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.sakuli.services.forwarder.gearman; + +import org.jtwig.JtwigModel; +import org.sakuli.services.forwarder.AbstractTemplateOutputBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Georgi Todorov + */ +@ProfileGearman +@Component +public class GearmanTemplateOutputBuilder extends AbstractTemplateOutputBuilder { + + @Autowired + private GearmanProperties gearmanProperties; + + @Override + public String getConverterName() { + return "Gearman"; + } + + @Override + public JtwigModel createModel() { + return super.createModel() + .with("gearman", gearmanProperties); + } + +}