diff --git a/src/service/clmcservice/__init__.py b/src/service/clmcservice/__init__.py index 94354234b6be0fdafa6272be365cc1d0ac0955a7..b34c2c9fdbef516b960c22745dcf33360935a34b 100644 --- a/src/service/clmcservice/__init__.py +++ b/src/service/clmcservice/__init__.py @@ -48,13 +48,14 @@ def main(global_config, **settings): DBSession.configure(bind=engine) # bind the engine to a DB session Base.metadata.bind = engine # bind the engine to the Base class metadata - # validate and use (if valid) the configuration file + # validate and use (if valid) the configuration file for the aggregator conf_file_path = settings[CONF_FILE_ATTRIBUTE] conf = validate_conf_file(conf_file_path) # if None returned here, service is in unconfigured state settings[CONF_OBJECT] = conf - settings[MALFORMED_FLAG] = False + settings['influx_port'] = int(settings['influx_port']) # the influx port setting must be converted to integer instead of a string + settings['kapacitor_port'] = int(settings['kapacitor_port']) # the kapacitor port setting must be converted to integer instead of a string network_config_file_path = settings["network_configuration_path"] with open(network_config_file_path) as f: diff --git a/src/service/clmcservice/alertsapi/tests.py b/src/service/clmcservice/alertsapi/tests.py index 9707a707dcce678deddd48c69a1d33cac1e2bf58..556120f1bc8850a49bb480260aa64ce928199a8c 100644 --- a/src/service/clmcservice/alertsapi/tests.py +++ b/src/service/clmcservice/alertsapi/tests.py @@ -62,6 +62,7 @@ class TestAlertsConfigurationAPI(object): """ self.registry = testing.setUp() + self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092}) yield diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 5f9e24ef84890f439e448fa39ea22df3718d0e04..01c91b5f747fd40689a2af1b59c14615f52b320f 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -64,6 +64,8 @@ class AlertsConfigurationAPI(object): :raises HTTPBadRequest: if the request doesn't contain a (YAML) file input referenced as alert-spec representing the TOSCA Alerts Specification """ + kapacitor_host, kapacitor_port = self.request.registry.settings['kapacitor_host'], self.request.registry.settings['kapacitor_port'] + if not hasattr(self.request.POST.get('alert-spec'), "file") or not hasattr(self.request.POST.get('alert-spec'), "filename"): raise HTTPBadRequest("Request to this API endpoint must include a (YAML) file input referenced as 'alert-spec' representing the TOSCA Alerts Specification.") @@ -125,7 +127,7 @@ class AlertsConfigurationAPI(object): topic_id=topic_id, where_clause=where_clause) # create and activate alert task through the kapacitor HTTP API - kapacitor_api_tasks_url = "http://localhost:9092/kapacitor/v1/tasks" + kapacitor_api_tasks_url = "http://{0}:{1}/kapacitor/v1/tasks".format(kapacitor_host, kapacitor_port) kapacitor_http_request_body = { "id": alert_id, "template-id": template_id, @@ -144,7 +146,7 @@ class AlertsConfigurationAPI(object): http_handlers = trigger.trigger_tpl["action"]["implementation"] # subscribe all http handlers to the created topic - kapacitor_api_handlers_url = "http://localhost:9092/kapacitor/v1/alerts/topics/{0}/handlers".format(topic_id) + kapacitor_api_handlers_url = "http://{0}:{1}/kapacitor/v1/alerts/topics/{2}/handlers".format(kapacitor_host, kapacitor_port, topic_id) for http_handler_url in http_handlers: http_handler_host = urlparse(http_handler_url).hostname handler_id = "{0}.{1}.{2}".format(policy.name, event_id, http_handler_host) diff --git a/src/service/development.ini b/src/service/development.ini index 3d14f33fa23e32ac0ec50d839efcdcf4d080704f..07fccc62d52a1e55d428e05948ecf9f5e7a3fe6b 100644 --- a/src/service/development.ini +++ b/src/service/development.ini @@ -26,6 +26,10 @@ sqlalchemy.url = postgresql://clmc:clmc_service@localhost:5432/whoamidb influx_host = localhost influx_port = 8086 +# Kapacitor connection +kapacitor_host = localhost +kapacitor_port = 9092 + # Neo4j connection neo4j_host = localhost neo4j_password = admin diff --git a/src/service/production.ini b/src/service/production.ini index 33c7ca6cb032aceffb2ac12e21af9416ab1624d2..00aa006bbf7cef627c93f29485a41290e0ff968b 100644 --- a/src/service/production.ini +++ b/src/service/production.ini @@ -26,6 +26,10 @@ sqlalchemy.url = postgresql://clmc:clmc_service@localhost:5432/whoamidb influx_host = localhost influx_port = 8086 +# Kapacitor connection +kapacitor_host = localhost +kapacitor_port = 9092 + # Neo4j connection neo4j_host = localhost neo4j_password = admin