Commit accdc8ea authored by Alain Takoudjou's avatar Alain Takoudjou

monitor: allow to set periodicity for custom report scripts

parent 83d87101
......@@ -100,7 +100,7 @@ recipe = slapos.recipe.template:jinja2
filename = template-monitor.cfg
template = ${:_profile_base_location_}/instance-monitor.cfg.jinja2.in
rendered = ${buildout:directory}/template-monitor.cfg
md5sum = 354da434447697b8b4f503a62599cf32
md5sum = 7ae453794e320d3b512ec037efc5fc1f
context =
key apache_location apache:location
key gzip_location gzip:location
......@@ -131,7 +131,7 @@ depends =
[monitor2-bin]
<= monitor-template-script
filename = monitor.py
md5sum = 3166f5d110fda63aade1ca486dfb7996
md5sum = 280412f9024030c8cae343c2b07e5130
[run-promise-py]
recipe = slapos.recipe.template:jinja2
......
......@@ -364,8 +364,8 @@ mode = 0644
context = section parameter_dict monitor-password-promise-conf-parameter
[publish]
<= monitor-base
monitor-base-url = ${monitor-conf-parameters:base-url}
# XXX depends on monitor-base section
monitor-base-url = ${monitor-base:base-url}
monitor-url = ${:monitor-base-url}/public/feeds
monitor-user = ${monitor-instance-parameter:username}
monitor-password = ${monitor-instance-parameter:password}
......@@ -415,6 +415,7 @@ check-secure = 1
recipe = plone.recipe.command
command = true
update-command =
base-url = ${monitor-conf-parameters:base-url}
depends =
${monitor-globalstate-cron-entry:name}
${monitor-configurator-cron-entry:name}
......
......@@ -245,6 +245,28 @@ class Monitoring(object):
print "Bad Json file at %s" % url
return 'Unknown Instance'
def getReportInfoFromFilename(self, filename):
splited_filename = filename.split('_every_')
possible_time_list = ['hour', 'minute']
if len(splited_filename) == 1:
return (filename, "* * * * *")
run_time = splited_filename[1].split('_')
report_name = splited_filename[0]
if len(run_time) != 2 or not run_time[1] in possible_time_list:
return (report_name, "* * * * *")
try:
value = int(run_time[0])
except ValueError:
print "Warning: Bad report filename: %s" % filename
return (report_name, "* * * * *")
if run_time[1] == 'hour':
return (report_name, "* */%s * * *" % value)
if run_time[1] == 'minute':
return (report_name, "*/%s * * * *" % value)
def configureFolders(self):
# configure public and private folder
self.createSymlinksFromConfig(self.webdav_folder, [self.public_folder])
......@@ -387,8 +409,6 @@ class Monitoring(object):
def generateReportCronEntries(self):
cron_line_list = []
# We should add the possibility to modify this parameter later from monitor interface
report_frequency = "*/20 * * * *"
report_name_list = [name.replace('.report.json', '')
for name in os.listdir(self.report_folder) if name.endswith('.report.json')]
......@@ -396,11 +416,12 @@ class Monitoring(object):
for filename in os.listdir(self.report_script_folder):
report_script = os.path.join(self.report_script_folder, filename)
if os.path.isfile(report_script) and os.access(report_script, os.X_OK):
report_name = os.path.splitext(filename)[0]
report_name, frequency = self.getReportInfoFromFilename(filename)
# report_name = os.path.splitext(filename)[0]
report_json_path = "%s.report.json" % report_name
report_cmd_line = [
report_frequency,
frequency,
self.promise_runner,
'--pid_path "%s"' % os.path.join(self.service_pid_folder,
"%s.pid" % filename),
......
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