X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Frole%2Fmanifests%2Fcryptoportfolio%2Fbot.pp;h=0021bc63e6b6cd5263ff841e7dc27c2a770fa3ad;hb=871df075f3b3c405ef104266bbfb937cd6734b7d;hp=082e82059ae43b9222759bce9a0d4c6bd9e209f0;hpb=acaa9ea9b08b2cb4783194b0f06b494c1aabe9c1;p=perso%2FImmae%2FProjets%2FPuppet.git diff --git a/modules/role/manifests/cryptoportfolio/bot.pp b/modules/role/manifests/cryptoportfolio/bot.pp index 082e820..0021bc6 100644 --- a/modules/role/manifests/cryptoportfolio/bot.pp +++ b/modules/role/manifests/cryptoportfolio/bot.pp @@ -3,6 +3,7 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio { $cf_bot_app = "${home}/bot" $cf_bot_app_conf = "${home}/bot_config.ini" + $cf_bot_app_conf_hourly = "${home}/bot_config_hourly.ini" $cf_bot_app_reports = "${home}/bot_reports" ensure_packages(["python", "python-pip"]) @@ -17,7 +18,7 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio { archive { "${home}/trader_${trader_version}.tar.gz": path => "${home}/trader_${trader_version}.tar.gz", - source => "https://git.immae.eu/releases/cryptoportfolio/trader/trader_${trader_version}.tar.gz", + source => "https://release.immae.eu/cryptoportfolio/trader/trader_${trader_version}.tar.gz", checksum_type => "sha256", checksum => $trader_sha256, cleanup => false, @@ -68,18 +69,58 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio { hour => 22, minute => 30, description => "Run before the cryptoportfolio update", - }, - { - command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --after", - user => $user, - weekday => 1, # Monday - hour => 0, - minute => 0, - description => "Run after the cryptoportfolio update", } ], } + if ($environment == "production") { + $monitored_key = 3 + @profile::monitoring::local_service { "Last redis report is less than 2 hours old": + local => { + check_command => "check_date!redis-cli -s $redis_host GET /cryptoportfolio/$monitored_key/latest/date!2" + } + } + + @profile::monitoring::local_service { "Last bot report is less than one week old": + sudos => { + "naemon-cryptoportfolio-bot" => "naemon ALL=($user) NOPASSWD: /usr/bin/find $cf_bot_app_reports -mindepth 1 -maxdepth 1 -printf %T@?n", + }, + local => { + check_command => "check_last_file_date!$cf_bot_app_reports!168!$user", + }, + } + } + + if versioncmp($trader_version, "v1.3") >= 0 { + file { $cf_bot_app_conf_hourly: + owner => $user, + group => $group, + mode => "0600", + content => template("role/cryptoportfolio/bot_config_hourly.ini.erb"), + require => [ + User["$user:"], + Archive["${home}/trader_${trader_version}.tar.gz"], + ], + } + + cron::job::multiple { "py-cryptoportfolio-hourly": + ensure => present, + environment => ["HOME=${home}","PATH=/usr/bin/"], + require => [ + File[$cf_bot_app_conf_hourly], + Archive["${home}/trader_${trader_version}.tar.gz"] + ], + jobs => [ + { + command => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf_hourly", + user => $user, + minute => 30, + description => "Print the current state to redis", + }, + ], + } + } + unless empty($webhook_url) { exec { "bot-slack-notify": refreshonly => true,