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 ...@@ -56,7 +56,7 @@ md5sum = 2db5c08c7e8658981b4b1e3f27fd5967
[monitor-bin] [monitor-bin]
<= monitor-download-base <= monitor-download-base
filename = monitor.py.in filename = monitor.py.in
md5sum = 331e8579c390aba5c5f4a4e7820b4c03 md5sum = cc2f9c6b138ce11af9999ed58cd46799
[monitor-web-index-html] [monitor-web-index-html]
<= monitor-download-base <= monitor-download-base
......
...@@ -22,16 +22,32 @@ def main(): ...@@ -22,16 +22,32 @@ def main():
for filename in os.listdir(configuration_folder_location) for filename in os.listdir(configuration_folder_location)
if os.path.isfile(os.path.join(configuration_folder_location, filename)) 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): for filename in os.listdir(promise_folder):
path = os.path.join(promise_folder, filename) promise_path = os.path.join(promise_folder, filename)
if os.path.isfile(path): if os.path.isfile(promise_path) and os.access(promise_path, os.X_OK):
c = ConfigParser.ConfigParser() service_name = filename
c.add_section("service") service_config = service_config_dict.get(service_name)
c.set("service", "name", filename) if service_name not in service_config_dict or softConfigGet(service_config, "service", "promise-path"):
c.set("service", "frequency", "* * * * *") # every minutes service_name = newServiceName(service_name, service_config_dict)
c.set("service", "promise-path", os.path.join(path)) service_config = ConfigParser.ConfigParser()
service_config_list.append(c) 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 # generate monitor.json
monitor_dict = {} monitor_dict = {}
tmp = softConfigGet(config, "monitor", "title") tmp = softConfigGet(config, "monitor", "title")
...@@ -109,6 +125,14 @@ def createSymlinksFromConfig(destination_folder_config_tuple, source_list_config ...@@ -109,6 +125,14 @@ def createSymlinksFromConfig(destination_folder_config_tuple, source_list_config
if e.errno != os.errno.EEXIST: if e.errno != os.errno.EEXIST:
raise 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): def mkdirAll(path):
try: try:
os.makedirs(path) 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