diff --git a/src/service/clmcservice/alertsapi/alerts_specification_schema.py b/src/service/clmcservice/alertsapi/alerts_specification_schema.py index 8eaa2d78cdae65a22b1796d2ba44d7e2c2e2d5a5..952d1c133f6ae84b386fe6fd336c25585e37f939 100644 --- a/src/service/clmcservice/alertsapi/alerts_specification_schema.py +++ b/src/service/clmcservice/alertsapi/alerts_specification_schema.py @@ -40,6 +40,9 @@ from schema import Schema, And, Or, Optional, SchemaError # * the condition section must specify threshold, granularity, aggregation_method, comparison_operator +SFEMC = "flame_sfemc" # describes the keyword used for the SFEMC alert handler + + # Influx QL functions defined in the documentation https://docs.influxdata.com/influxdb/v1.6/query_language/functions/ INFLUX_QL_FUNCTIONS = ( "count", "mean", "median", "mode", "sum", "first", "last", "max", "min" @@ -96,7 +99,7 @@ ALERTS_SPECIFICATION_SCHEMA = Schema({ "action": { "implementation": [ - And(str, lambda s: URL_REGEX.match(s) is not None) + Or(SFEMC, And(str, lambda s: URL_REGEX.match(s) is not None)) ] } } diff --git a/src/service/clmcservice/alertsapi/tests.py b/src/service/clmcservice/alertsapi/tests.py index c142707c06f7723b7597ea1d9a4898b95c12a4c7..535db2350d8d3e19f038d275170a512f91c213b5 100644 --- a/src/service/clmcservice/alertsapi/tests.py +++ b/src/service/clmcservice/alertsapi/tests.py @@ -25,7 +25,7 @@ # Python standard libs from os import listdir -from os.path import isfile, join, dirname +from os.path import isfile, join, dirname, splitext # PIP installed libs import pytest @@ -62,7 +62,7 @@ class TestAlertsConfigurationAPI(object): """ self.registry = testing.setUp() - self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092}) + self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092, "sfemc_fqdn": "sfemc.localhost"}) yield @@ -272,6 +272,7 @@ def extract_alert_spec_data(alert_spec): :return: a tuple containing sfc_id and sfc_instance_id along with a list and a dictionary of generated IDs (alert IDs (list), topic IDs linked to handler IDs (dict)) """ + version = splitext(alert_spec.name)[0].split("-")[-1] # take the ending number of the alert spec file yaml_alert_spec = load(alert_spec) adjust_tosca_definitions_import(yaml_alert_spec) tosca_tpl = ToscaTemplate(yaml_dict_tpl=yaml_alert_spec) @@ -296,6 +297,10 @@ def extract_alert_spec_data(alert_spec): alert_ids.append((alert_id, alert_type)) for handler_url in trigger.trigger_tpl["action"]["implementation"]: + + if handler_url == "flame_sfemc": + handler_url = "http://sfemc.localhost/{0}/{1}/{2}/{3}".format(sfc, sfc_instance, policy_id, "trigger_id_{0}".format(version)) + handler_id = "{0}\n{1}\n{2}\n{3}\n{4}".format(sfc, sfc_instance, policy_id, trigger_id, handler_url) handler_id = AlertsConfigurationAPI.get_hash(handler_id) topic_handlers[topic_id].append((handler_id, handler_url)) diff --git a/src/service/clmcservice/alertsapi/utilities.py b/src/service/clmcservice/alertsapi/utilities.py index 55470c1251509fda261d5c0f7238ded3cdf224f0..68dff5ee0b79351afc12bbd7c49e24a573665c17 100644 --- a/src/service/clmcservice/alertsapi/utilities.py +++ b/src/service/clmcservice/alertsapi/utilities.py @@ -57,18 +57,18 @@ def adjust_tosca_definitions_import(alert_spec): pass # nothing to replace if the import is not specified (either imports are missed, or no reference to the clmc tosca definitions file) -def get_resource_spec_topic_ids(resource_spec_reference): +def get_resource_spec_policy_triggers(resource_spec_reference): """ Tries to extract all event identifiers from a TOSCA resource specification :param resource_spec_reference: the resource specification file reference from the POST HTTP request - :return: sfc ID, sfc instance ID and the list of topic IDs + :return: sfc ID, sfc instance ID and the map of policy trigger IDs linked to the resource spec trigger id """ resource_spec = load(resource_spec_reference.file) - topic_ids = [] + policy_trigger_ids = {} sfc, sfc_i = resource_spec["metadata"]["sfc"], resource_spec["metadata"]["sfci"] policies = resource_spec["topology_template"]["policies"] @@ -79,25 +79,26 @@ def get_resource_spec_topic_ids(resource_spec_reference): if policy_object["type"] == "eu.ict-flame.policies.StateChange": triggers = policy_object["triggers"] - for trigger in triggers.values(): + for trigger_id in triggers: + trigger = triggers[trigger_id] event = trigger["condition"]["constraint"] source, event_id = event.split("::") if source.lower() == "clmc": # only take those event IDs that have clmc set as their source - topic_ids.append("{0}\n{1}".format(policy_id, event_id)) + policy_trigger_ids["{0}\n{1}".format(policy_id, event_id)] = trigger_id - return sfc, sfc_i, topic_ids + return sfc, sfc_i, policy_trigger_ids -def get_alert_spec_topic_ids(alerts_spec_tpl): +def get_alert_spec_policy_triggers(alerts_spec_tpl): """ Tries to extract all event identifiers from a TOSCA alerts specification :param alerts_spec_tpl: the alerts specification TOSCA template object - :return: the list of topic IDs + :return: the list of policy triggers """ - topic_ids = [] + policy_trigger_ids = [] for policy in alerts_spec_tpl.policies: policy_id = policy.name @@ -105,10 +106,10 @@ def get_alert_spec_topic_ids(alerts_spec_tpl): for trigger in policy.triggers: trigger_id = trigger.name - topic_id = "{0}\n{1}".format(policy_id, trigger_id) - topic_ids.append(topic_id) + policy_trigger_string = "{0}\n{1}".format(policy_id, trigger_id) + policy_trigger_ids.append(policy_trigger_string) - return topic_ids + return policy_trigger_ids def fill_http_post_handler_vars(handler_id, handler_url): diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 5c586e34375cdf4d4429eca755552535eda661ab..7919c022600e939885d7cd37e03f25815c3d81ca 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -34,8 +34,8 @@ from toscaparser.tosca_template import ToscaTemplate from requests import post # CLMC-service imports -from clmcservice.alertsapi.utilities import adjust_tosca_definitions_import, TICKScriptTemplateFiller, fill_http_post_handler_vars, get_resource_spec_topic_ids, get_alert_spec_topic_ids -from clmcservice.alertsapi.alerts_specification_schema import COMPARISON_OPERATORS, validate_clmc_alerts_specification +from clmcservice.alertsapi.utilities import adjust_tosca_definitions_import, TICKScriptTemplateFiller, fill_http_post_handler_vars, get_resource_spec_policy_triggers, get_alert_spec_policy_triggers +from clmcservice.alertsapi.alerts_specification_schema import COMPARISON_OPERATORS, SFEMC, validate_clmc_alerts_specification # initialise logger log = logging.getLogger('service_logger') @@ -101,7 +101,7 @@ class AlertsConfigurationAPI(object): alert_spec_reference = self.request.POST.get('alert-spec') resource_spec_reference = self.request.POST.get('resource-spec') try: - resource_spec_sfc, resource_spec_sfc_i, resource_spec_topic_ids = get_resource_spec_topic_ids(resource_spec_reference) + resource_spec_sfc, resource_spec_sfc_i, resource_spec_policy_triggers = get_resource_spec_policy_triggers(resource_spec_reference) except Exception as e: log.error("Couldn't extract resource specification event IDs due to error: {0}".format(e)) raise HTTPBadRequest("Couldn't extract resource specification event IDs - invalid TOSCA resource specification.") @@ -136,19 +136,20 @@ class AlertsConfigurationAPI(object): if not valid_alert_spec: raise HTTPBadRequest("Request alert specification file could not be validated as a CLMC TOSCA alerts specification document.") - alert_spec_topic_ids = get_alert_spec_topic_ids(tosca_tpl) + alert_spec_policy_triggers = get_alert_spec_policy_triggers(tosca_tpl) sfc, sfc_instance = tosca_tpl.tpl["metadata"]["sfc"], tosca_tpl.tpl["metadata"]["sfci"] # do validation between the two TOSCA documents - self._compare_alert_and_resource_spec(sfc, sfc_instance, alert_spec_topic_ids, resource_spec_sfc, resource_spec_sfc_i, resource_spec_topic_ids) + self._compare_alert_and_resource_spec(sfc, sfc_instance, alert_spec_policy_triggers, resource_spec_sfc, resource_spec_sfc_i, resource_spec_policy_triggers) + + db = sfc # database per service function chain, named after the service function chain ID - db = sfc # ASSUMPTION: database per service function chain, named after the service function chain ID # two lists to keep track of any errors while interacting with the Kapacitor HTTP API alert_tasks_errors = [] alert_handlers_errors = [] # iterate through every policy and extract all triggers of the given policy - self._config_kapacitor_alerts(tosca_tpl, sfc, sfc_instance, db, kapacitor_host, kapacitor_port, alert_tasks_errors, alert_handlers_errors) + self._config_kapacitor_alerts(tosca_tpl, sfc, sfc_instance, db, kapacitor_host, kapacitor_port, resource_spec_policy_triggers, alert_tasks_errors, alert_handlers_errors) return_msg = {"msg": "Alerts specification has been successfully validated and forwarded to Kapacitor", "service_function_chain_id": sfc, "service_function_chain_instance_id": sfc_instance} @@ -163,16 +164,16 @@ class AlertsConfigurationAPI(object): return return_msg - def _compare_alert_and_resource_spec(self, alert_spec_sfc, alert_spec_sfc_instance, alert_spec_topics, resource_spec_sfc, resource_spec_sfc_instance, resource_spec_topics): + def _compare_alert_and_resource_spec(self, alert_spec_sfc, alert_spec_sfc_instance, alert_spec_policy_triggers, resource_spec_sfc, resource_spec_sfc_instance, resource_spec_policy_triggers): """ Compares the extracted values from the resource spec against the values from the alerts spec - validation that they refer to the same things, :param alert_spec_sfc: sfc from alert spec :param alert_spec_sfc_instance: sfc instance from alert spec - :param alert_spec_topics: policy/trigger IDs from alert spec + :param alert_spec_policy_triggers: policy/trigger IDs from alert spec :param resource_spec_sfc: sfc from resource spec :param resource_spec_sfc_instance: sfc instance from resource spec - :param resource_spec_topics: policy/trigger IDs from resource spec + :param resource_spec_policy_triggers: policy/trigger IDs from resource spec :raises: HTTP Bad Request if the two specifications are inconsistent """ @@ -183,14 +184,14 @@ class AlertsConfigurationAPI(object): if alert_spec_sfc_instance != resource_spec_sfc_instance: raise HTTPBadRequest("Different service function chain instance ID used in the alert and resource specification documents: {0} != {1}".format(alert_spec_sfc_instance, resource_spec_sfc_instance)) - alert_spec_topics_set = set(alert_spec_topics) - missing_topic_ids = [topic_id for topic_id in resource_spec_topics if topic_id not in alert_spec_topics_set] + alert_spec_triggers_set = set(alert_spec_policy_triggers) + missing_policy_triggers = [policy_trigger_id for policy_trigger_id in resource_spec_policy_triggers if policy_trigger_id not in alert_spec_triggers_set] - if len(missing_topic_ids) > 0: - missing_topic_ids = [topic_id.replace("\n", " : ") for topic_id in missing_topic_ids] - raise HTTPBadRequest("Couldn't match the following policy triggers from the resource specification with triggers defined in the alerts specification: {0}".format(missing_topic_ids)) + if len(missing_policy_triggers) > 0: + missing_policy_triggers = [policy_trigger_id.replace("\n", " : ") for policy_trigger_id in missing_policy_triggers] + raise HTTPBadRequest("Couldn't match the following policy triggers from the resource specification with triggers defined in the alerts specification: {0}".format(missing_policy_triggers)) - def _config_kapacitor_alerts(self, tosca_tpl, sfc, sfc_instance, db, kapacitor_host, kapacitor_port, alert_tasks_errors, alert_handlers_errors): + def _config_kapacitor_alerts(self, tosca_tpl, sfc, sfc_instance, db, kapacitor_host, kapacitor_port, resource_spec_policy_triggers, alert_tasks_errors, alert_handlers_errors): """ Configures the alerts task and alert handlers within Kapacitor. @@ -200,6 +201,7 @@ class AlertsConfigurationAPI(object): :param db: Influx database ID :param kapacitor_host: default host is localhost (CLMC service running on the same machine as Kapacitor) :param kapacitor_port: default value to use is 9092 + :param resource_spec_policy_triggers: the extracted policy-trigger strings from the resource specification :param alert_tasks_errors: the list for tracking errors while interacting with Kapacitor tasks :param alert_handlers_errors: the list for tracking errors while interacting with Kapacitor alert handlers @@ -210,6 +212,7 @@ class AlertsConfigurationAPI(object): for trigger in policy.triggers: event_id = trigger.name policy_id = policy.name + resource_spec_trigger_id = resource_spec_policy_triggers["{0}\n{1}".format(policy_id, event_id)] event_type = trigger.trigger_tpl["event_type"] template_id = "{0}-template".format(event_type) @@ -283,9 +286,11 @@ class AlertsConfigurationAPI(object): http_handlers = trigger.trigger_tpl["action"]["implementation"] # subscribe all http handlers to the created topic - self._config_kapacitor_alert_handlers(kapacitor_host, kapacitor_port, sfc, sfc_instance, policy_id, topic_id, event_id, http_handlers, alert_handlers_errors) + self._config_kapacitor_alert_handlers(kapacitor_host, kapacitor_port, sfc, sfc_instance, policy_id, resource_spec_trigger_id, topic_id, event_id, + http_handlers, alert_handlers_errors) - def _config_kapacitor_alert_handlers(self, kapacitor_host, kapacitor_port, sfc, sfc_i, policy_id, topic_id, event_id, http_handlers, alert_handlers_errors): + def _config_kapacitor_alert_handlers(self, kapacitor_host, kapacitor_port, sfc, sfc_i, policy_id, trigger_id, + topic_id, event_id, http_handlers, alert_handlers_errors): """ Handles the configuration of HTTP Post alert handlers. @@ -294,6 +299,7 @@ class AlertsConfigurationAPI(object): :param sfc: service function chain identifier :param sfc_i: service function chain instance identifier :param policy_id: policy ID those triggers relate to + :param trigger_id: the resource specification trigger ID :param topic_id: topic ID built of sfc, sfc instance and event_id :param event_id: name of trigger :param http_handlers: list of handlers to subscribe @@ -302,6 +308,12 @@ class AlertsConfigurationAPI(object): kapacitor_api_handlers_url = "http://{0}:{1}/kapacitor/v1/alerts/topics/{2}/handlers".format(kapacitor_host, kapacitor_port, topic_id) for http_handler_url in http_handlers: + + # check for flame_sfemc entry, if found replace with sfemc FQDN + if http_handler_url == SFEMC: + sfemc_fqdn = self.request.registry.settings['sfemc_fqdn'] + http_handler_url = "http://{0}/{1}/{2}/{3}/{4}".format(sfemc_fqdn, sfc, sfc_i, policy_id, trigger_id) + handler_id = "{0}\n{1}\n{2}\n{3}\n{4}".format(sfc, sfc_i, policy_id, event_id, http_handler_url) handler_id = self.get_hash(handler_id) kapacitor_http_request_body = fill_http_post_handler_vars(handler_id, http_handler_url) diff --git a/src/service/development.ini b/src/service/development.ini index faf52a578c2e639d0a1cf872d0bb4792c8a80cd8..d459d200d5120137079fbb03b0f788c5eaf4c00a 100644 --- a/src/service/development.ini +++ b/src/service/development.ini @@ -14,14 +14,15 @@ pyramid.default_locale_name = en pyramid.includes = pyramid_debugtoolbar pyramid_exclog exclog.ignore = -# Configuration file path -configuration_file_path = /etc/flame/clmc/service.conf network_configuration_path = /vagrant/src/service/resources/GraphAPI/network_config.json # PostgreSQL connection url sqlalchemy.url = postgresql://clmc:clmc_service@localhost:5432/whoamidb +# SFEMC FQDN +sfemc_fqdn = sfemc.localhost + # Influx connection influx_host = localhost influx_port = 8086 diff --git a/src/service/production.ini b/src/service/production.ini index 1716af09d14e2121556b2133aec17a640516805e..94a00710ee9bcc923d25e0778e44f889ddf1a87f 100644 --- a/src/service/production.ini +++ b/src/service/production.ini @@ -14,14 +14,15 @@ pyramid.default_locale_name = en pyramid.includes = pyramid_exclog exclog.ignore = -# Configuration file path -configuration_file_path = /etc/flame/clmc/service.conf network_configuration_path = /vagrant/src/service/resources/GraphAPI/network_config.json # PostgreSQL connection url sqlalchemy.url = postgresql://clmc:clmc_service@localhost:5432/whoamidb +# SFEMC FQDN +sfemc_fqdn = sfemc.localhost + # Influx connection influx_host = localhost influx_port = 8086 diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-1.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-1.yaml index eb47f97eb1b17ed8b91831faf613f49035e05675..44e73ab464da406ee7b194c1ef6c931c69d222b3 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-1.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-1.yaml @@ -28,7 +28,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - requests_diff_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-10.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-10.yaml index 67793a750eee7654c944c7504acb7e1c1d33a9f5..1710bd0c7a5db3fa265e5b0e155025d85497433a 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-10.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-10.yaml @@ -28,7 +28,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - requests_diff_policy: type: eu.ict-flame.policies.StateChange @@ -49,7 +49,7 @@ topology_template: comparison_operator: lte action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - low_requests_policy: type: eu.ict-flame.policies.StateChange triggers: @@ -70,5 +70,5 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-11.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-11.yaml index 44837acabde8a7c6f5eef382c0c2a96037b1649f..97db7e99b852c7569394b2a6f27843a67be58ffb 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-11.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-11.yaml @@ -29,7 +29,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - requests_diff_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-12.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-12.yaml index 42d33a8b6fdc6c69b1bae50e02e70496ff9154a4..15ba25b7e2b7025ba9d129dd86f6de5bb8d0b0cb 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-12.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-12.yaml @@ -29,7 +29,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - requests_diff_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-2.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-2.yaml index 8a06dcf2c47a9c75d6d4dd5516ec9eba11e278b9..90e6f0be1b8b89f3aeaf851c094351c4fb86422d 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-2.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-2.yaml @@ -26,7 +26,7 @@ topology_template: flame_sfp: storage action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - low_requests_policy: type: eu.ict-flame.policies.StateChange triggers: diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-3.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-3.yaml index 4ed49c37360320e59bd4c881b627217a83ffdd85..7b61aaa00f0d040cd018d9e5be77b86f0a8c2296 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-3.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-3.yaml @@ -32,4 +32,5 @@ topology_template: comparison_operator: lt action: implementation: - - http://companyA.alert-handler.flame.eu/high-latency \ No newline at end of file + - http://companyA.alert-handler.flame.eu/high-latency + - flame_sfemc \ No newline at end of file diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-5.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-5.yaml index 735761389c4e4234c451efca3669303ce0108bed..ac2bc0050bfb9bb02c0c01c58dd6018d4493878f 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-5.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-5.yaml @@ -33,4 +33,4 @@ topology_template: action: implementation: - http://companyA.alert-handler.flame.eu/high-latency - - sfemc-webhook # should be a valid URL address \ No newline at end of file + - sfemc-webhook # should be a valid URL address or flame_sfemc for the SFEMC URL generation \ No newline at end of file diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-6.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-6.yaml index ac13f6fe6eca8ce4b9b80233eba7c65572952360..9142fe0fa7c64105522ac60549f646240a66c511 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-6.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-6.yaml @@ -29,7 +29,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-7.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-7.yaml index acb00ed3ac6ff2380c90d12424d6b386b3a45498..694bed6f1289bceed4aec0a04ce9c19ea2fdeec9 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-7.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-7.yaml @@ -28,7 +28,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: type: eu.ict-flame.policies.StateChange @@ -50,7 +50,7 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests - missing_measurement_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-8.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-8.yaml index a2c3009707631525caa656294f0cf2461ba2a0b9..ed8af914202e860f377686e0d650a5ea598f0c40 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-8.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-8.yaml @@ -36,7 +36,7 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests - requests_diff_policy: type: eu.ict-flame.policies.StateChange @@ -74,4 +74,4 @@ topology_template: comparison_operator: lte action: implementation: - - http://sfemc.flame.eu/notify \ No newline at end of file + - flame_sfemc \ No newline at end of file diff --git a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-9.yaml b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-9.yaml index 102c476d55265c73c22b46d889fa2a44d0e85930..4f6f6cb34092e38c16f0a16394fe1fd78add4e72 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-9.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/invalid/alerts_test_config-9.yaml @@ -26,7 +26,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: type: eu.ict-flame.policies.StateChange @@ -48,5 +48,5 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests diff --git a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml index 0114a3546eaadda10e54ab0e051f67eebe303b40..7d3a1be81c4a7785c19c5312b8294e6ac62c6113 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml @@ -28,7 +28,7 @@ topology_template: comparison_operator: eq action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: @@ -51,5 +51,5 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests \ No newline at end of file diff --git a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-2.yaml b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-2.yaml index 80ae206971d839272e4be8aff891e3a270caaf99..e618469fb4b186127456a3ce1e07922d13289f16 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-2.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-2.yaml @@ -31,7 +31,7 @@ topology_template: comparison_operator: lte action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - missing_measurement_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-3.yaml b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-3.yaml index ef1c542aa86bbcd08809b850c1bdfb28de2b693b..d8fa6e8012a2f91f43f0848d26d1f175b95a00e3 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-3.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-3.yaml @@ -28,7 +28,7 @@ topology_template: # comparison operator is optional, default value is >= or "gte" action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: type: eu.ict-flame.policies.StateChange @@ -48,5 +48,5 @@ topology_template: comparison_operator: lt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests diff --git a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-4.yaml b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-4.yaml index 13808f97ec173a5e1187d1a2551875b60e74208d..849f0379bc7c9ca299f7e464bfa80f4086c734e5 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-4.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-4.yaml @@ -46,7 +46,7 @@ topology_template: comparison_operator: lte action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests - missing_measurement_policy: type: eu.ict-flame.policies.StateChange @@ -65,4 +65,4 @@ topology_template: comparison_operator: gte # although events of type deadman do not use a comparison operator, the validator will not complain if one is given, it will simply ignore it action: implementation: - - http://sfemc.flame.eu/notify + - http://companyA.alert-handler.flame.eu/missing_measurements diff --git a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-5.yaml b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-5.yaml index f03c52382b2eccbc268617a975cf018bdc8d7c18..a341c6c25c6e6b0e41bb99753d4be27bd115ca39 100644 --- a/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-5.yaml +++ b/src/service/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-5.yaml @@ -28,7 +28,7 @@ topology_template: comparison_operator: gt action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: type: eu.ict-flame.policies.StateChange @@ -67,4 +67,4 @@ topology_template: comparison_operator: gte action: implementation: - - http://sfemc.flame.eu/notify + - flame_sfemc \ No newline at end of file diff --git a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-1.yaml b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-1.yaml index ceb65829204591b0d9eec14429014f3a325778c6..a17b840e608e6a4af4654ae464d9dc516452b7f4 100644 --- a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-1.yaml +++ b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-1.yaml @@ -75,7 +75,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_1: description: Check high latency on relationships condition: constraint: clmc::high_latency @@ -93,7 +93,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_1: description: Check high latency on relationships condition: constraint: clmc::low_requests diff --git a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-2.yaml b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-2.yaml index cda9496ad069c82eeebe6b187f24c887a5d77446..f2530f59e6e03ee793977ff63bb89266586de5ac 100644 --- a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-2.yaml +++ b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-2.yaml @@ -74,7 +74,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_2: description: Check high latency on relationships condition: constraint: clmc::decrease_in_requests @@ -90,7 +90,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_2: description: Check high latency on relationships condition: constraint: clmc::missing_storage_measurements diff --git a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-3.yaml b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-3.yaml index 6190b25551dfdc78cba6dcd8ab4353f3c8791a65..4ca88b33a0fd4186b85e2668e66accb8787d6d2b 100644 --- a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-3.yaml +++ b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-3.yaml @@ -75,7 +75,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_3: description: Check high latency on relationships condition: constraint: clmc::high_latency @@ -92,7 +92,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_3: description: Check high latency on relationships condition: constraint: clmc::low_requests diff --git a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-4.yaml b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-4.yaml index fe46de4d3bbb0e3d204a17de4d8da831d159f2b2..496e972b73e5fad39016c118e1824cacbac33399 100644 --- a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-4.yaml +++ b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-4.yaml @@ -75,7 +75,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_4: description: Check high latency on relationships condition: constraint: clmc::high_latency @@ -92,7 +92,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_4: description: Check high latency on relationships condition: constraint: clmc::low_requests @@ -109,7 +109,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_4: description: Check high latency on relationships condition: constraint: clmc::missing_storage_measurements diff --git a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-5.yaml b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-5.yaml index 82a200cc1fa9cc44e285459bbaa1303829c34c8f..0466063c748d5a5f8a470a2cf253cfb9c5c31460 100644 --- a/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-5.yaml +++ b/src/service/resources/tosca/test-data/resource-spec/resources_valid_test_config-5.yaml @@ -75,7 +75,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_5: description: Check high latency on relationships condition: constraint: clmc::high_latency @@ -92,7 +92,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_5: description: Check high latency on relationships condition: constraint: clmc::low_requests @@ -109,7 +109,7 @@ topology_template: properties: parent: service_paid triggers: - check_trigger: + trigger_id_5: description: Check high latency on relationships condition: constraint: clmc::increase_in_requests diff --git a/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml b/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml index 7bd6e44b5b14bb7431630a2549530ee62774d22f..773f8f947fea76b593c324f1fe0a039c723de594 100644 --- a/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml +++ b/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml @@ -27,6 +27,7 @@ topology_template: comparison_operator: gt action: implementation: + - flame_sfemc - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/high-latency - requests_diff_policy: diff --git a/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-4.yaml b/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-4.yaml index 76b8a0cd04ca08872f104bbb3e3aff9a505b0de6..0e546d5bbaad9c688e4a0c5cb4777976848be6e6 100644 --- a/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-4.yaml +++ b/src/service/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-4.yaml @@ -28,6 +28,7 @@ alerts: comparison_operator: gt action: implementation: + - flame_sfemc - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/high-latency - low_requests_policy: diff --git a/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml b/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml index 5924c13817555788959d792044500d7e0dfe00bb..0b9fb2cfc58f831d35a30ecc1350e4568f360901 100644 --- a/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml +++ b/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml @@ -28,6 +28,7 @@ topology_template: implementation: - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/high-latency + - flame_sfemc - low_requests_policy: type: eu.ict-flame.policies.StateChange triggers: diff --git a/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml b/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml index 64b19cbe37225546b4e5c73adfb83ee47c9d981d..92a392a8221f00ca2637dc4f1b9a3a86b20c730c 100644 --- a/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml +++ b/src/service/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml @@ -32,6 +32,7 @@ topology_template: comparison_operator: lt action: implementation: + - flame_sfemc - http://companyA.alert-handler.flame.eu/low-requests - requests_diff_policy: type: eu.ict-flame.policies.StateChange diff --git a/src/test/clmctest/alerts/alerts_test_config.yaml b/src/test/clmctest/alerts/alerts_test_config.yaml index f2fb3baa511fbcd7df520bb229bb900a7d76d0ee..fbaeda756f12ffc1d6d88400daefe78787a8f944 100644 --- a/src/test/clmctest/alerts/alerts_test_config.yaml +++ b/src/test/clmctest/alerts/alerts_test_config.yaml @@ -45,6 +45,7 @@ topology_template: comparison_operator: gte action: implementation: + - flame_sfemc - http://172.40.231.200:9999/ increase_in_active_requests: description: This event triggers when the cpu system usage is too high. @@ -61,6 +62,7 @@ topology_template: comparison_operator: gte action: implementation: + - flame_sfemc - http://172.40.231.200:9999/ - deadman_policy: type: eu.ict-flame.policies.StateChange @@ -80,4 +82,5 @@ topology_template: flame_server: DC1 action: implementation: + - flame_sfemc - http://172.40.231.200:9999/ \ No newline at end of file diff --git a/src/test/clmctest/alerts/test_alerts.py b/src/test/clmctest/alerts/test_alerts.py index a8679b37fcbeb9aa51fda7c7af2e6671b1bb6605..8f5ca464693428791094994753fb737d200e5b93 100644 --- a/src/test/clmctest/alerts/test_alerts.py +++ b/src/test/clmctest/alerts/test_alerts.py @@ -31,7 +31,6 @@ from schema import Schema, And, Or, Optional, SchemaError from clmctest.alerts.alert_handler_server import LOG_TEST_FOLDER_PATH -CLMC_SERVICE_PORT = 9080 NGINX_PORT = 80 @@ -94,7 +93,7 @@ class TestAlerts(object): :param rspec_config: fixture from conftest.py """ - global CLMC_SERVICE_PORT, NGINX_PORT, JSON_BODY_SCHEMA + global NGINX_PORT, JSON_BODY_SCHEMA clmc_service_host, nginx_host = None, None for host in rspec_config: @@ -113,11 +112,13 @@ class TestAlerts(object): with open(alerts_spec, 'rb') as alerts: with open(resources_spec, 'rb') as resources: files = {'alert-spec': alerts, 'resource-spec': resources} - response = post("http://{0}:{1}/alerts".format(clmc_service_host, CLMC_SERVICE_PORT), files=files) - assert response.status_code == 200 - clmc_service_response = response.json() - assert "triggers_specification_errors" not in clmc_service_response, "Unexpected error was returned for triggers specification" - assert "triggers_action_errors" not in clmc_service_response, "Unexpected error was returned for handlers specification" + response = post("http://{0}/clmc-service/alerts".format(clmc_service_host), files=files) + + assert response.status_code == 200 + clmc_service_response = response.json() + assert "triggers_specification_errors" not in clmc_service_response, "Unexpected error was returned for triggers specification" + assert "triggers_action_errors" not in clmc_service_response, "Unexpected error was returned for handlers specification" + print("Alert spec sent successfully") print("Wait 10 seconds for Kapacitor stream/batch tasks to start working...")