[buildout]

extends = {{ monitor_template_output }}

parts =
  cron
  cron-network-bench
  symlink-re6st-logs
  symlink-collected-logs
  monitor-collect-csv-wrapper
  fluentd-wrapper
  monitor-base
  publish-connection-information


eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

[cron-network-bench]
<= cron
recipe = slapos.cookbook:cron.d
name = network-bench-test
frequency = */10 * * * *
command = {{ buildout }}/networkbench ${network-bench-configuration:rendered} ${monitor-directory:monitor-log}

[symlink-re6st-logs]
recipe = cns.recipe.symlink
symlink = /var/log/re6stnet = ${monitor-directory:system-log}/re6stnet
autocreate = true

[symlink-collected-logs]
recipe = cns.recipe.symlink
symlink = /srv/slapgrid/var/data-log = ${monitor-directory:server-log}/data-log
autocreate = true

[network-bench-configuration]
recipe = slapos.recipe.template:jinja2
template = {{ network_benck_cfg_output }}
rendered = ${monitor-directory:etc}/network_bench.cfg
mode = 0744
context =
  key slapparameter_dict slap-configuration:configuration

[pwgen]
recipe = slapos.cookbook:generate.password
user = admin
bytes = 16

[pwgen32]
recipe = slapos.cookbook:generate.password
user = admin
bytes = 16

[monitor-directory]
service = ${buildout:directory}/etc/service
var = ${buildout:directory}/var
srv = ${buildout:directory}/srv
server-log = ${:private}/server-log
monitor-log = ${:private}/monitor-log
cache = ${:var}/cache
mod-ssl = ${:cache}/httpd_mod_ssl
system-log = ${:private}/system-log
fluentd-log = ${:log}/fluentd
consumption = ${:fluentd-log}/consumption

[monitor-httpd-configuration-file]
context =
  import json_module json
  section directory monitor-directory
  section monitor_parameters monitor-parameters
  section httpd_configuration monitor-httpd-configuration
  section monitor_rewrite_rule monitor-rewrite-rule
  section slave_information slap-configuration
  key monitor_private_hash slap-configuration:private-hash  

[fluentd-wrapper]
recipe = slapos.cookbook:wrapper
command-line = {{ fluentd_location }}/bin/fluentd -l ${monitor-directory:log}/fluend.log -c ${fluentd-conf-configuration:rendered}
wrapper-path = ${monitor-directory:service}/fluentd
environment = 
  GEM_PATH={{ fluentd_location }}/lib/ruby/gems/1.8/

[fluentd-conf-configuration]
recipe = slapos.recipe.template:jinja2
template = {{ fluent_conf_output }}
rendered = ${monitor-directory:etc}/fluentd.cfg
mode = 0744
context =
  key slapparameter_dict slap-configuration:configuration
  key slave_instance_list slap-configuration:slave-instance-list
  key fluentd_log_directory monitor-directory:fluentd-log
  key computer_id slap-connection:computer-id


[monitor-collect-csv-wrapper]
recipe = slapos.cookbook:wrapper
command-line = 
  ${monitor-directory:bin}/python {{ monitor_collect_csv_dump }} --output_folder ${monitor-directory:fluentd-log}/consumption/
wrapper-path = ${monitor-directory:reports}/monitor-collect-csv-dump  
parameters-extra = true

[publish-connection-information]
recipe = slapos.cookbook:publish
monitor-setup-url = https://monitor.app.officejs.com/#page=settings_configurator&url=${publish:monitor-url}&username=${publish:monitor-user}&password=${publish:monitor-password}
server_log_url = ${publish:monitor-base-url}/${slap-configuration:private-hash}/ 


[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}
private-hash = ${pwgen:passwd}${pwgen32:passwd}
frontend-domain = 
