caco 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +227 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/bin/_guard-core +29 -0
- data/bin/bundle +114 -0
- data/bin/byebug +29 -0
- data/bin/caco +29 -0
- data/bin/coderay +29 -0
- data/bin/console +20 -0
- data/bin/eyaml +29 -0
- data/bin/guard +29 -0
- data/bin/listen +29 -0
- data/bin/pry +29 -0
- data/bin/rake +29 -0
- data/bin/safe_yaml +29 -0
- data/bin/setup +8 -0
- data/bin/thor +29 -0
- data/bin/tilt +29 -0
- data/caco.gemspec +43 -0
- data/exe/caco +27 -0
- data/lib/caco.rb +115 -0
- data/lib/caco/barman.rb +10 -0
- data/lib/caco/barman/cell/global.rb +4 -0
- data/lib/caco/barman/cell/node.rb +15 -0
- data/lib/caco/barman/install.rb +25 -0
- data/lib/caco/barman/view/global.erb +7 -0
- data/lib/caco/barman/view/node.erb +8 -0
- data/lib/caco/cell.rb +8 -0
- data/lib/caco/config.rb +23 -0
- data/lib/caco/debian.rb +28 -0
- data/lib/caco/debian/add_user.rb +18 -0
- data/lib/caco/debian/apt_key_install.rb +19 -0
- data/lib/caco/debian/apt_repo_add.rb +17 -0
- data/lib/caco/debian/apt_sources_list.rb +15 -0
- data/lib/caco/debian/apt_update.rb +33 -0
- data/lib/caco/debian/cell/service.rb +19 -0
- data/lib/caco/debian/cell/sources_list.rb +7 -0
- data/lib/caco/debian/package_install.rb +21 -0
- data/lib/caco/debian/package_installed.rb +17 -0
- data/lib/caco/debian/service_enable.rb +26 -0
- data/lib/caco/debian/service_install.rb +31 -0
- data/lib/caco/debian/user_home.rb +17 -0
- data/lib/caco/debian/view/service.erb +18 -0
- data/lib/caco/debian/view/sources_list.erb +10 -0
- data/lib/caco/downloader.rb +41 -0
- data/lib/caco/executer.rb +33 -0
- data/lib/caco/facter.rb +41 -0
- data/lib/caco/file_link.rb +36 -0
- data/lib/caco/file_reader.rb +24 -0
- data/lib/caco/file_writer.rb +57 -0
- data/lib/caco/finder.rb +13 -0
- data/lib/caco/grafana.rb +6 -0
- data/lib/caco/grafana/install.rb +26 -0
- data/lib/caco/haproxy.rb +12 -0
- data/lib/caco/haproxy/cell/conf_postgres.rb +4 -0
- data/lib/caco/haproxy/cell/conf_stats.rb +4 -0
- data/lib/caco/haproxy/conf_get.rb +15 -0
- data/lib/caco/haproxy/conf_set.rb +52 -0
- data/lib/caco/haproxy/install.rb +9 -0
- data/lib/caco/haproxy/view/conf_postgres.erb +25 -0
- data/lib/caco/haproxy/view/conf_stats.erb +6 -0
- data/lib/caco/macro.rb +2 -0
- data/lib/caco/postgres.rb +44 -0
- data/lib/caco/postgres/build_augeas.rb +20 -0
- data/lib/caco/postgres/conf_get.rb +37 -0
- data/lib/caco/postgres/conf_set.rb +54 -0
- data/lib/caco/postgres/database_create.rb +28 -0
- data/lib/caco/postgres/extension_create.rb +28 -0
- data/lib/caco/postgres/hba_set.rb +65 -0
- data/lib/caco/postgres/install.rb +34 -0
- data/lib/caco/postgres/shell.rb +13 -0
- data/lib/caco/postgres/sql.rb +17 -0
- data/lib/caco/postgres/user_change_password.rb +13 -0
- data/lib/caco/postgres/user_create.rb +33 -0
- data/lib/caco/prometheus.rb +15 -0
- data/lib/caco/prometheus/adapter_install_pg.rb +107 -0
- data/lib/caco/prometheus/adapter_install_postgresql.rb +47 -0
- data/lib/caco/prometheus/cell/alertmanager_conf.rb +4 -0
- data/lib/caco/prometheus/cell/alerts.rb +4 -0
- data/lib/caco/prometheus/cell/conf.rb +7 -0
- data/lib/caco/prometheus/exporter_install.rb +35 -0
- data/lib/caco/prometheus/install.rb +50 -0
- data/lib/caco/prometheus/install_alert_manager.rb +62 -0
- data/lib/caco/prometheus/view/alertmanager_conf.erb +13 -0
- data/lib/caco/prometheus/view/alerts.erb +18 -0
- data/lib/caco/prometheus/view/conf.erb +34 -0
- data/lib/caco/rbenv.rb +8 -0
- data/lib/caco/rbenv/cell/profile.rb +4 -0
- data/lib/caco/rbenv/install.rb +56 -0
- data/lib/caco/rbenv/install_version.rb +17 -0
- data/lib/caco/rbenv/view/profile.erb +3 -0
- data/lib/caco/repmgr.rb +15 -0
- data/lib/caco/repmgr/cell/conf.rb +43 -0
- data/lib/caco/repmgr/conf.rb +25 -0
- data/lib/caco/repmgr/install.rb +25 -0
- data/lib/caco/repmgr/node_register_primary.rb +34 -0
- data/lib/caco/repmgr/node_register_standby.rb +25 -0
- data/lib/caco/repmgr/node_registered.rb +15 -0
- data/lib/caco/repmgr/node_role.rb +18 -0
- data/lib/caco/repmgr/view/conf.erb +27 -0
- data/lib/caco/settings_loader.rb +67 -0
- data/lib/caco/settings_loader_monkeypatch.rb +28 -0
- data/lib/caco/ssh.rb +6 -0
- data/lib/caco/ssh/authorized_keys_add.rb +82 -0
- data/lib/caco/sudo.rb +6 -0
- data/lib/caco/sudo/sudoers_add.rb +15 -0
- data/lib/caco/timescale.rb +6 -0
- data/lib/caco/timescale/install.rb +25 -0
- data/lib/caco/unpacker.rb +76 -0
- data/lib/caco/version.rb +3 -0
- metadata +398 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Caco::Postgres
|
2
|
+
class Install < Trailblazer::Operation
|
3
|
+
class Repo < Trailblazer::Operation
|
4
|
+
step Subprocess(Caco::Debian::AptKeyInstall),
|
5
|
+
input: ->(_ctx, **) {{
|
6
|
+
url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc',
|
7
|
+
fingerprint: 'B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8'
|
8
|
+
}}
|
9
|
+
step Subprocess(Caco::Debian::AptRepoAdd),
|
10
|
+
input: ->(_ctx, **) {{
|
11
|
+
name: 'pgdg',
|
12
|
+
url: 'http://apt.postgresql.org/pub/repos/apt/',
|
13
|
+
release: "#{Caco::Facter.("os", "distro", "codename")}-pgdg",
|
14
|
+
component: 'main'
|
15
|
+
}}
|
16
|
+
end
|
17
|
+
|
18
|
+
step Subprocess(Repo)
|
19
|
+
step Subprocess(Caco::Debian::AptUpdate)
|
20
|
+
step Subprocess(Caco::Debian::PackageInstall),
|
21
|
+
input: ->(_ctx, **) {{
|
22
|
+
package: 'postgresql-server-12'
|
23
|
+
}},
|
24
|
+
id: :install_server
|
25
|
+
|
26
|
+
pass ->(ctx, **){ ctx.to_hash.dig(:install_dev_package) }, Output(:success) => Id(:install_dev_package)
|
27
|
+
step Subprocess(Class.new(Caco::Debian::PackageInstall)),
|
28
|
+
input: ->(_ctx, **) {{
|
29
|
+
package: 'postgresql-server-dev-12'
|
30
|
+
}},
|
31
|
+
id: :install_dev_package,
|
32
|
+
magnetic_to: nil
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Caco::Postgres
|
2
|
+
class Shell < Trailblazer::Operation
|
3
|
+
step ->(ctx, command:, **) {
|
4
|
+
ctx[:shell_command] = "su -c \"#{command}\" postgres"
|
5
|
+
},
|
6
|
+
id: :build_command
|
7
|
+
|
8
|
+
step Subprocess(Caco::Executer),
|
9
|
+
input: { shell_command: :command },
|
10
|
+
output: [:exit_code, :output],
|
11
|
+
id: "shell"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Caco::Postgres
|
2
|
+
class Sql < Trailblazer::Operation
|
3
|
+
step :build_command
|
4
|
+
step Subprocess(Caco::Executer),
|
5
|
+
input: { sql_command: :command },
|
6
|
+
output: [:exit_code, :output, :stderr],
|
7
|
+
id: "shell"
|
8
|
+
|
9
|
+
def build_command(ctx, sql:, **)
|
10
|
+
ctx[:sql_command] = "su -l -c \"psql -e -U postgres -d postgres <<EOF
|
11
|
+
#{sql}
|
12
|
+
EOF
|
13
|
+
\" postgres"
|
14
|
+
# ctx[:sql_command] = "psql -U fernandes -d postgres -c \"#{sql}\""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Caco::Postgres
|
2
|
+
class UserChangePassword < Trailblazer::Operation
|
3
|
+
step ->(ctx, user:, password:, **) {
|
4
|
+
ctx[:sql] = "alter user #{user} with password '#{password}';"
|
5
|
+
},
|
6
|
+
id: :build_sql
|
7
|
+
|
8
|
+
step Subprocess(Caco::Postgres::Sql),
|
9
|
+
input: ->(_ctx, sql:, **) {{
|
10
|
+
sql: sql,
|
11
|
+
}}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Caco::Postgres
|
2
|
+
class UserCreate < Trailblazer::Operation
|
3
|
+
step Subprocess(Caco::Postgres::Sql),
|
4
|
+
input: ->(_ctx, user:, **) {{
|
5
|
+
sql: "select usename from pg_user where usename='#{user}';",
|
6
|
+
}},
|
7
|
+
id: :sql_find_user
|
8
|
+
|
9
|
+
step ->(_ctx, output:, user:, **) {
|
10
|
+
output.match?(/^\s#{user}$/)
|
11
|
+
},
|
12
|
+
Output(:success) => End(:success),
|
13
|
+
Output(:failure) => Track(:success),
|
14
|
+
id: :verify_user_exists
|
15
|
+
|
16
|
+
step Subprocess(Caco::Executer),
|
17
|
+
input: ->(ctx, user:, **) {{
|
18
|
+
command: "createuser -e #{user} #{ctx[:additional_args]}",
|
19
|
+
}},
|
20
|
+
id: :create_user
|
21
|
+
|
22
|
+
step Subprocess(Caco::Postgres::UserChangePassword),
|
23
|
+
input: ->(ctx, user:, password:, **) {{
|
24
|
+
user: user, password: password,
|
25
|
+
}},
|
26
|
+
id: :user_change_password
|
27
|
+
|
28
|
+
step ->(ctx, **) {
|
29
|
+
ctx[:created] = ctx[:changed] = true
|
30
|
+
},
|
31
|
+
id: :mark_created
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Caco
|
2
|
+
module Prometheus
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'caco/prometheus/adapter_install_pg'
|
7
|
+
require 'caco/prometheus/adapter_install_postgresql'
|
8
|
+
require 'caco/prometheus/exporter_install'
|
9
|
+
require 'caco/prometheus/install'
|
10
|
+
require 'caco/prometheus/install_alert_manager'
|
11
|
+
|
12
|
+
# Templates
|
13
|
+
require 'caco/prometheus/cell/alertmanager_conf'
|
14
|
+
require 'caco/prometheus/cell/alerts'
|
15
|
+
require 'caco/prometheus/cell/conf'
|
@@ -0,0 +1,107 @@
|
|
1
|
+
class Caco::Prometheus::AdapterInstallPg < Trailblazer::Operation
|
2
|
+
step Subprocess(Class.new(Caco::Debian::PackageInstall)),
|
3
|
+
input: ->(_ctx, postgresql_version:, **) {{
|
4
|
+
package: "postgresql-server-dev-#{postgresql_version}"
|
5
|
+
}},
|
6
|
+
id: :install_postgresql_server_dev
|
7
|
+
|
8
|
+
step Subprocess(Class.new(Caco::Debian::PackageInstall)),
|
9
|
+
input: ->(_ctx, postgresql_version:, **) {{
|
10
|
+
package: "libpq-dev"
|
11
|
+
}},
|
12
|
+
id: :install_libpq_dev
|
13
|
+
|
14
|
+
step :check_root
|
15
|
+
def check_root(ctx, **)
|
16
|
+
ctx[:root] = Settings.prometheus.root
|
17
|
+
FileUtils.mkdir_p(Settings.prometheus.root)
|
18
|
+
end
|
19
|
+
|
20
|
+
step :build_url
|
21
|
+
def build_url(ctx, version:, root:, **)
|
22
|
+
ctx[:url] = "https://github.com/timescale/pg_prometheus/archive/#{version}.tar.gz"
|
23
|
+
ctx[:dest] = "#{root}/pg_prometheus-#{version}.tar.gz"
|
24
|
+
ctx[:current_target] = "#{root}/pg_prometheus-#{version}"
|
25
|
+
ctx[:current_link] = "#{root}/pg_prometheus-current"
|
26
|
+
end
|
27
|
+
|
28
|
+
step Subprocess(Caco::Downloader),
|
29
|
+
input: ->(ctx, url:, dest:, **) {{
|
30
|
+
url: url,
|
31
|
+
dest: dest,
|
32
|
+
stubbed_file: ctx[:stubbed_file]
|
33
|
+
}}
|
34
|
+
step Subprocess(Caco::Unpacker),
|
35
|
+
input: ->(ctx, root:, dest:, **) {{
|
36
|
+
pack: dest,
|
37
|
+
dest: root
|
38
|
+
}}
|
39
|
+
step Subprocess(Caco::FileLink),
|
40
|
+
input: ->(ctx, current_target:, current_link:, **) {{
|
41
|
+
target: current_target,
|
42
|
+
link: current_link
|
43
|
+
}}
|
44
|
+
|
45
|
+
# Build
|
46
|
+
step Subprocess(Class.new(Caco::Executer)),
|
47
|
+
input: ->(_ctx, current_link:, **) {{
|
48
|
+
command: "test -f #{current_link}/.caco_built"
|
49
|
+
}},
|
50
|
+
id: :check_caco_built,
|
51
|
+
Output(:failure) => Track(:build_pg)
|
52
|
+
|
53
|
+
step Subprocess(Class.new(Caco::Executer)),
|
54
|
+
input: ->(_ctx, current_link:, **) {{
|
55
|
+
command: "cd #{current_link} && make"
|
56
|
+
}},
|
57
|
+
id: :build_pg,
|
58
|
+
magnetic_to: :build_pg,
|
59
|
+
Output(:success) => Track(:build_pg)
|
60
|
+
|
61
|
+
step Subprocess(Class.new(Caco::Executer)),
|
62
|
+
input: ->(_ctx, current_link:, **) {{
|
63
|
+
command: "touch #{current_link}/.caco_built"
|
64
|
+
}},
|
65
|
+
id: :mark_as_built,
|
66
|
+
magnetic_to: :build_pg
|
67
|
+
|
68
|
+
# Install
|
69
|
+
step Subprocess(Class.new(Caco::Executer)),
|
70
|
+
input: ->(_ctx, current_link:, **) {{
|
71
|
+
command: "test -f #{current_link}/.caco_installed"
|
72
|
+
}},
|
73
|
+
id: :check_caco_installed,
|
74
|
+
Output(:failure) => Track(:install_pg)
|
75
|
+
|
76
|
+
step Subprocess(Class.new(Caco::Executer)),
|
77
|
+
input: ->(_ctx, current_link:, **) {{
|
78
|
+
command: "cd #{current_link} && make install"
|
79
|
+
}},
|
80
|
+
id: :install_pg,
|
81
|
+
magnetic_to: :install_pg,
|
82
|
+
Output(:success) => Track(:install_pg)
|
83
|
+
|
84
|
+
step Subprocess(Class.new(Caco::Executer)),
|
85
|
+
input: ->(_ctx, current_link:, **) {{
|
86
|
+
command: "touch #{current_link}/.caco_installed"
|
87
|
+
}},
|
88
|
+
id: :mark_as_installed,
|
89
|
+
magnetic_to: :install_pg,
|
90
|
+
Output(:success) => Track(:install_pg)
|
91
|
+
|
92
|
+
step :postgresql_shared_library,
|
93
|
+
magnetic_to: :install_pg,
|
94
|
+
Output(:success) => Track(:install_pg)
|
95
|
+
|
96
|
+
step :postgresql_should_restart,
|
97
|
+
magnetic_to: :install_pg
|
98
|
+
|
99
|
+
def postgresql_shared_library(ctx, **)
|
100
|
+
Caco::Postgres.add_shared_library("timescaledb")
|
101
|
+
Caco::Postgres.add_shared_library("pg_prometheus")
|
102
|
+
end
|
103
|
+
|
104
|
+
def postgresql_should_restart(ctx, **)
|
105
|
+
Caco::Postgres.should_restart!
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Caco::Prometheus::AdapterInstallPostgresql < Trailblazer::Operation
|
2
|
+
step :check_root
|
3
|
+
step :build_url
|
4
|
+
step :mkdir_target
|
5
|
+
|
6
|
+
step Subprocess(Caco::Downloader),
|
7
|
+
input: ->(ctx, url:, dest:, **) {{
|
8
|
+
url: url,
|
9
|
+
dest: dest,
|
10
|
+
stubbed_file: ctx[:stubbed_file]
|
11
|
+
}}
|
12
|
+
|
13
|
+
step Subprocess(Caco::Unpacker),
|
14
|
+
input: ->(ctx, adapter_root:, dest:, **) {{
|
15
|
+
pack: dest,
|
16
|
+
dest: adapter_root
|
17
|
+
}}
|
18
|
+
|
19
|
+
step Subprocess(Caco::FileLink),
|
20
|
+
input: ->(ctx, current_target:, current_link:, **) {{
|
21
|
+
target: current_target,
|
22
|
+
link: current_link
|
23
|
+
}}
|
24
|
+
|
25
|
+
step Subprocess(Caco::Debian::ServiceInstall),
|
26
|
+
input: ->(ctx, current_link:, database:, host:, username:, password:, **) {{
|
27
|
+
name: "prometheus-adapter-postgresql",
|
28
|
+
command: "#{current_link}/prometheus-postgresql-adapter -pg-database #{database} -pg-host #{host} -pg-user #{username} -pg-password #{password} -log-level warn"
|
29
|
+
}}
|
30
|
+
|
31
|
+
def check_root(ctx, version:, **)
|
32
|
+
ctx[:root] = Settings.prometheus.root
|
33
|
+
ctx[:adapter_root] = "#{Settings.prometheus.root}/postgresql-adapter-#{version}.linux-amd64"
|
34
|
+
FileUtils.mkdir_p(ctx[:adapter_root])
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_url(ctx, version:, root:, adapter_root:, **)
|
38
|
+
ctx[:url] = "https://github.com/timescale/prometheus-postgresql-adapter/releases/download/v#{version}/prometheus-postgresql-adapter-#{version}-linux-amd64.tar.gz"
|
39
|
+
ctx[:dest] = "#{root}/prometheus-postgresql-adapter-#{version}-linux-amd64.tar.gz"
|
40
|
+
ctx[:current_target] = adapter_root
|
41
|
+
ctx[:current_link] = "#{root}/postgresql-adapter-current"
|
42
|
+
end
|
43
|
+
|
44
|
+
def mkdir_target(ctx, current_target:, **)
|
45
|
+
FileUtils.mkdir_p(current_target)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Caco::Prometheus::ExporterInstall < Trailblazer::Operation
|
2
|
+
step :check_root
|
3
|
+
|
4
|
+
step Subprocess(Caco::Downloader),
|
5
|
+
input: ->(ctx, url:, tar_dest_path:, **) {{
|
6
|
+
url: url,
|
7
|
+
dest: tar_dest_path,
|
8
|
+
stubbed_file: ctx[:stubbed_file]
|
9
|
+
}}
|
10
|
+
|
11
|
+
step Subprocess(Caco::Unpacker),
|
12
|
+
input: ->(ctx, tar_dest_path:, tar_unpack_path:, **) {{
|
13
|
+
pack: tar_dest_path,
|
14
|
+
dest: tar_unpack_path
|
15
|
+
}}
|
16
|
+
|
17
|
+
step Subprocess(Caco::FileLink),
|
18
|
+
input: ->(ctx, current_target:, current_link:, **) {{
|
19
|
+
target: current_target,
|
20
|
+
link: current_link
|
21
|
+
}}
|
22
|
+
|
23
|
+
step Subprocess(Caco::Debian::ServiceInstall),
|
24
|
+
input: ->(ctx, service_name:, service_command:, environment_vars: nil, environment_file: nil, **) {{
|
25
|
+
name: service_name,
|
26
|
+
command: service_command,
|
27
|
+
environment_vars: environment_vars,
|
28
|
+
environment_file: environment_file
|
29
|
+
}}
|
30
|
+
|
31
|
+
def check_root(ctx, **)
|
32
|
+
ctx[:root] = Settings.prometheus.root
|
33
|
+
FileUtils.mkdir_p(Settings.prometheus.root)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Caco::Prometheus::Install < Trailblazer::Operation
|
2
|
+
step :check_root
|
3
|
+
def check_root(ctx, **)
|
4
|
+
ctx[:root] = Settings.prometheus.root
|
5
|
+
FileUtils.mkdir_p(Settings.prometheus.root)
|
6
|
+
end
|
7
|
+
|
8
|
+
step :build_url
|
9
|
+
def build_url(ctx, version:, root:, **)
|
10
|
+
ctx[:url] = "https://github.com/prometheus/prometheus/releases/download/v#{version}/prometheus-#{version}.linux-amd64.tar.gz"
|
11
|
+
ctx[:dest] = "#{root}/prometheus-#{version}.linux-amd64.tar.gz"
|
12
|
+
ctx[:current_target] = "#{root}/prometheus-#{version}.linux-amd64"
|
13
|
+
ctx[:current_link] = "#{root}/prometheus-current"
|
14
|
+
ctx[:config_file_path] = "#{Settings.prometheus.config_root}/prometheus.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
step Subprocess(Caco::Downloader),
|
18
|
+
input: ->(ctx, url:, dest:, **) {{
|
19
|
+
url: url,
|
20
|
+
dest: dest,
|
21
|
+
stubbed_file: ctx[:stubbed_file]
|
22
|
+
}}
|
23
|
+
|
24
|
+
step Subprocess(Caco::Unpacker),
|
25
|
+
input: ->(ctx, root:, dest:, **) {{
|
26
|
+
pack: dest,
|
27
|
+
dest: root
|
28
|
+
}}
|
29
|
+
|
30
|
+
step Subprocess(Caco::FileLink),
|
31
|
+
input: ->(ctx, current_target:, current_link:, **) {{
|
32
|
+
target: current_target,
|
33
|
+
link: current_link
|
34
|
+
}}
|
35
|
+
|
36
|
+
step Subprocess(Caco::Debian::ServiceInstall),
|
37
|
+
input: ->(ctx, current_link:, **) {{
|
38
|
+
name: "prometheus",
|
39
|
+
command: "#{current_link}/prometheus --config.file=#{Settings.prometheus.config_root}/prometheus.yml --storage.tsdb.path=#{Settings.prometheus.root}/data"
|
40
|
+
}}
|
41
|
+
|
42
|
+
step ->(ctx, **) {
|
43
|
+
ctx[:content] = Caco::Prometheus::Cell::Conf.({root: Settings.prometheus.config_root}).to_s
|
44
|
+
},
|
45
|
+
id: :generate_template!
|
46
|
+
|
47
|
+
step Subprocess(Caco::FileWriter),
|
48
|
+
input: { content: :content, config_file_path: :path },
|
49
|
+
output: { file_changed: :sources_updated }
|
50
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Caco::Prometheus::InstallAlertManager < Trailblazer::Operation
|
2
|
+
step :check_root
|
3
|
+
def check_root(ctx, **)
|
4
|
+
ctx[:root] = Settings.prometheus.root
|
5
|
+
FileUtils.mkdir_p(Settings.prometheus.root)
|
6
|
+
end
|
7
|
+
|
8
|
+
step :build_url
|
9
|
+
def build_url(ctx, version:, root:, **)
|
10
|
+
ctx[:url] = "https://github.com/prometheus/alertmanager/releases/download/v#{version}/alertmanager-#{version}.linux-amd64.tar.gz"
|
11
|
+
ctx[:dest] = "#{root}/alertmanager-#{version}.linux-amd64.tar.gz"
|
12
|
+
ctx[:current_target] = "#{root}/alertmanager-#{version}.linux-amd64"
|
13
|
+
ctx[:current_link] = "#{root}/alertmanager-current"
|
14
|
+
ctx[:config_file_path] = "#{Settings.prometheus.config_root}/alertmanager.yml"
|
15
|
+
ctx[:alerts_file_path] = "#{Settings.prometheus.config_root}/alerts.d/alerts.rules"
|
16
|
+
end
|
17
|
+
|
18
|
+
step Subprocess(Caco::Downloader),
|
19
|
+
input: ->(ctx, url:, dest:, **) {{
|
20
|
+
url: url,
|
21
|
+
dest: dest,
|
22
|
+
stubbed_file: ctx[:stubbed_file]
|
23
|
+
}}
|
24
|
+
|
25
|
+
step Subprocess(Caco::Unpacker),
|
26
|
+
input: ->(ctx, root:, dest:, **) {{
|
27
|
+
pack: dest,
|
28
|
+
dest: root
|
29
|
+
}}
|
30
|
+
|
31
|
+
step Subprocess(Caco::FileLink),
|
32
|
+
input: ->(ctx, current_target:, current_link:, **) {{
|
33
|
+
target: current_target,
|
34
|
+
link: current_link
|
35
|
+
}}
|
36
|
+
|
37
|
+
step Subprocess(Caco::Debian::ServiceInstall),
|
38
|
+
input: ->(ctx, current_link:, **) {{
|
39
|
+
name: "prometheus-alertmanager",
|
40
|
+
command: "#{current_link}/alertmanager --config.file=#{Settings.prometheus.config_root}/alertmanager.yml"
|
41
|
+
}}
|
42
|
+
|
43
|
+
step ->(ctx, **) {
|
44
|
+
ctx[:content] = Caco::Prometheus::Cell::Conf.({root: Settings.prometheus.config_root}).to_s
|
45
|
+
},
|
46
|
+
id: :generate_template!
|
47
|
+
|
48
|
+
step Subprocess(Caco::FileWriter),
|
49
|
+
input: { content: :content, config_file_path: :path },
|
50
|
+
output: { file_changed: :sources_updated },
|
51
|
+
id: :write_config_template
|
52
|
+
|
53
|
+
step ->(ctx, **) {
|
54
|
+
ctx[:alerts_content] = Caco::Prometheus::Cell::Alerts.().to_s
|
55
|
+
},
|
56
|
+
id: :generate_alerts_template!
|
57
|
+
|
58
|
+
step Subprocess(Class.new(Caco::FileWriter)),
|
59
|
+
input: { alerts_file_path: :path, alerts_content: :content },
|
60
|
+
output: { file_changed: :sources_updated },
|
61
|
+
id: :write_alerts_template
|
62
|
+
end
|