From 3299c998a8181c060c866039705fd607320c2f42 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 28 Nov 2023 17:02:44 +0100 Subject: [PATCH] fix #98i add order to global zones, fix #99 add feature to add additional zones --- REFERENCE.md | 17 ++++++++++++-- examples/mysql/databases.pp | 29 +++++++++++++++++++---- manifests/agent.pp | 1 + manifests/server.pp | 11 +++++---- manifests/worker.pp | 10 +++++++- spec/classes/server_spec.rb | 24 ++++++++++++------- spec/classes/worker_spec.rb | 47 ++++++++++++++++++++++++++++++++++++- 7 files changed, 118 insertions(+), 21 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index f06695a..0a522e5 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -597,6 +597,7 @@ The following parameters are available in the `icinga::server` class: * [`zone`](#-icinga--server--zone) * [`colocation_endpoints`](#-icinga--server--colocation_endpoints) * [`workers`](#-icinga--server--workers) +* [`extra_zones`](#-icinga--server--extra_zones) * [`global_zones`](#-icinga--server--global_zones) * [`ca_server`](#-icinga--server--ca_server) * [`ticket_salt`](#-icinga--server--ticket_salt) @@ -645,11 +646,14 @@ Default value: `{}` Data type: `Hash[String,Hash]` -All worker zones with key 'endpoints' for -endpoint objects. +All worker zones with key 'endpoints' for endpoint objects. Default value: `{}` +##### `extra_zones` + +Additonal zones that are not limited to the 'parent_zone' as parent. + ##### `global_zones` Data type: `Array[String]` @@ -1774,6 +1778,7 @@ The following parameters are available in the `icinga::worker` class: * [`parent_zone`](#-icinga--worker--parent_zone) * [`parent_endpoints`](#-icinga--worker--parent_endpoints) * [`colocation_endpoints`](#-icinga--worker--colocation_endpoints) +* [`workers`](#-icinga--worker--workers) * [`global_zones`](#-icinga--worker--global_zones) * [`logging_type`](#-icinga--worker--logging_type) * [`logging_level`](#-icinga--worker--logging_level) @@ -1814,6 +1819,14 @@ Icinga supports two endpoints per zone only. Default value: `{}` +##### `workers` + +Data type: `Hash[String, Hash]` + +All cascading worker zones with key 'endpoints' for endpoint objects. + +Default value: `{}` + ##### `global_zones` Data type: `Array[String]` diff --git a/examples/mysql/databases.pp b/examples/mysql/databases.pp index bc35fb8..d97bf75 100644 --- a/examples/mysql/databases.pp +++ b/examples/mysql/databases.pp @@ -54,31 +54,50 @@ } class { 'icinga::ido::database': - ido_instances => ['192.168.5.13', '192.168.5.23'], + ido_instances => ['192.168.6.11', '192.168.6.12'], db_type => 'mysql', db_pass => 'icinga2', + tls => 'password', } class { 'icinga::db::database': - access_instances => ['192.168.5.13', '192.168.5.23'], + access_instances => ['192.168.6.11', '192.168.6.12'], db_type => 'mysql', db_pass => 'icingadb', + tls => 'cert', } class { 'icinga::web::database': - web_instances => ['192.168.5.13', '192.168.5.23'], + web_instances => ['192.168.6.11', '192.168.6.12'], db_type => 'mysql', db_pass => 'icingaweb2', + tls => 'cert', } class { 'icinga::web::director::database': - web_instances => ['192.168.5.13', '192.168.5.23'], + web_instances => ['192.168.6.11', '192.168.6.12'], db_type => 'mysql', db_pass => 'director', + tls => 'password', +} + +class { 'icinga::web::reporting::database': + web_instances => ['192.168.6.11', '192.168.6.12'], + db_type => 'mysql', + db_pass => 'reporting', + tls => 'password', +} + +class { 'icinga::web::x509::database': + web_instances => ['192.168.6.11', '192.168.6.12'], + db_type => 'mysql', + db_pass => 'x509', + tls => 'password', } class { 'icinga::web::vspheredb::database': - web_instances => ['192.168.5.13', '192.168.5.23'], + web_instances => ['192.168.6.11', '192.168.6.12'], db_type => 'mysql', db_pass => 'vspheredb', + tls => 'password', } diff --git a/manifests/agent.pp b/manifests/agent.pp index e0e9095..7d3af9d 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -52,5 +52,6 @@ icinga2::object::zone { $global_zones: global => true, + order => 'zz', } } diff --git a/manifests/server.pp b/manifests/server.pp index 839353a..7c4d414 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -15,8 +15,10 @@ # Icinga supports two endpoints per zone only. # # @param workers -# All worker zones with key 'endpoints' for -# endpoint objects. +# All worker zones with key 'endpoints' for endpoint objects. +# +# @param extra_zones +# Additonal zones that are not limited to the 'parent_zone' as parent. # # @param global_zones # List of global zones to configure. @@ -77,8 +79,8 @@ $_config_server = $config_server } - # inject parent zone - $_workers = parseyaml(inline_template('<%= @workers.inject({}) {|h, (x,y)| h[x] = y.merge({"parent" => @zone}); h}.to_yaml %>')) + # inject parent zone if no parent exists + $_workers = $workers.reduce( {} ) |$memo, $worker| { $memo + { $worker[0] => { parent => $zone } + $worker[1] } } class { 'icinga': ca => $_ca, @@ -96,6 +98,7 @@ icinga2::object::zone { $global_zones: global => true, + order => 'zz', } if $_config_server { diff --git a/manifests/worker.pp b/manifests/worker.pp index 0c6ea6d..f54e845 100644 --- a/manifests/worker.pp +++ b/manifests/worker.pp @@ -17,6 +17,9 @@ # When the zone includes more than one endpoint, set here the additional endpoint(s). # Icinga supports two endpoints per zone only. # +# @param workers +# All cascading worker zones with key 'endpoints' for endpoint objects. +# # @param global_zones # List of global zones to configure. # @@ -36,11 +39,15 @@ Hash[String, Hash] $parent_endpoints, String $parent_zone = 'main', Hash[String, Hash] $colocation_endpoints = {}, + Hash[String, Hash] $workers = {}, Array[String] $global_zones = [], Enum['file', 'syslog'] $logging_type = 'file', Optional[Icinga::LogLevel] $logging_level = undef, Boolean $run_web = false, ) { + # inject parent zone if no parent exists + $_workers = $workers.reduce( {} ) |$memo, $worker| { $memo + { $worker[0] => { parent => $zone } + $worker[1] } } + class { 'icinga': ca => false, ssh_private_key => undef, @@ -49,7 +56,7 @@ zones => { 'ZoneName' => { 'endpoints' => { 'NodeName' => {} } + $colocation_endpoints, 'parent' => $parent_zone, }, $parent_zone => { 'endpoints' => $parent_endpoints, }, - }, + } + $_workers, logging_type => $logging_type, logging_level => $logging_level, prepare_web => $run_web, @@ -59,5 +66,6 @@ icinga2::object::zone { $global_zones: global => true, + order => 'zz', } } diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 8709741..d8c6e77 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -18,15 +18,15 @@ let(:icinga2_group) { 'icinga' } end - context 'with defaults' do + context "#{os} with defaults" do it { is_expected.to compile.and_raise_error(%r{expects a String value if a CA is configured}) } end - context 'with ticket_salt => supersecret, global_zones => [foo], web_api_user => bar, web_api_pass => topsecret' do + context "#{os} with ticket_salt 'supersecret', global_zones ['foo','bar'], web_api_user 'bar', web_api_pass 'topsecret'" do let(:params) do { ticket_salt: 'supersecret', - global_zones: ['foo'], + global_zones: ['foo', 'bar'], web_api_user: 'bar', web_api_pass: 'topsecret' } @@ -65,7 +65,8 @@ ) } - it { is_expected.to contain_icinga2__object__zone('foo').with('global' => true) } + it { is_expected.to contain_icinga2__object__zone('foo').with('global' => true, 'order' => 'zz') } + it { is_expected.to contain_icinga2__object__zone('bar').with('global' => true, 'order' => 'zz') } it { is_expected.to contain_file("#{icinga2_config_dir}/zones.d/foo").with( @@ -81,7 +82,7 @@ it { is_expected.to contain_icinga2__object__apiuser('bar').with({ 'password' => 'topsecret' }) } end - context 'with ca_server => foo, ticket_salt => supersecret, colocation_endpoints => {bar => {host => 127.0.0.1}}' do + context "#{os} with ca_server 'foo', ticket_salt 'supersecret' and a colocation_endpoints" do let(:params) do { ca_server: 'foo', @@ -113,12 +114,15 @@ } end - context 'with ticket_salt => supersecret, zone => foo, workers => {bar => {endpoints => {foobar => {host => 127.0.0.1}}}}, logging_type => syslog, logging_level => warning' do + context "#{os} with ticket_salt 'supersecret', zone 'foo' and two workers, logging_type 'syslog', logging_level 'warning'" do let(:params) do { ticket_salt: 'supersecret', zone: 'foo', - workers: { 'bar' => { 'endpoints' => { 'foobar' => { 'host' => '127.0.0.1' } } } }, + workers: { + 'bar' => { 'endpoints' => { 'foobar' => { 'host' => '127.0.0.1' } } }, + 'out' => { 'endpoints' => { 'outbar' => {} }, 'parent' => 'bar' }, + }, logging_type: 'syslog', logging_level: 'warning', } @@ -136,9 +140,13 @@ 'endpoints' => { 'NodeName' => {} }, }, 'bar' => { + 'parent' => 'foo', 'endpoints' => { 'foobar' => { 'host' => '127.0.0.1' } }, - 'parent' => 'foo', }, + 'out' => { + 'parent' => 'bar', + 'endpoints' => { 'outbar' => {} }, + } }, 'logging_type' => 'syslog', 'logging_level' => 'warning', diff --git a/spec/classes/worker_spec.rb b/spec/classes/worker_spec.rb index 55f35fe..cb624bf 100644 --- a/spec/classes/worker_spec.rb +++ b/spec/classes/worker_spec.rb @@ -7,7 +7,7 @@ context "on #{os}" do let(:facts) { facts } - context 'with ca_server => foo, zone => bar, parent_endpoints => { foobar => { host => 127.0.0.1}}, global_zones => [foobaz]' do + context "#{os} with ca_server 'foo', zone 'bar', a parent_endpoints 'foobar', global_zones ['foobaz']" do let(:params) do { ca_server: 'foo', @@ -43,6 +43,51 @@ it { is_expected.to contain_icinga2__object__zone('foobaz').with({ 'global' => true }) } end + + context "#{os} with zone 'foo' and two workers, logging_type 'syslog', logging_level 'warning'" do + let(:params) do + { + ca_server: 'foo', + zone: 'foo', + parent_endpoints: { 'foobar' => { 'host' => '127.0.0.1' } }, + workers: { + 'baz' => { 'endpoints' => { 'foobaz' => { 'host' => '127.0.0.1' } } }, + 'out' => { 'endpoints' => { 'outbar' => {} }, 'parent' => 'baz' }, + }, + logging_type: 'syslog', + logging_level: 'warning', + } + end + + it { + is_expected.to contain_class('icinga').with( + { + 'ca' => false, + 'ca_server' => 'foo', + 'this_zone' => 'foo', + 'zones' => { + 'ZoneName' => { + 'parent' => 'main', + 'endpoints' => { 'NodeName' => {} }, + }, + 'main' => { + 'endpoints' => { 'foobar' => { 'host' => '127.0.0.1' } }, + }, + 'baz' => { + 'parent' => 'foo', + 'endpoints' => { 'foobaz' => { 'host' => '127.0.0.1' } }, + }, + 'out' => { + 'parent' => 'baz', + 'endpoints' => { 'outbar' => {} }, + } + }, + 'logging_type' => 'syslog', + 'logging_level' => 'warning', + }, + ) + } + end end end end