diff --git a/src/service/MANIFEST.in b/src/service/MANIFEST.in index 250b3a92e4e0fa8a5608d979a649706671261c15..094e7aed183660531b0985ba68ef73a7ecdbfdb0 100644 --- a/src/service/MANIFEST.in +++ b/src/service/MANIFEST.in @@ -1,6 +1,6 @@ include VERSION -include .coveragerc +include *coveragerc include network_config.json include *.ini -include clmcservice/flame_clmc_alerts_definitions.yaml -recursive-include resources/TICKscript *_template.tick \ No newline at end of file +include clmcservice/static/* +include resources/TICKscript/*-template.tick \ No newline at end of file diff --git a/src/service/clmcservice/alertsapi/tests.py b/src/service/clmcservice/alertsapi/tests.py index e5bf014a559975464aaaab4e41d4121771fbd377..b04601f1d5f99cc837ae85358ad1519674964860 100644 --- a/src/service/clmcservice/alertsapi/tests.py +++ b/src/service/clmcservice/alertsapi/tests.py @@ -172,6 +172,7 @@ class TestAlertsConfigurationAPI(object): kapacitor_response_json = kapacitor_response.json() assert "link" in kapacitor_response_json, "Incorrect response from kapacitor for alert with ID {0} - test file {1}".format(alert_id, test_file_path) assert kapacitor_response_json["status"] == "enabled", "Alert with ID {0} was created but is disabled - test file {1}".format(alert_id, test_file_path) + assert kapacitor_response_json["executing"], "Alert with ID {0} was created and is enabled, but is not executing - test file {1}".format(alert_id, test_file_path) # check that all topic IDs were registered within Kapacitor topic_ids = list(topic_handlers.keys()) diff --git a/src/service/clmcservice/alertsapi/utilities.py b/src/service/clmcservice/alertsapi/utilities.py index f741e5a61c52d66aba94aaec02f7c27c0267ccc9..23a5dcc7d9c1c6be9259a1ef4f5f16d97e0eb685 100644 --- a/src/service/clmcservice/alertsapi/utilities.py +++ b/src/service/clmcservice/alertsapi/utilities.py @@ -30,7 +30,7 @@ from os.path import join from clmcservice import ROOT_DIR -CLMC_ALERTS_TOSCA_DEFINITIONS_REL_PATH = ["flame_clmc_alerts_definitions.yaml"] +CLMC_ALERTS_TOSCA_DEFINITIONS_REL_PATH = ["static", "flame_clmc_alerts_definitions.yaml"] CLMC_ALERTS_TOSCA_DEFINITIONS_ABS_PATH = join(ROOT_DIR, *CLMC_ALERTS_TOSCA_DEFINITIONS_REL_PATH) @@ -78,6 +78,22 @@ class TICKScriptTemplateFiller: A utility class used for TICK script templates filtering. """ + # a class variable used to hold the comparison operator used to build the where clause in TICK script templates, + # these differ if the where clause is built as a string opposed to when it is build as a lambda + _TEMPLATE_COMPARISON_OPERATOR = {"threshold": "=", "relative": "==", "deadman": "=="} + + @staticmethod + def get_comparison_operator(template_type): + """ + Get the correct comparison operator depending on the template type, if template type not recognized, return "==" + + :param template_type: one of the template types, that are created within kapacitor + + :return: the comparison operator that should be used in the template to build the where clause + """ + + return TICKScriptTemplateFiller._TEMPLATE_COMPARISON_OPERATOR.get(template_type, "==") + @staticmethod def fill_template_vars(template_type, **kwargs): """ diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 01c91b5f747fd40689a2af1b59c14615f52b320f..00be03f1ffba7f574375a81ef2ba3e8654d2f983 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -112,7 +112,13 @@ class AlertsConfigurationAPI(object): where_clause = None if "resource_type" in trigger.trigger_tpl["condition"]: tags = condition["resource_type"] - where_clause = " AND ".join(map(lambda tag_name: '"{0}"==\'{1}\''.format(tag_name, tags[tag_name]), tags)) + + # NOTE: if the template has its where clause defined as lambda (stream templates), then use "==" as comparison operator, + # else if the template's where clause is defined as a string (batch templates), then use "=" as comparison operator + comparison_operator = TICKScriptTemplateFiller.get_comparison_operator(event_type) # retrieves the correct comparison operator to use for building the where clause + + # build up the where clause from the tags dictionary + where_clause = " AND ".join(map(lambda tag_name: '"{0}"{1}\'{2}\''.format(tag_name, comparison_operator, tags[tag_name]), tags)) comparison_operator = COMPARISON_OPERATORS[condition.get("comparison_operator", "gte")] # if not specified, use "gte" (>=) diff --git a/src/service/clmcservice/flame_clmc_alerts_definitions.yaml b/src/service/clmcservice/static/flame_clmc_alerts_definitions.yaml similarity index 100% rename from src/service/clmcservice/flame_clmc_alerts_definitions.yaml rename to src/service/clmcservice/static/flame_clmc_alerts_definitions.yaml