Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flame
flame-clmc
Commits
d1a70994
Commit
d1a70994
authored
6 years ago
by
Nikolay Stanchev
Browse files
Options
Downloads
Patches
Plain Diff
Slight code refactoring
parent
4df8037b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/service/clmcservice/alertsapi/alerts_specification_schema.py
+18
-18
18 additions, 18 deletions
...vice/clmcservice/alertsapi/alerts_specification_schema.py
src/service/clmcservice/alertsapi/views.py
+4
-1
4 additions, 1 deletion
src/service/clmcservice/alertsapi/views.py
with
22 additions
and
19 deletions
src/service/clmcservice/alertsapi/alerts_specification_schema.py
+
18
−
18
View file @
d1a70994
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/service/clmcservice/alertsapi/views.py
+
4
−
1
View file @
d1a70994
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment