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

Updates clmcservice to read kapacitor host and port from the configuration files

parent f2cf0328
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -62,6 +62,7 @@ class TestAlertsConfigurationAPI(object):
"""
self.registry = testing.setUp()
self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092})
yield
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment