Commit 841517de authored by Alain Takoudjou's avatar Alain Takoudjou

monitor: allow to specify a second promise folder

parent 03dff33c
Pipeline #2972 skipped
...@@ -92,6 +92,8 @@ class Monitoring(object): ...@@ -92,6 +92,8 @@ class Monitoring(object):
# Use this file to write knowledge0_cfg required by webrunner # Use this file to write knowledge0_cfg required by webrunner
self.parameter_cfg_file = config.get("monitor", "parameter-file-path").strip() self.parameter_cfg_file = config.get("monitor", "parameter-file-path").strip()
self.pid_file = config.get("monitor", "pid-file") self.pid_file = config.get("monitor", "pid-file")
self.monitor_promise_folder = softConfigGet(config, "monitor",
"monitor-promise-folder")
self.config_folder = os.path.join(self.private_folder, 'config') self.config_folder = os.path.join(self.private_folder, 'config')
self.report_folder = self.private_folder self.report_folder = self.private_folder
...@@ -409,6 +411,7 @@ class Monitoring(object): ...@@ -409,6 +411,7 @@ class Monitoring(object):
"monitor-promises.pid"), "monitor-promises.pid"),
'--output "%s"' % self.public_folder, '--output "%s"' % self.public_folder,
'--promise_folder "%s"' % self.promise_folder, '--promise_folder "%s"' % self.promise_folder,
'--monitor_promise_folder "%s"' % self.monitor_promise_folder,
'--monitor_url "%s/jio_private/"' % self.webdav_url, # XXX hardcoded, '--monitor_url "%s/jio_private/"' % self.webdav_url, # XXX hardcoded,
'--history_folder "%s"' % self.public_folder, '--history_folder "%s"' % self.public_folder,
'--instance_name "%s"' % self.title, '--instance_name "%s"' % self.title,
......
...@@ -28,6 +28,8 @@ def parseArguments(): ...@@ -28,6 +28,8 @@ def parseArguments():
help='Promise script to execute.') help='Promise script to execute.')
parser.add_argument('--promise_folder', parser.add_argument('--promise_folder',
help='Folder where to find promises to execute. Hide --promise_script and --promise_name') help='Folder where to find promises to execute. Hide --promise_script and --promise_name')
parser.add_argument('--monitor_promise_folder',
help='Folder where to find Custom monitor promises to execute.')
parser.add_argument('--promise_name', parser.add_argument('--promise_name',
help='Title to give to this promise.') help='Title to give to this promise.')
parser.add_argument('--promise_type', parser.add_argument('--promise_type',
...@@ -118,7 +120,10 @@ class RunPromise(object): ...@@ -118,7 +120,10 @@ class RunPromise(object):
with open(self.config.pid_path, 'w') as fpid: with open(self.config.pid_path, 'w') as fpid:
fpid.write(str(os.getpid())) fpid.write(str(os.getpid()))
status_list = self.checkPromises(self.config.promise_folder) promise_folder_list = [self.config.promise_folder]
if self.config.monitor_promise_folder:
promise_folder_list.append(self.config.monitor_promise_folder)
status_list = self.checkPromises(promise_folder_list)
promises_status_file = os.path.join(self.config.output, '_promise_status') promises_status_file = os.path.join(self.config.output, '_promise_status')
previous_state_dict = {} previous_state_dict = {}
new_state_dict = {} new_state_dict = {}
...@@ -254,19 +259,22 @@ class RunPromise(object): ...@@ -254,19 +259,22 @@ class RunPromise(object):
stderr=subprocess.PIPE stderr=subprocess.PIPE
) )
def checkPromises(self, promise_dir): def checkPromises(self, promise_dir_list):
""" """
Run all promises found into specified folder Run all promises found into specified folder
""" """
if not os.path.exists(promise_dir) or not os.path.isdir(promise_dir): promise_list = []
return [] for promise_dir in promise_dir_list:
if not os.path.exists(promise_dir) or not os.path.isdir(promise_dir):
continue
promise_list.extend([os.path.join(promise_dir, promise)
for promise in os.listdir(promise_dir)])
promise_result_list = [] promise_result_list = []
# Check whether every promise is kept # Check whether every promise is kept
for promise in os.listdir(promise_dir): for promise_script in promise_list:
promise_script = os.path.join(promise_dir, promise)
if not os.path.isfile(promise_script) or not os.access(promise_script, os.X_OK): if not os.path.isfile(promise_script) or not os.access(promise_script, os.X_OK):
# Not executable file # Not executable file
continue continue
...@@ -300,7 +308,10 @@ class RunPromise(object): ...@@ -300,7 +308,10 @@ class RunPromise(object):
result_dict["message"] = process_handler.communicate()[0] result_dict["message"] = process_handler.communicate()[0]
result_dict["status"] = "OK" result_dict["status"] = "OK"
else: else:
result_dict["message"] = process_handler.communicate()[1] stdout, stderr = process_handler.communicate()
result_dict["message"] = stderr
if not stderr:
result_dict["message"] = stdout
break break
else: else:
process_handler.terminate() process_handler.terminate()
......
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