Commit 693c0dc4 authored by Tristan Cavelier's avatar Tristan Cavelier

monitor: handle relation between promise and configuration

parent 381c6736
......@@ -56,7 +56,7 @@ md5sum = 2db5c08c7e8658981b4b1e3f27fd5967
[monitor-bin]
<= monitor-download-base
filename = monitor.py.in
md5sum = 331e8579c390aba5c5f4a4e7820b4c03
md5sum = cc2f9c6b138ce11af9999ed58cd46799
[monitor-web-index-html]
<= monitor-download-base
......
......@@ -22,16 +22,32 @@ def main():
for filename in os.listdir(configuration_folder_location)
if os.path.isfile(os.path.join(configuration_folder_location, filename))
]
# search for promises in promise folder and convert into configuration
# fill dict of service
service_config_dict = {}
for service_config in service_config_list:
service_config_dict[service_config.get("service", "name")] = service_config
# search for promises and make relation between service_config_list
for filename in os.listdir(promise_folder):
path = os.path.join(promise_folder, filename)
if os.path.isfile(path):
c = ConfigParser.ConfigParser()
c.add_section("service")
c.set("service", "name", filename)
c.set("service", "frequency", "* * * * *") # every minutes
c.set("service", "promise-path", os.path.join(path))
service_config_list.append(c)
promise_path = os.path.join(promise_folder, filename)
if os.path.isfile(promise_path) and os.access(promise_path, os.X_OK):
service_name = filename
service_config = service_config_dict.get(service_name)
if service_name not in service_config_dict or softConfigGet(service_config, "service", "promise-path"):
service_name = newServiceName(service_name, service_config_dict)
service_config = ConfigParser.ConfigParser()
service_config_list.append(service_config)
service_config_dict[service_name] = service_config
service_config.add_section("service")
service_config.set("service", "name", service_name)
service_config.set("service", "frequency", "* * * * *") # every minutes
service_config.set("service", "promise-path", promise_path)
# filter services without promise-path
service_config_dict = None
service_config_list = [
service_config
for service_config in service_config_list
if softConfigGet(service_config, "service", "promise-path")
]
# generate monitor.json
monitor_dict = {}
tmp = softConfigGet(config, "monitor", "title")
......@@ -109,6 +125,14 @@ def createSymlinksFromConfig(destination_folder_config_tuple, source_list_config
if e.errno != os.errno.EEXIST:
raise
def newServiceName(name, name_dict):
part = name
count = 1
while name in name_dict:
name = part + "_" + str(count)
count += 1
return name
def mkdirAll(path):
try:
os.makedirs(path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment