Commit 8a0a74e8 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

monitor: clean directory and parameter sections

monitor: continue cleaning section in monitor.cfg.in

monitor: continue fix and optimising monitor.cfg

monitor: Fix make RSS (introduced by clean sections)
parent 68636f8c
#!${dash-output:dash} #!${dash-output:dash}
STATUS=$${monitor-parameters:result-dir} STATUS={{ directory['monitor-result-bool'] }}
RSS_FILE=$${monitor-parameters:rss-path} RSS_FILE={{ monitor_parameters['rss-path'] }}
PYTHON=${buildout:directory}/bin/${extra-eggs:interpreter} PYTHON=${buildout:directory}/bin/${extra-eggs:interpreter}
STATUS2RSS=${rss-bin:location}/${rss-bin:filename} STATUS2RSS=${rss-bin:location}/${rss-bin:filename}
NAME=`basename $STATUS` NAME=`basename $STATUS`
cat $STATUS/* | $PYTHON $STATUS2RSS "Monitoring RSS feed" "https://[$${slap-parameters:ipv6-random}]:$${monitor-parameters:port}/$${deploy-index:filename}" > $RSS_FILE cat $STATUS/* | $PYTHON $STATUS2RSS "Monitoring RSS feed" "{{ monitor_parameters['url'] }}/{{ monitor_parameters['index-filename'] }}" > $RSS_FILE
...@@ -7,23 +7,20 @@ key = $${slap-connection:key-file} ...@@ -7,23 +7,20 @@ key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file} cert = $${slap-connection:cert-file}
[monitor-parameters] [monitor-parameters]
monitor-dir = $${monitor-directory:var}/monitor
result-dir = $${:monitor-dir}/bool
json-filename = monitor.json json-filename = monitor.json
json-path = $${:monitor-dir}/$${:json-filename} json-path = $${monitor-directory:monitor-result}/$${:json-filename}
rss-path = $${:public-cgi}/$${:rss-filename}
rss-filename = rssfeed.html rss-filename = rssfeed.html
rss-path = $${monitor-directory:public-cgi}/$${:rss-filename}
executable = $${monitor-directory:bin}/monitor.py executable = $${monitor-directory:bin}/monitor.py
cgi-bin = $${monitor-directory:cgi-bin}
monitoring-cgi = $${monitor-directory:monitoring-cgi}
knowledge0-cgi = $${monitor-directory:knowledge0-cgi}
public-cgi = $${monitor-directory:public-cgi}
port = 9685 port = 9685
private-directory = $${monitor-directory:monitor-private-directory} htaccess-file = $${monitor-directory:etc}/.htaccess-monitor
htaccess-file = $${monitor-htaccess:htaccess-path} url = https://[$${slap-parameters:ipv6-random}]:$${:port}
index-filename = index.cgi
index-path = $${monitor-directory:www}/$${:index-filename}
[monitor-directory] [monitor-directory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
# Standard directory needed by monitoring stack
home = $${buildout:directory} home = $${buildout:directory}
etc = $${:home}/etc etc = $${:home}/etc
bin = $${:home}/bin bin = $${:home}/bin
...@@ -40,29 +37,22 @@ cron-entries = $${:etc}/cron.d ...@@ -40,29 +37,22 @@ cron-entries = $${:etc}/cron.d
crontabs = $${:etc}/crontabs crontabs = $${:etc}/crontabs
cronstamps = $${:etc}/cronstamps cronstamps = $${:etc}/cronstamps
promises = $${:etc}/promise
ca-dir = $${:srv}/ssl ca-dir = $${:srv}/ssl
www = $${:var}/www
cgi-bin = $${:var}/cgi-bin cgi-bin = $${:var}/cgi-bin
monitoring-cgi = $${:cgi-bin}/monitoring monitoring-cgi = $${:cgi-bin}/monitoring
knowledge0-cgi = $${:cgi-bin}/zero-knowledge knowledge0-cgi = $${:cgi-bin}/zero-knowledge
cron-entries = $${:etc}/cron.d
crontabs = $${:etc}/crontabs
cronstamps = $${:etc}/cronstamps
log = $${:var}/log
monitor = $${:etc}/monitor
monitor-result = $${:var}/monitor
monitor-result-bool = $${:var}/monitor
promise = $${:etc}/promise
public-cgi = $${:cgi-bin}/public public-cgi = $${:cgi-bin}/public
run = $${:var}/run
service = $${:etc}/service/ monitor-custom-scripts = $${:etc}/monitor
tmp = $${:home}/tmp monitor-result = $${:var}/monitor
www = $${:var}/www monitor-result-bool = $${:monitor-result}/bool
monitor-private-directory = $${:srv}/monitor-private private-directory = $${:srv}/monitor-private
[public-symlink] [public-symlink]
recipe = cns.recipe.symlink recipe = cns.recipe.symlink
symlink = $${monitor-parameters:public-cgi} = $${monitor-directory:www}/public symlink = $${monitor-directory:public-cgi} = $${monitor-directory:www}/public
autocreate = true autocreate = true
[cron] [cron]
...@@ -85,14 +75,14 @@ log = $${monitor-directory:log}/cron.log ...@@ -85,14 +75,14 @@ log = $${monitor-directory:log}/cron.log
recipe = slapos.cookbook:cron.d recipe = slapos.cookbook:cron.d
name = launch-monitor name = launch-monitor
frequency = */5 * * * * frequency = */5 * * * *
command = $${monitor-parameters:executable} -a command = $${deploy-monitor-script:rendered} -a
[cron-entry-rss] [cron-entry-rss]
<= cron <= cron
recipe = slapos.cookbook:cron.d recipe = slapos.cookbook:cron.d
name = build-rss name = build-rss
frequency = */5 * * * * frequency = */5 * * * *
command = $${make-rss:output} command = $${make-rss:rendered}
[setup-static-files] [setup-static-files]
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
...@@ -105,11 +95,10 @@ mode = 0644 ...@@ -105,11 +95,10 @@ mode = 0644
[deploy-index] [deploy-index]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = ${index:location}/${index:filename} template = ${index:location}/${index:filename}
rendered = $${monitor-directory:www}/$${:filename} rendered = $${monitor-parameters:index-path}
filename = index.cgi
mode = 0744 mode = 0744
context = context =
key cgi_directory monitor-parameters:cgi-bin key cgi_directory monitor-directory:cgi-bin
raw index_template $${deploy-index-template:location}/$${deploy-index-template:filename} raw index_template $${deploy-index-template:location}/$${deploy-index-template:filename}
key password zero-parameters:monitor-password key password zero-parameters:monitor-password
raw extra_eggs_interpreter ${buildout:directory}/bin/${extra-eggs:interpreter} raw extra_eggs_interpreter ${buildout:directory}/bin/${extra-eggs:interpreter}
...@@ -126,7 +115,7 @@ mode = 0644 ...@@ -126,7 +115,7 @@ mode = 0644
[deploy-status-cgi] [deploy-status-cgi]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = ${status-cgi:location}/${status-cgi:filename} template = ${status-cgi:location}/${status-cgi:filename}
rendered = $${monitor-parameters:monitoring-cgi}/$${:filename} rendered = $${monitor-directory:monitoring-cgi}/$${:filename}
filename = status.cgi filename = status.cgi
mode = 0744 mode = 0744
context = context =
...@@ -136,14 +125,14 @@ context = ...@@ -136,14 +125,14 @@ context =
[deploy-settings-cgi] [deploy-settings-cgi]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = ${settings-cgi:location}/${settings-cgi:filename} template = ${settings-cgi:location}/${settings-cgi:filename}
rendered = $${monitor-parameters:knowledge0-cgi}/$${:filename} rendered = $${monitor-directory:knowledge0-cgi}/$${:filename}
filename = settings.cgi filename = settings.cgi
mode = 0744 mode = 0744
context = context =
raw config_cfg $${buildout:directory}/knowledge0.cfg raw config_cfg $${buildout:directory}/knowledge0.cfg
raw timestamp $${buildout:directory}/.timestamp raw timestamp $${buildout:directory}/.timestamp
raw python_executable ${buildout:executable} raw python_executable ${buildout:executable}
key pwd monitor-parameters:knowledge0-cgi key pwd monitor-directory:knowledge0-cgi
key this_file :filename key this_file :filename
[deploy-monitor-script] [deploy-monitor-script]
...@@ -154,32 +143,26 @@ mode = 0744 ...@@ -154,32 +143,26 @@ mode = 0744
context = context =
section directory monitor-directory section directory monitor-directory
key monitoring_file_json monitor-parameters:json-path key monitoring_file_json monitor-parameters:json-path
key monitoring_folder_bool monitor-parameters:result-dir
raw python_executable ${buildout:executable} raw python_executable ${buildout:executable}
[deploy-rss-script]
recipe = hexagonit.recipe.download
url = ${rss-bin:destination}/${rss-bin:filename}
destination = $${monitor-directory:bin}
filename = ${rss-bin:filename}
mode = 0744
download-only = true
[make-rss] [make-rss]
recipe = slapos.recipe.template recipe = slapos.recipe.template:jinja2
url = ${make-rss-script:output} template = ${make-rss-script:output}
output = $${monitor-directory:bin}/make-rss.sh rendered = $${monitor-directory:bin}/make-rss.sh
mode = 0744 mode = 0744
context =
section directory monitor-directory
section monitor_parameters monitor-parameters
[monitor-htaccess] [monitor-htaccess]
recipe = plone.recipe.command recipe = plone.recipe.command
stop-on-error = true stop-on-error = true
htaccess-path = $${monitor-directory:monitor}/.htaccess htaccess-path = $${monitor-parameters:htaccess-file}
command = ${apache:location}/bin/htpasswd -cb $${:htaccess-path} admin $${zero-parameters:monitor-password} command = ${apache:location}/bin/htpasswd -cb $${:htaccess-path} admin $${zero-parameters:monitor-password}
[monitor-directory-access] [monitor-directory-access]
recipe = plone.recipe.command recipe = plone.recipe.command
command = ln -s $${:source} $${monitor-directory:monitor-private-directory} command = ln -s $${:source} $${monitor-directory:private-directory}
source = source =
[cadirectory] [cadirectory]
...@@ -273,10 +256,10 @@ input = inline: ...@@ -273,10 +256,10 @@ input = inline:
# XXX: security???? # XXX: security????
Options +ExecCGI Options +ExecCGI
AddHandler cgi-script .cgi AddHandler cgi-script .cgi
DirectoryIndex $${deploy-index:filename} DirectoryIndex $${monitor-parameters:index-filename}
</Directory> </Directory>
Alias /private/ $${monitor-parameters:private-directory}/ Alias /private/ $${monitor-directory:private-directory}/
<Directory $${monitor-parameters:private-directory}> <Directory $${monitor-directory:private-directory}>
Order Deny,Allow Order Deny,Allow
Deny from env=AUTHREQUIRED Deny from env=AUTHREQUIRED
<Files ".??*"> <Files ".??*">
...@@ -285,7 +268,7 @@ input = inline: ...@@ -285,7 +268,7 @@ input = inline:
</Files> </Files>
AuthType Basic AuthType Basic
AuthName "Private access" AuthName "Private access"
AuthUserFile "$${monitor-parameters:htaccess-file}" AuthUserFile "$${monitor-htaccess:htaccess-path}"
Require valid-user Require valid-user
Options Indexes FollowSymLinks Options Indexes FollowSymLinks
Satisfy all Satisfy all
...@@ -312,8 +295,8 @@ wrapper-path = $${monitor-directory:etc-run}/cgi-httpd-graceful ...@@ -312,8 +295,8 @@ wrapper-path = $${monitor-directory:etc-run}/cgi-httpd-graceful
[monitor-promise] [monitor-promise]
recipe = slapos.cookbook:check_url_available recipe = slapos.cookbook:check_url_available
path = $${monitor-directory:promises}/monitor path = $${monitor-directory:promise}/monitor
url = https://[$${cgi-httpd-configuration-file:listening-ip}]:$${monitor-parameters:port}/$${deploy-index:filename} url = $${monitor-parameters:url}/$${monitor-parameters:index-filename}
check-secure = 1 check-secure = 1
dash_path = ${dash:location}/bin/dash dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl curl_path = ${curl:location}/bin/curl
......
...@@ -9,12 +9,12 @@ import time ...@@ -9,12 +9,12 @@ import time
from optparse import OptionParser, make_option from optparse import OptionParser, make_option
instance_path = "{{ directory['home'] }}" instance_path = "{{ directory['home'] }}"
monitor_dir = "{{ directory['monitor'] }}" monitor_dir = "{{ directory['monitor-custom-scripts'] }}"
pid_dir = "{{ directory['run'] }}" pid_dir = "{{ directory['run'] }}"
promise_dir = "{{ directory['promise'] }}" promise_dir = "{{ directory['promise'] }}"
monitoring_file_json = "{{ monitoring_file_json }}" monitoring_file_json = "{{ monitoring_file_json }}"
monitoring_folder_bool = "{{ monitoring_folder_bool }}" monitoring_folder_bool = "{{ directory['monitor-result-bool'] }}"
option_list = [ option_list = [
make_option("-a", "--all", action="store_true", dest="all", make_option("-a", "--all", action="store_true", dest="all",
...@@ -31,15 +31,21 @@ option_list = [ ...@@ -31,15 +31,21 @@ option_list = [
def getListOfScripts(directory): def getListOfScripts(directory):
"""
Get the list of script inside of a directory (not recursive)
"""
scripts = [] scripts = []
if os.path.exists(directory) and os.path.isdir(directory): if os.path.exists(directory) and os.path.isdir(directory):
for file in os.listdir(directory): for file_name in os.listdir(directory):
scripts.append(os.path.join(directory, file)) file = os.path.join(directory, file_name)
if os.access(file, os.X_OK) and not os.path.isdir(file):
scripts.append(file)
else: else:
exit("There is a problem in your directories" \ exit("There is a problem in your directories" \
"of monitoring. Please check them") "of monitoring. Please check them")
return scripts return scripts
def runServices(directory): def runServices(directory):
services = getListOfScripts(directory) services = getListOfScripts(directory)
result = {} result = {}
......
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