assertkapacitor_response.status_code==200,"Alert with ID {0} was not created - test file {1}.".format(alert_id,alerts_test_file)
kapacitor_response_json=kapacitor_response.json()
assert"link"inkapacitor_response_json,"Incorrect response from kapacitor for alert with ID {0} - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["status"]=="enabled","Alert with ID {0} was created but is disabled - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["executing"],"Alert with ID {0} was created and is enabled, but is not executing - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["type"]==alert_type,"Alert with ID {0} was created with the wrong type - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response.status_code==200,"Handler with ID {0} for topic with ID {1} doesn't exist - test file {2}".format(handler_id,topic_id,alerts_test_file)
kapacitor_response_json=kapacitor_response.json()
assertkapacitor_response_json["id"]==handler_id,"Incorrect ID of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
assertkapacitor_response_json["kind"]=="post","Incorrect kind of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
assertkapacitor_response_json["options"]["url"]==handler_url,"Incorrect url of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
assertkapacitor_response.status_code==200,"Alert with ID {0} was not created - test file {1}.".format(alert_id,alerts_test_file)
kapacitor_response_json=kapacitor_response.json()
assert"link"inkapacitor_response_json,"Incorrect response from kapacitor for alert with ID {0} - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["status"]=="enabled","Alert with ID {0} was created but is disabled - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["executing"],"Alert with ID {0} was created and is enabled, but is not executing - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response_json["type"]==alert_type,"Alert with ID {0} was created with the wrong type - test file {1}".format(alert_id,alerts_test_file)
assertkapacitor_response.status_code==200,"Handler with ID {0} for topic with ID {1} doesn't exist - test file {2}".format(handler_id,topic_id,alerts_test_file)
kapacitor_response_json=kapacitor_response.json()
assertkapacitor_response_json["id"]==handler_id,"Incorrect ID of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
assertkapacitor_response_json["kind"]=="post","Incorrect kind of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
assertkapacitor_response_json["options"]["url"]==handler_url,"Incorrect url of handler {0} in the Kapacitor response - test file {1}".format(handler_id,alerts_test_file)
The view for receiving and configuring alerts based on the TOSCA alerts specification document. This endpoint must also receive the TOSCA resources specification document for validation.
A PUT request will update any existing alerts and handlers that were registered before.
:return: a dictionary with a msg and optional keys for errors encountered while interacting with Kapacitor
:raises HTTPBadRequest: if the request doesn't contain a (YAML) file input referenced as alert-spec representing the TOSCA Alerts Specification
:raises HTTPBadRequest: if the request doesn't contain a (YAML) file input referenced as resource-spec representing the TOSCA Resources Specification
The view for receiving and configuring alerts based on the TOSCA alerts specification document. This endpoint must also receive the TOSCA resources specification document for validation.
A POST request will not try to update existing alerts and handlers and will simply return the error message from Kapacitor.
:return: a dictionary with a msg and optional keys for errors encountered while interacting with Kapacitor
:raises HTTPBadRequest: if the request doesn't contain a (YAML) file input referenced as alert-spec representing the TOSCA Alerts Specification
:raises HTTPBadRequest: if the request doesn't contain a (YAML) file input referenced as resource-spec representing the TOSCA Resources Specification
raiseHTTPBadRequest("Request to this API endpoint must include a (YAML) file input referenced as 'resource-spec' representing the TOSCA Resource Specification.")
# extract the required information from the resource specification and return an error if an exception was encountered
@@ -291,7 +311,7 @@ class AlertsConfigurationAPI(object):
iflen(missing_policy_triggers)>0:
raiseHTTPBadRequest("Couldn't match the following policy triggers from the alerts specification with triggers defined in the resource specification: {0}".format(missing_policy_triggers))
Configures the alerts task and alert handlers within Kapacitor.
...
...
@@ -302,6 +322,7 @@ class AlertsConfigurationAPI(object):
: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 patch_duplicates: (defaults to False) if set to True, any duplication errors will be handled by first deleting the existing resource and then creating it
:return: the list for tracking errors while interacting with Kapacitor tasks and the list for tracking errors while interacting with Kapacitor alert handlers
"""
...
...
@@ -378,24 +399,36 @@ class AlertsConfigurationAPI(object):
log.info(response_content,response.status_code)
# track all reported errors
ifresponse_content.get("error","")!="":
alert_tasks_errors.append({
"policy":policy_id,
"trigger":event_id,
"error":response_content.get("error")
})
ifresponse_content.get("error","")!="":# Kapacitor always returns an error key which is set to an empty string if successful
capture_error=True
# check if a Kapacitor task with the given identifier already exists, if so, delete it and create it again
Handles the configuration of HTTP Post alert handlers.
...
...
@@ -409,6 +442,7 @@ class AlertsConfigurationAPI(object):
:param event_id: name of trigger
:param http_handlers: list of handlers to subscribe
:param alert_handlers_errors: the list for tracking errors while interacting with Kapacitor alert handlers
:param patch_duplicates: (defaults to False) if set to True, any duplication errors will be handled by first deleting the existing resource and then creating it
raiseHTTPBadRequest("Request to this API endpoint must include a (YAML) file input referenced as 'resource-spec' representing the TOSCA Resource Specification.")
# extract the required information from the resource specification and return an error if an exception was encountered