42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'manifests/server.pp', line 42
class icinga::server(
Boolean $ca = false,
Boolean $config_server = false,
String $zone = 'main',
Hash[String,Hash] $colocation_endpoints = {},
Hash[String,Hash] $workers = {},
Array[String] $global_zones = [],
Optional[Stdlib::Host] $ca_server = undef,
Optional[String] $ticket_salt = undef,
String $web_api_user = 'icingaweb2',
Optional[String] $web_api_pass = undef,
Enum['file', 'syslog'] $logging_type = 'file',
Optional[Icinga2::LogSeverity] $logging_level = undef,
) {
if empty($colocation_endpoints) {
$_ca = true
$_config_server = true
} else {
if !$ca and !$ca_server {
fail('Class[Icinga::Server]: expects a value for parameter \'ca_server\'')
}
$_ca = $ca
$_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 %>'
))
class { '::icinga':
ca => $_ca,
ca_server => $ca_server,
this_zone => $zone,
zones => merge({
'ZoneName' => { 'endpoints' => { 'NodeName' => {}} + $colocation_endpoints },
}, $_workers),
logging_type => $logging_type,
logging_level => $logging_level,
ticket_salt => $ticket_salt,
}
include ::icinga2::feature::checker
include ::icinga2::feature::notification
::icinga2::object::zone { $global_zones:
global => true,
}
if $_config_server {
::icinga2::object::apiuser { $web_api_user:
password => $web_api_pass,
permissions => [ 'status/query', 'actions/*', 'objects/modify/*', 'objects/query/*' ],
target => "/etc/icinga2/zones.d/${zone}/api-users.conf",
}
($global_zones + keys($_workers) + $zone).each |String $dir| {
file { "${::icinga2::globals::conf_dir}/zones.d/${dir}":
ensure => directory,
tag => 'icinga2::config::file',
owner => $::icinga2::globals::user,
group => $::icinga2::globals::group,
mode => '0750',
}
}
} else {
file { "${::icinga2::globals::conf_dir}/zones.d":
ensure => directory,
purge => true,
recurse => true,
force => true,
}
}
}
|