Commit ad032691 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5: http monitor script get settings from zero knowledge config file

parent 31ab0f18
......@@ -180,7 +180,7 @@ context =
recipe = slapos.recipe.template
filename = instance-http-monitor.cfg.in
url = ${:_profile_base_location_}/${:filename}
md5sum = f1d5fa0e3f0b5f42cc87119c427d20a6
md5sum = d2ddadaa0459319745b78dc704200755
output = ${buildout:directory}/template-http-monitor.cfg.in
##################e
......@@ -191,7 +191,7 @@ output = ${buildout:directory}/template-http-monitor.cfg.in
< = download-base
url = ${:_profile_base_location_}/monitor-templates/monitor-check-cache-hit.in
download-only = true
md5sum = b9f3f93bc41287698a44a687e6483f01
md5sum = 8e9ea2bec2fff4bd98c074cb69cf8592
filename = monitor-check-cache-hit.in
mode = 0644
......
......@@ -30,15 +30,14 @@ template = ${template-monitor-check-cache-hit:location}/${template-monitor-check
rendered = $${monitor-directory:monitor-custom-scripts}/check-cache-hit.py
mode = 700
context =
key url_list zero-parameters:url_list
key resolve_list zero-parameters:resolve_list
raw config_cfg $${buildout:directory}/$${public:filename}
raw python_executable ${buildout:bin-directory}/python2.7
[public]
recipe = slapos.cookbook:zero-knowledge.write
filename = knowledge0.cfg
url_list = ['http://www.erp5.com/']
resolve_list = ['www.erp5.com:80:5.135.149.226']
json_url_list = ["http://www.erp5.com/"]
json_resolve_list = ["www.erp5.com:80:5.135.149.226"]
[zero-parameters]
recipe = slapos.cookbook:zero-knowledge.read
......
......@@ -5,11 +5,16 @@
import sys
import pycurl
import ConfigParser
import os
import json
from mimetools import Message
from cStringIO import StringIO
from HTMLParser import HTMLParser
####################
# Init logging tools
def debug(*args):
# sys.stderr.write("DEBUG: " + "\n : ".join(" ".join((str(arg) for arg in args)).split("\n")) + "\n")
pass
......@@ -30,6 +35,27 @@ def error(*args):
last_error_log = "ERROR: " + "\n : ".join(" ".join((str(arg) for arg in args)).split("\n")) + "\n"
sys.stderr.write(last_error_log)
#############################
# Checking configuration file
config_file = "{{ config_cfg }}"
if not os.path.exists(config_file):
error("Your software does *NOT* embed 0-knowledge. This interface is useless in this case")
exit(1)
##################################
# Getting configuration parameters
config_parser = ConfigParser.ConfigParser()
config_parser.read(config_file)
if not config_parser.has_section('public'):
error("Your software does not use 0-knowledge settings.")
exit(1)
url_list = json.loads(config_parser.get("public", "json_url_list"))
resolve_list = json.loads(config_parser.get("public", "json_resolve_list"))
########################
# Prepare & run requests
class MyHTMLParser(HTMLParser):
def __init__(self, base_url):
HTMLParser.__init__(self)
......@@ -61,9 +87,6 @@ headers = {
# "Connection": "keep-alive"
}
url_list = {{ url_list }}
resolve_list = {{ resolve_list }}
parsed_url_dict = {}
info("Start checking for cache hits")
......
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