Commit 572e915d authored by Alain Takoudjou's avatar Alain Takoudjou

monitor: import checkpromise method from slapos.core now

parent 8b1572ea
......@@ -170,8 +170,6 @@ def run(args_list):
instance_dict = {}
global_state_dict['title'] = config.get('instance', 'name')
# XXX - hosting-title should be removed at some point in favour of specialise_title
global_state_dict['hosting-title'] = config.get('instance', 'root-name')
global_state_dict['specialise_title'] = config.get('instance', 'root-name')
global_state_dict['aggregate_reference'] = config.get('instance', 'computer')
if not global_state_dict['title']:
......
......@@ -104,6 +104,7 @@ class Monitoring(object):
self.config_folder = os.path.join(self.private_folder, 'config')
self.report_folder = self.private_folder
self.data_folder = os.path.join(self.private_folder, 'documents')
self.log_folder = os.path.join(self.private_folder, 'monitor-log')
self.promise_output_file = config.get("monitor", "promise-output-file")
self.bootstrap_is_ok = True
......@@ -387,7 +388,8 @@ class Monitoring(object):
'--history_folder "%s"' % self.data_folder,
'--instance_name "%s"' % self.title,
'--hosting_name "%s"' % self.root_title,
'--promise_type "report"']
'--promise_type "report"',
'--log_file "%s.report.log"' % os.path.join(self.log_folder, report_name)]
cron_line_list.append(' '.join(report_cmd_line))
......@@ -427,7 +429,9 @@ class Monitoring(object):
'--monitor_url "%s/private/"' % self.webdav_url, # XXX hardcoded,
'--history_folder "%s"' % self.public_folder,
'--instance_name "%s"' % self.title,
'--hosting_name "%s"' % self.root_title]
'--hosting_name "%s"' % self.root_title,
'--log_file "%s.log"' % os.path.join(self.log_folder,
self.title.replace(' ', '_'))]
registered_promise_list = os.listdir(self.promise_folder)
registered_promise_list.extend(os.listdir(self.monitor_promise_folder))
......@@ -501,6 +505,15 @@ class Monitoring(object):
file_list = ["%s/*.history.json" % self.public_folder]
self.generateLogrotateEntry('monitor.service.status', file_list, option_list)
# Rotate monitor log files
option_list = [
'daily', 'dateext', 'create', 'rotate 180',
'compress', 'delaycompress', 'notifempty',
'missingok'
]
file_list = ["%s/*.log" % self.log_folder]
self.generateLogrotateEntry('monitor.promise.log', file_list, option_list)
# Add cron entry for SlapOS Collect
command = "sleep $((1 + RANDOM % 60)) && " # Random sleep between 1 to 60 seconds
if self.nice_command:
......
This diff is collapsed.
......@@ -141,7 +141,7 @@ exit %(code)s
self.writePromise('promise_4')
parser = self.getPromiseParser()
promise_runner = RunPromise(parser)
promise_runner.runpromise()
promise_runner.runPromise()
self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'promise_1.status.json')))
self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'promise_2.status.json')))
......@@ -191,7 +191,7 @@ exit %(code)s
"process_resource": "monitor_resource_process.data",
"monitor_process_state": "monitor_resource.status"
},
"portal_type": "instance_state",
"portal_type": "Software Instance",
"state": {
"success": 2,
"error": 2
......@@ -207,9 +207,9 @@ exit %(code)s
"href": "https://monitor.test.com/share/private/"
}
},
"computer_reference": "COMP-1234",
"aggregate_reference": "COMP-1234",
"type": "global",
"hosting-title": "Monitor ROOT"
"specialise_title": "Monitor ROOT"
}"""
with open(os.path.join(self.private_dir, 'monitor.global.json')) as r:
......@@ -221,7 +221,7 @@ exit %(code)s
# all promises are OK now
self.writePromise('promise_2', success=True)
self.writePromise('promise_3', success=True)
promise_runner.runpromise()
promise_runner.runPromise()
globalstate.run([self.monitor_config_file, os.path.join(self.base_dir, 'instance.cfg')])
expected_result_dict = json.loads(expected_result)
......
This diff is collapsed.
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