From edfe2523b84f89e81c9643506337a08672d9772a Mon Sep 17 00:00:00 2001
From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk>
Date: Thu, 4 Oct 2018 16:58:15 +0100
Subject: [PATCH] Updates alerts api to generate sfemc url, updates tests as
 well

---
 .../alertsapi/alerts_specification_schema.py  |  5 +-
 src/service/clmcservice/alertsapi/tests.py    |  9 +++-
 .../clmcservice/alertsapi/utilities.py        | 25 +++++-----
 src/service/clmcservice/alertsapi/views.py    | 48 ++++++++++++-------
 src/service/development.ini                   |  5 +-
 src/service/production.ini                    |  5 +-
 .../invalid/alerts_test_config-1.yaml         |  2 +-
 .../invalid/alerts_test_config-10.yaml        |  6 +--
 .../invalid/alerts_test_config-11.yaml        |  2 +-
 .../invalid/alerts_test_config-12.yaml        |  2 +-
 .../invalid/alerts_test_config-2.yaml         |  2 +-
 .../invalid/alerts_test_config-3.yaml         |  3 +-
 .../invalid/alerts_test_config-5.yaml         |  2 +-
 .../invalid/alerts_test_config-6.yaml         |  2 +-
 .../invalid/alerts_test_config-7.yaml         |  4 +-
 .../invalid/alerts_test_config-8.yaml         |  4 +-
 .../invalid/alerts_test_config-9.yaml         |  4 +-
 .../valid/alerts_test_config-1.yaml           |  4 +-
 .../valid/alerts_test_config-2.yaml           |  2 +-
 .../valid/alerts_test_config-3.yaml           |  4 +-
 .../valid/alerts_test_config-4.yaml           |  4 +-
 .../valid/alerts_test_config-5.yaml           |  4 +-
 .../resources_valid_test_config-1.yaml        |  4 +-
 .../resources_valid_test_config-2.yaml        |  4 +-
 .../resources_valid_test_config-3.yaml        |  4 +-
 .../resources_valid_test_config-4.yaml        |  6 +--
 .../resources_valid_test_config-5.yaml        |  6 +--
 .../invalid/alerts_test_config-2.yaml         |  1 +
 .../invalid/alerts_test_config-4.yaml         |  1 +
 .../valid/alerts_test_config-2.yaml           |  1 +
 .../valid/alerts_test_config-4.yaml           |  1 +
 .../clmctest/alerts/alerts_test_config.yaml   |  3 ++
 src/test/clmctest/alerts/test_alerts.py       | 15 +++---
 33 files changed, 113 insertions(+), 81 deletions(-)

diff --git a/src/service/clmcservice/alertsapi/alerts_specification_schema.py b/src/service/clmcservice/alertsapi/alerts_specification_schema.py
index 8eaa2d7..952d1c1 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 c142707..535db23 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 55470c1..68dff5e 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 5c586e3..7919c02 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 faf52a5..d459d20 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 1716af0..94a0071 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 eb47f97..44e73ab 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 67793a7..1710bd0 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 44837ac..97db7e9 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 42d33a8..15ba25b 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 8a06dcf..90e6f0b 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 4ed49c3..7b61aaa 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 7357613..ac2bc00 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 ac13f6f..9142fe0 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 acb00ed..694bed6 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 a2c3009..ed8af91 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 102c476..4f6f6cb 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 0114a35..7d3a1be 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 80ae206..e618469 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 ef1c542..d8fa6e8 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 13808f9..849f037 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 f03c523..a341c6c 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 ceb6582..a17b840 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 cda9496..f2530f5 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 6190b25..4ca88b3 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 fe46de4..496e972 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 82a200c..0466063 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 7bd6e44..773f8f9 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 76b8a0c..0e546d5 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 5924c13..0b9fb2c 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 64b19cb..92a392a 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 f2fb3ba..fbaeda7 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 a8679b3..8f5ca46 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...")
-- 
GitLab