Skip to content

Commit

Permalink
fix #98i add order to global zones, fix #99 add feature to add additi…
Browse files Browse the repository at this point in the history
…onal zones
  • Loading branch information
lbetz committed Nov 28, 2023
1 parent 419dfec commit 3299c99
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 21 deletions.
17 changes: 15 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: `{}`

##### <a name="-icinga--server--extra_zones"></a>`extra_zones`

Additonal zones that are not limited to the 'parent_zone' as parent.

##### <a name="-icinga--server--global_zones"></a>`global_zones`

Data type: `Array[String]`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1814,6 +1819,14 @@ Icinga supports two endpoints per zone only.

Default value: `{}`

##### <a name="-icinga--worker--workers"></a>`workers`

Data type: `Hash[String, Hash]`

All cascading worker zones with key 'endpoints' for endpoint objects.

Default value: `{}`

##### <a name="-icinga--worker--global_zones"></a>`global_zones`

Data type: `Array[String]`
Expand Down
29 changes: 24 additions & 5 deletions examples/mysql/databases.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
1 change: 1 addition & 0 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@

icinga2::object::zone { $global_zones:
global => true,
order => 'zz',
}
}
11 changes: 7 additions & 4 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -96,6 +98,7 @@

icinga2::object::zone { $global_zones:
global => true,
order => 'zz',
}

if $_config_server {
Expand Down
10 changes: 9 additions & 1 deletion manifests/worker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -59,5 +66,6 @@

icinga2::object::zone { $global_zones:
global => true,
order => 'zz',
}
}
24 changes: 16 additions & 8 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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(
Expand All @@ -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',
Expand Down Expand Up @@ -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',
}
Expand All @@ -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',
Expand Down
47 changes: 46 additions & 1 deletion spec/classes/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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

0 comments on commit 3299c99

Please sign in to comment.