diff --git a/src/service/clmcservice/alertsapi/alerts_specification_schema.py b/src/service/clmcservice/alertsapi/alerts_specification_schema.py index 6f6b1e03b947bfa0f360bc3f3e8cee14decc07f2..6faa5175bedd129beeca506b0289e96c5c9e6e63 100644 --- a/src/service/clmcservice/alertsapi/alerts_specification_schema.py +++ b/src/service/clmcservice/alertsapi/alerts_specification_schema.py @@ -23,22 +23,22 @@ """ # Python standard libs -from re import compile, IGNORECASE +import re # PIP installed libs from schema import Schema, And, Or, Optional, SchemaError -""" -This module defines the schema objects for the TOSCA Alert Specification: - - * flame_clmc_alerts_definitions.yaml must be the only import - * metadata section must be present (with key-value pairs for sfc and sfci) - * policies section must be present (under the topology_template node) - * each policy must be associated with a triggers node (containing at least 1 trigger) - * each policy is of type eu.ict-flame.policies.StateChange or eu.ict-flame.policies.Alert - * each trigger must specify event_type, metric, condition, and at least one handler in action/implementation - * the condition section must specify threshold, granularity, aggregation_method, comparison_operator -""" + +# This module defines the schema objects for the TOSCA Alert Specification: +# +# * flame_clmc_alerts_definitions.yaml must be the only import +# * metadata section must be present (with key-value pairs for sfc and sfci) +# * policies section must be present (under the topology_template node) +# * each policy must be associated with a triggers node (containing at least 1 trigger) +# * each policy is of type eu.ict-flame.policies.StateChange or eu.ict-flame.policies.Alert +# * each trigger must specify event_type, metric, condition, and at least one handler in action/implementation +# * the condition section must specify threshold, granularity, aggregation_method, comparison_operator + # Influx QL functions defined in the documentation https://docs.influxdata.com/influxdb/v1.6/query_language/functions/ INFLUX_QL_FUNCTIONS = ( @@ -52,14 +52,14 @@ TICK_SCRIPT_TEMPLATES = ("threshold", "relative", "deadman") COMPARISON_OPERATORS = {"lt": "<", "gt": ">", "lte": "<=", "gte": ">=", "eq": "=", "neq": "<>"} # Regular expression for validating http handlers -URL_REGEX = compile( +URL_REGEX = re.compile( r'^https?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain, e.g. example.domain.com r'localhost|' # or localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # or IP address (IPv4 format) r'(?::\d{2,5})?' # optional port number r'(?:[/?#][^\s]*)?$', # URL path or query parameters - IGNORECASE) + re.IGNORECASE) # Global tags allowed to be used for filtering in the trigger condition CLMC_INFORMATION_MODEL_GLOBAL_TAGS = {"flame_sfc", "flame_sfci", "flame_sfp", "flame_sf", "flame_sfe", "flame_server", "flame_location"} @@ -120,10 +120,10 @@ def validate_clmc_alerts_specification(tosca_yaml_tpl, include_error=False): try: ALERTS_SPECIFICATION_SCHEMA.validate(tosca_yaml_tpl) valid, err = True, None - except SchemaError as e: - valid, err = False, e + except SchemaError as schema_error: + valid, err = False, schema_error if include_error: return valid, err - else: - return valid + + return valid diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 34490678d30774d4fee6ea445257d59113b7633c..44183f1b40c300daaaea6bbf744675d9edd6f55e 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -36,7 +36,7 @@ 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.alerts_specification_schema import COMPARISON_OPERATORS, validate_clmc_alerts_specification # initialise logger log = logging.getLogger('service_logger') @@ -59,6 +59,9 @@ class AlertsConfigurationAPI(object): @view_config(route_name='alerts_configuration', request_method='GET') def get_alerts_hash(self): + """ + Retrieves hash value for alerts task, topic and handlers based on sfc, sfci, policy and trigger IDs + """ for param in ("sfc", "sfci", "policy", "trigger"): if param not in self.request.params: