From 6d1dd00d79dbfb5f2b745b7ee8ef75021a9972f8 Mon Sep 17 00:00:00 2001
From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk>
Date: Tue, 28 Aug 2018 11:34:37 +0100
Subject: [PATCH] Updates alerts specificaiton documentation

---
 docs/AlertsSpecification.md                    | 4 +++-
 src/service/clmcservice/alertsapi/utilities.py | 2 --
 src/service/clmcservice/alertsapi/views.py     | 9 +++++++--
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/docs/AlertsSpecification.md b/docs/AlertsSpecification.md
index c689e6b..6fdbb2f 100644
--- a/docs/AlertsSpecification.md
+++ b/docs/AlertsSpecification.md
@@ -235,8 +235,10 @@ format `<measurement>`.`<field>`. The only exception is when a **deadman** event
 the event_type is set to **threshold**.
 
 * **resource_type** - provides context for the given event - key-value pairs for the global tags of the CLMC Information Model.
+This includes any of the following: `"sfc", "sfci", "sf_package", "sf", "sf_endpoint", "host", "location"`. Keep in mind that
+filtering for **sfc** and **sfci** is automatically generated by extracting the metadata values from the alerts specification.
 
-* **comparison_operator** - the logical operator to use for comparison - lt (less than), gt ()greater than), lte (less than or equal to), etc.
+* **comparison_operator** - the logical operator to use for comparison - lt (less than), gt (greater than), lte (less than or equal to), etc.
 
 * **implementation** - a list of the URLs of alert handlers to which alert data is sent when the event condition is true.
 
diff --git a/src/service/clmcservice/alertsapi/utilities.py b/src/service/clmcservice/alertsapi/utilities.py
index 23a5dcc..32ac93a 100644
--- a/src/service/clmcservice/alertsapi/utilities.py
+++ b/src/service/clmcservice/alertsapi/utilities.py
@@ -108,8 +108,6 @@ class TICKScriptTemplateFiller:
         fill_function_name = "_fill_{0}_template_vars".format(template_type)
         fill_function = getattr(TICKScriptTemplateFiller, fill_function_name)  # python functions are first-class objects !
 
-        # TODO is this the best way to avoid long if-else chains ?
-
         return fill_function(**kwargs)
 
     @staticmethod
diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py
index 1ce908a..db276f0 100644
--- a/src/service/clmcservice/alertsapi/views.py
+++ b/src/service/clmcservice/alertsapi/views.py
@@ -96,9 +96,11 @@ class AlertsConfigurationAPI(object):
         sfc, sfc_instance = tosca_tpl.tpl["metadata"]["sfc"], tosca_tpl.tpl["metadata"]["sfci"]
         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
         for policy in tosca_tpl.policies:
             for trigger in policy.triggers:
                 event_id = trigger.name
@@ -115,6 +117,9 @@ class AlertsConfigurationAPI(object):
                 where_clause = None
                 if "resource_type" in trigger.trigger_tpl["condition"]:
                     tags = condition["resource_type"]
+                    # make sure alert tasks are executing with queries for the given sfc and sfc instance
+                    # tags["sfc"] = sfc TODO uncomment this line when we updated telegraf to name db after sfc
+                    # tags["sfci"] = sfc_instance TODO uncomment this line when telegraf global tags are updated, currently we have sfc_i instead of sfci
 
                     # 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
@@ -130,7 +135,7 @@ class AlertsConfigurationAPI(object):
                 alert_id = "{0}.{1}.{2}.{3}".format(sfc, sfc_instance, policy.name, event_id)
 
                 # built up the template vars dictionary depending on the event type (threshold, relative, etc.)
-                # all extracted properties from the trigger are passed, the TICKScriptTemplateFiller entry point then forwards those to the appropriate function
+                # all extracted properties from the trigger are passed, the TICKScriptTemplateFiller entry point then forwards those to the appropriate function for template filling
                 template_vars = TICKScriptTemplateFiller.fill_template_vars(event_type, db=db, measurement=measurement, field=field, influx_function=influx_function,
                                                                             critical_value=critical_value, comparison_operator=comparison_operator, alert_period=alert_period,
                                                                             topic_id=topic_id, where_clause=where_clause)
@@ -159,7 +164,7 @@ class AlertsConfigurationAPI(object):
                         "error": response_content.get("error")
                     })
 
-                # exttranc http handlers
+                # extract http handlers
                 http_handlers = trigger.trigger_tpl["action"]["implementation"]
 
                 # subscribe all http handlers to the created topic
-- 
GitLab