95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
# File 'manifests/web.pp', line 95
class zabbix::web (
$zabbix_url = $zabbix::params::zabbix_url,
$database_type = $zabbix::params::database_type,
$manage_repo = $zabbix::params::manage_repo,
$zabbix_version = $zabbix::params::zabbix_version,
$zabbix_timezone = $zabbix::params::zabbix_timezone,
$zabbix_package_state = $zabbix::params::zabbix_package_state,
$zabbix_template_dir = $zabbix::params::zabbix_template_dir,
$web_config_owner = $zabbix::params::web_config_owner,
$web_config_group = $zabbix::params::web_config_group,
$manage_vhost = $zabbix::params::manage_vhost,
$default_vhost = $zabbix::params::default_vhost,
$manage_resources = $zabbix::params::manage_resources,
$apache_use_ssl = $zabbix::params::apache_use_ssl,
$apache_ssl_cert = $zabbix::params::apache_ssl_cert,
$apache_ssl_key = $zabbix::params::apache_ssl_key,
$apache_ssl_cipher = $zabbix::params::apache_ssl_cipher,
$apache_ssl_chain = $zabbix::params::apache_ssl_chain,
$apache_listen_ip = $zabbix::params::apache_listen_ip,
Variant[Array[Stdlib::Port], Stdlib::Port] $apache_listenport = $zabbix::params::apache_listenport,
Variant[Array[Stdlib::Port], Stdlib::Port] $apache_listenport_ssl = $zabbix::params::apache_listenport_ssl,
$zabbix_api_user = $zabbix::params::server_api_user,
$zabbix_api_pass = $zabbix::params::server_api_pass,
Optional[Array[Stdlib::Host,1]] $zabbix_api_access = $zabbix::params::server_api_access,
$database_host = $zabbix::params::server_database_host,
$database_name = $zabbix::params::server_database_name,
$database_schema = $zabbix::params::server_database_schema,
Boolean $database_double_ieee754 = $zabbix::params::server_database_double_ieee754,
$database_user = $zabbix::params::server_database_user,
$database_password = $zabbix::params::server_database_password,
$database_socket = $zabbix::params::server_database_socket,
$database_port = $zabbix::params::server_database_port,
$zabbix_server = $zabbix::params::zabbix_server,
Optional[String] $zabbix_server_name = $zabbix::params::zabbix_server,
$zabbix_listenport = $zabbix::params::server_listenport,
$apache_php_max_execution_time = $zabbix::params::apache_php_max_execution_time,
$apache_php_memory_limit = $zabbix::params::apache_php_memory_limit,
$apache_php_post_max_size = $zabbix::params::apache_php_post_max_size,
$apache_php_upload_max_filesize = $zabbix::params::apache_php_upload_max_filesize,
$apache_php_max_input_time = $zabbix::params::apache_php_max_input_time,
$apache_php_always_populate_raw_post_data = $zabbix::params::apache_php_always_populate_raw_post_data,
$apache_php_max_input_vars = $zabbix::params::apache_php_max_input_vars,
Optional[Stdlib::Absolutepath] $ldap_cacert = $zabbix::params::ldap_cacert,
Optional[Stdlib::Absolutepath] $ldap_clientcert = $zabbix::params::ldap_clientcert,
Optional[Stdlib::Absolutepath] $ldap_clientkey = $zabbix::params::ldap_clientkey,
Optional[Enum['never','allow','try','demand','hard']] $ldap_reqcert = $zabbix::params::ldap_reqcert,
Optional[Stdlib::Absolutepath] $saml_sp_key = $zabbix::params::saml_sp_key,
Optional[Stdlib::Absolutepath] $saml_sp_cert = $zabbix::params::saml_sp_cert,
Optional[Stdlib::Absolutepath] $saml_idp_cert = $zabbix::params::saml_idp_cert,
Hash[String[1], Variant[ScalarData, Hash]] $saml_settings = $zabbix::params::saml_settings,
$puppetgem = $zabbix::params::puppetgem,
Boolean $manage_selinux = $zabbix::params::manage_selinux,
Hash[String[1], Any] $apache_vhost_custom_params = {},
) inherits zabbix::params {
# check osfamily, Arch is currently not supported for web
if $facts['os']['family'] in ['Archlinux', 'Gentoo',] {
fail("${facts['os']['family']} is currently not supported for zabbix::web")
}
# Only include the repo class if it has not yet been included
unless defined(Class['Zabbix::Repo']) {
class { 'zabbix::repo':
manage_repo => $manage_repo,
zabbix_version => $zabbix_version,
}
}
# use the correct db.
case $database_type {
'postgresql': {
$db = 'pgsql'
$db_port = '5432'
}
'mysql': {
$db = 'mysql'
$db_port = '3306'
}
default: {
fail('unrecognized database type for server.')
}
}
# So if manage_resources is set to true, we can send some data
# to the puppetdb. We will include an class, otherwise when it
# is set to false, you'll get warnings like this:
# "Warning: You cannot collect without storeconfigs being set"
if $manage_resources {
file { $zabbix_template_dir:
ensure => directory,
owner => 'zabbix',
group => 'zabbix',
mode => '0755',
}
-> class { 'zabbix::zabbixapi':
zabbix_version => $zabbix_version,
puppetgem => $puppetgem,
}
-> class { 'zabbix::resources::web':
zabbix_url => $zabbix_url,
zabbix_user => $zabbix_api_user,
zabbix_pass => $zabbix_api_pass,
apache_use_ssl => $apache_use_ssl,
}
}
case $facts['os']['family'] {
'Debian': {
$zabbix_web_package = 'zabbix-frontend-php'
$php_db_package = "php-${db}"
package { $php_db_package:
ensure => $zabbix_package_state,
before => [
Package[$zabbix_web_package],
File['/etc/zabbix/web/zabbix.conf.php'],
],
}
}
'RedHat': {
$zabbix_web_package = 'zabbix-web'
if ($facts['os']['release']['major'] == '7') {
package { "zabbix-web-${db}-scl":
ensure => $zabbix_package_state,
before => Package[$zabbix_web_package],
require => Class['zabbix::repo'],
tag => 'zabbix',
}
} else {
package { "zabbix-web-${db}":
ensure => $zabbix_package_state,
before => Package[$zabbix_web_package],
require => Class['zabbix::repo'],
tag => 'zabbix',
}
}
}
default: {
$zabbix_web_package = 'zabbix-web'
package { "zabbix-web-${db}":
ensure => $zabbix_package_state,
before => Package[$zabbix_web_package],
require => Class['zabbix::repo'],
tag => 'zabbix',
}
}
} # END case $facts['os']['family']
file { '/etc/zabbix/web':
ensure => directory,
owner => 'zabbix',
group => 'zabbix',
mode => '0755',
require => Package[$zabbix_web_package],
}
package { $zabbix_web_package:
ensure => $zabbix_package_state,
before => File['/etc/zabbix/web/zabbix.conf.php'],
require => Class['zabbix::repo'],
tag => 'zabbix',
}
# Webinterface config file
file { '/etc/zabbix/web/zabbix.conf.php':
ensure => file,
owner => $web_config_owner,
group => $web_config_group,
mode => '0640',
replace => true,
content => template('zabbix/web/zabbix.conf.php.erb'),
}
# For API to work on Zabbix 5.x zabbix.conf.php needs to be in the root folder.
file { '/etc/zabbix/zabbix.conf.php':
ensure => link,
target => '/etc/zabbix/web/zabbix.conf.php',
owner => $web_config_owner,
group => $web_config_group,
mode => '0640',
}
# Is set to true, it will create the apache vhost.
if $manage_vhost {
include apache
include apache::mod::dir
if $facts['os']['family'] == 'RedHat' {
if $facts['os']['release']['major'] == '7' {
$fpm_service = 'rh-php72-php-fpm'
# PHP parameters are moved to /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf per package zabbix-web-deps-scl
$fpm_scl_prefix = '/opt/rh/rh-php72'
} else {
$fpm_service = 'php-fpm'
$fpm_scl_prefix = ''
}
include apache::mod::proxy
include apache::mod::proxy_fcgi
$apache_vhost_custom_fragment = ''
service { $fpm_service:
ensure => 'running',
enable => true,
}
file { "/etc${fpm_scl_prefix}/php-fpm.d/zabbix.conf":
ensure => file,
notify => Service[$fpm_service],
content => epp('zabbix/web/php-fpm.d.zabbix.conf.epp'),
}
$fcgi_filematch = {
path => '/usr/share/zabbix',
provider => 'directory',
addhandlers => [
{
extensions => [
'php',
'phar',
],
handler => "proxy:unix:/var${fpm_scl_prefix}/run/php-fpm/zabbix.sock|fcgi://localhost",
},
],
}
$proxy_directory = {
path => 'fcgi://localhost:9000',
provider => 'proxy',
}
}
else {
include apache::mod::php
$apache_vhost_custom_fragment = "
php_value max_execution_time ${apache_php_max_execution_time}
php_value memory_limit ${apache_php_memory_limit}
php_value post_max_size ${apache_php_post_max_size}
php_value upload_max_filesize ${apache_php_upload_max_filesize}
php_value max_input_time ${apache_php_max_input_time}
php_value always_populate_raw_post_data ${apache_php_always_populate_raw_post_data}
php_value max_input_vars ${apache_php_max_input_vars}
# Set correct timezone
php_value date.timezone ${zabbix_timezone}"
$fcgi_filematch = {}
$proxy_directory = {}
}
# Check if we use ssl. If so, we also create an non ssl
# vhost for redirect traffic from non ssl to ssl site.
if $apache_use_ssl {
# Listen port
$apache_listen_port = $apache_listenport_ssl
# We create nonssl vhost for redirecting non ssl
# traffic to https.
apache::vhost { "${zabbix_url}_nonssl":
docroot => '/usr/share/zabbix',
manage_docroot => false,
default_vhost => $default_vhost,
port => $apache_listenport,
servername => $zabbix_url,
ssl => false,
rewrites => [
{
comment => 'redirect all to https',
rewrite_cond => ['%{SERVER_PORT} !^443$'],
rewrite_rule => ["^/(.*)$ https://${zabbix_url}/\$1 [L,R]"],
}
],
}
} else {
# So no ssl, so default port 80
$apache_listen_port = $apache_listenport
}
$location_api_access = $zabbix_api_access ? {
undef => 'all granted',
default => $zabbix_api_access.map |$host| { "host ${host}" },
}
apache::vhost { $zabbix_url:
docroot => '/usr/share/zabbix',
ip => $apache_listen_ip,
port => $apache_listen_port,
default_vhost => $default_vhost,
add_listen => true,
directories => [
merge({
path => '/usr/share/zabbix',
provider => 'directory',
require => 'all granted',
}, $fcgi_filematch
),
{
path => '/usr/share/zabbix/conf',
provider => 'directory',
require => 'all denied',
},
{
path => '/usr/share/zabbix/api',
provider => 'directory',
require => 'all denied',
},
{
path => '/usr/share/zabbix/include',
provider => 'directory',
require => 'all denied',
},
{
path => '/usr/share/zabbix/include/classes',
provider => 'directory',
require => 'all denied',
},
{
path => '/api_jsonrpc.php',
provider => 'location',
require => $location_api_access,
},
],
custom_fragment => $apache_vhost_custom_fragment,
rewrites => [
{
rewrite_rule => ['^$ /index.php [L]'] }
],
ssl => $apache_use_ssl,
ssl_cert => $apache_ssl_cert,
ssl_key => $apache_ssl_key,
ssl_cipher => $apache_ssl_cipher,
ssl_chain => $apache_ssl_chain,
require => Package[$zabbix_web_package],
* => $apache_vhost_custom_params,
}
} # END if $manage_vhost
# check if selinux is active and allow zabbix
if fact('os.selinux.enabled') == true and $manage_selinux {
# allow httpd to speak to the zabbix service
selboolean { 'httpd_can_connect_zabbix':
persistent => true,
value => 'on',
}
# allow httpd to speak to the database
selboolean { 'httpd_can_network_connect_db':
persistent => true,
value => 'on',
}
}
}
|