1 class role::cryptoportfolio::bot inherits role::cryptoportfolio {
2 $password_seed = lookup("base_installation::puppet_pass_seed")
4 $cf_bot_app = "${home}/bot"
5 $cf_bot_app_conf = "${home}/bot_config.ini"
6 $cf_bot_app_conf_hourly = "${home}/bot_config_hourly.ini"
7 $cf_bot_app_reports = "${home}/bot_reports"
9 ensure_packages(["python", "python-pip"])
12 ensure => "directory",
16 require => User["$user:"],
19 archive { "${home}/trader_${trader_version}.tar.gz":
20 path => "${home}/trader_${trader_version}.tar.gz",
21 source => "https://release.immae.eu/cryptoportfolio/trader/trader_${trader_version}.tar.gz",
22 checksum_type => "sha256",
23 checksum => $trader_sha256,
27 username => lookup("base_installation::ldap_cn"),
28 password => generate_password(24, $password_seed, "ldap"),
29 extract_path => $cf_bot_app,
30 require => [User["$user:"], File[$cf_bot_app]],
32 exec { "py-cryptoportfolio-dependencies":
35 environment => ["HOME=${home}"],
36 command => "/usr/bin/make install",
37 require => User["$user:"],
40 File[$cf_bot_app_conf],
41 Cron::Job::Multiple["py-cryptoportfolio"],
45 $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
46 file { $cf_bot_app_conf:
50 content => template("role/cryptoportfolio/bot_config.ini.erb"),
53 Archive["${home}/trader_${trader_version}.tar.gz"],
57 cron::job::multiple { "py-cryptoportfolio":
59 environment => ["HOME=${home}","PATH=/usr/bin/","CRON_TZ=UTC"],
61 File[$cf_bot_app_conf],
62 Archive["${home}/trader_${trader_version}.tar.gz"]
67 if ($environment == "production") {
69 @profile::monitoring::local_service { "Last redis report is less than 2 hours old":
71 check_command => "check_date!redis-cli -s $redis_host GET /cryptoportfolio/$monitored_key/latest/date!2"
75 @profile::monitoring::local_service { "Last bot report is less than one week old":
77 "naemon-cryptoportfolio-bot" => "naemon ALL=($user) NOPASSWD: /usr/bin/find $cf_bot_app_reports -mindepth 1 -maxdepth 1 -printf %T@?n",
80 check_command => "check_last_file_date!$cf_bot_app_reports!168!$user",
85 if versioncmp($trader_version, "v1.3") >= 0 {
86 file { $cf_bot_app_conf_hourly:
90 content => template("role/cryptoportfolio/bot_config_hourly.ini.erb"),
93 Archive["${home}/trader_${trader_version}.tar.gz"],
97 cron::job::multiple { "py-cryptoportfolio-hourly":
99 environment => ["HOME=${home}","PATH=/usr/bin/"],
101 File[$cf_bot_app_conf_hourly],
102 Archive["${home}/trader_${trader_version}.tar.gz"]
106 command => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf_hourly",
109 description => "Print the current state to redis",
115 unless empty($webhook_url) {
116 exec { "bot-slack-notify":
120 "P_WEBHOOK=${webhook_url}",
121 "P_VERSION=${trader_version}",
122 "P_HOST=${web_host}",
123 "P_HTTPS=${web_ssl}",
125 command => "/usr/local/bin/slack-notify",
126 require => File["/usr/local/bin/slack-notify"],
127 subscribe => Exec["py-cryptoportfolio-dependencies"],