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

Slight code refactoring

parent 4df8037b
Branches
Tags
No related merge requests found
...@@ -23,22 +23,22 @@ ...@@ -23,22 +23,22 @@
""" """
# Python standard libs # Python standard libs
from re import compile, IGNORECASE import re
# PIP installed libs # PIP installed libs
from schema import Schema, And, Or, Optional, SchemaError from schema import Schema, And, Or, Optional, SchemaError
"""
This module defines the schema objects for the TOSCA Alert Specification: # This module defines the schema objects for the TOSCA Alert Specification:
#
* flame_clmc_alerts_definitions.yaml must be the only import # * flame_clmc_alerts_definitions.yaml must be the only import
* metadata section must be present (with key-value pairs for sfc and sfci) # * metadata section must be present (with key-value pairs for sfc and sfci)
* policies section must be present (under the topology_template node) # * 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 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 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 # * 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 # * 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 defined in the documentation https://docs.influxdata.com/influxdb/v1.6/query_language/functions/
INFLUX_QL_FUNCTIONS = ( INFLUX_QL_FUNCTIONS = (
...@@ -52,14 +52,14 @@ TICK_SCRIPT_TEMPLATES = ("threshold", "relative", "deadman") ...@@ -52,14 +52,14 @@ TICK_SCRIPT_TEMPLATES = ("threshold", "relative", "deadman")
COMPARISON_OPERATORS = {"lt": "<", "gt": ">", "lte": "<=", "gte": ">=", "eq": "=", "neq": "<>"} COMPARISON_OPERATORS = {"lt": "<", "gt": ">", "lte": "<=", "gte": ">=", "eq": "=", "neq": "<>"}
# Regular expression for validating http handlers # Regular expression for validating http handlers
URL_REGEX = compile( URL_REGEX = re.compile(
r'^https?://' # http:// or https:// 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'(?:(?:[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'localhost|' # or localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # or IP address (IPv4 format) 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'(?::\d{2,5})?' # optional port number
r'(?:[/?#][^\s]*)?$', # URL path or query parameters r'(?:[/?#][^\s]*)?$', # URL path or query parameters
IGNORECASE) re.IGNORECASE)
# Global tags allowed to be used for filtering in the trigger condition # 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"} 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): ...@@ -120,10 +120,10 @@ def validate_clmc_alerts_specification(tosca_yaml_tpl, include_error=False):
try: try:
ALERTS_SPECIFICATION_SCHEMA.validate(tosca_yaml_tpl) ALERTS_SPECIFICATION_SCHEMA.validate(tosca_yaml_tpl)
valid, err = True, None valid, err = True, None
except SchemaError as e: except SchemaError as schema_error:
valid, err = False, e valid, err = False, schema_error
if include_error: if include_error:
return valid, err return valid, err
else:
return valid return valid
...@@ -59,6 +59,9 @@ class AlertsConfigurationAPI(object): ...@@ -59,6 +59,9 @@ class AlertsConfigurationAPI(object):
@view_config(route_name='alerts_configuration', request_method='GET') @view_config(route_name='alerts_configuration', request_method='GET')
def get_alerts_hash(self): 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"): for param in ("sfc", "sfci", "policy", "trigger"):
if param not in self.request.params: if param not in self.request.params:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment