[buildout]

extends = {{ monitor_template_output }}

parts =
  cron
  cron-network-bench
  symlink-re6st-logs
  symlink-collected-logs
  python-symlink
  monitor-collect-csv-wrapper
  monitor-base
  monitor-check-memory-usage
  monitor-check-cpu-usage
  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 * * * *
# skip to not fill cron log file.
# command = {{ buildout_bin }}/networkbench ${network-bench-configuration:rendered} ${monitor-directory:monitor-log}
command = true


[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
consumption = ${: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  

[python-symlink]
recipe = plone.recipe.command
command = ln -sf {{ buildout_bin }}/pythonwitheggs ${monitor-directory:bin}/python
update-command = ${:command}

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

[monitor-check-memory-usage]
recipe = slapos.cookbook:wrapper
command-line = {{ buildout_bin}}/check-computer-memory
               -db ${monitor-instance-parameter:collector-db}
               --threshold ${slap-parameter:memory-percent-threshold}
               --unit percent
wrapper-path = ${directory:promises}/check-computer-memory-usage

[monitor-check-cpu-usage]
recipe = slapos.cookbook:promise.plugin
eggs =
  slapos.toolbox
file = ${monitor-conf-parameters:promise-output-file}
content = 
  from slapos.promise.plugin.check_server_cpu_load import RunPromise
output = ${directory:plugins}/system-CPU-load-check.py
mode = 600
config-cpu-load-threshold = ${slap-parameter:cpu-load-threshold}

[publish-connection-information]
recipe = slapos.cookbook:publish
monitor-setup-url = https://monitor.app.officejs.com/#page=settings_configurator&url=${monitor-publish-parameters:monitor-url}&username=${monitor-publish-parameters:monitor-user}&password=${monitor-publish-parameters:monitor-password}
server_log_url = ${monitor-publish-parameters: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 = 

[slap-parameter]
# Max cpu load for one core on server
cpu-load-threshold = 3.0
memory-percent-threshold = 96
