Skip to content
Snippets Groups Projects
Commit 0c333847 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Fixes task not executing bug in the alerts API

parent 654be5e0
No related branches found
No related tags found
No related merge requests found
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
......@@ -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())
......
......@@ -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):
"""
......
......@@ -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" (>=)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment