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
|
# File 'manifests/agent.pp', line 204
class zabbix::agent (
$zabbix_version = $zabbix::params::zabbix_version,
$zabbix_package_state = $zabbix::params::zabbix_package_state,
$zabbix_package_agent = $zabbix::params::zabbix_package_agent,
Boolean $manage_firewall = $zabbix::params::manage_firewall,
Boolean $manage_repo = $zabbix::params::manage_repo,
Boolean $manage_resources = $zabbix::params::manage_resources,
$monitored_by_proxy = $zabbix::params::monitored_by_proxy,
$agent_use_ip = $zabbix::params::agent_use_ip,
$zbx_group = $zabbix::params::agent_zbx_group,
$zbx_group_create = $zabbix::params::agent_zbx_group_create,
$zbx_templates = $zabbix::params::agent_zbx_templates,
$agent_configfile_path = $zabbix::params::agent_configfile_path,
$pidfile = $zabbix::params::agent_pidfile,
$servicename = $zabbix::params::agent_servicename,
String $logtype = $zabbix::params::agent_logtype,
Optional[Stdlib::Absolutepath] $logfile = $zabbix::params::agent_logfile,
$logfilesize = $zabbix::params::agent_logfilesize,
$debuglevel = $zabbix::params::agent_debuglevel,
$sourceip = $zabbix::params::agent_sourceip,
$enableremotecommands = $zabbix::params::agent_enableremotecommands,
$logremotecommands = $zabbix::params::agent_logremotecommands,
$server = $zabbix::params::agent_server,
$listenport = $zabbix::params::agent_listenport,
$listenip = $zabbix::params::agent_listenip,
$startagents = $zabbix::params::agent_startagents,
$serveractive = $zabbix::params::agent_serveractive,
$hostname = $zabbix::params::agent_hostname,
$hostnameitem = $zabbix::params::agent_hostnameitem,
$hostmetadata = $zabbix::params::agent_hostmetadata,
$hostmetadataitem = $zabbix::params::agent_hostmetadataitem,
$refreshactivechecks = $zabbix::params::agent_refreshactivechecks,
$buffersend = $zabbix::params::agent_buffersend,
$buffersize = $zabbix::params::agent_buffersize,
$maxlinespersecond = $zabbix::params::agent_maxlinespersecond,
Optional[Array] $zabbix_alias = $zabbix::params::agent_zabbix_alias,
$timeout = $zabbix::params::agent_timeout,
$allowroot = $zabbix::params::agent_allowroot,
$zabbix_user = $zabbix::params::agent_zabbix_user,
$include_dir = $zabbix::params::agent_include,
$include_dir_purge = $zabbix::params::agent_include_purge,
$unsafeuserparameters = $zabbix::params::agent_unsafeuserparameters,
$userparameter = $zabbix::params::agent_userparameter,
$loadmodulepath = $zabbix::params::agent_loadmodulepath,
$loadmodule = $zabbix::params::agent_loadmodule,
$tlsaccept = $zabbix::params::agent_tlsaccept,
$tlscafile = $zabbix::params::agent_tlscafile,
$tlscertfile = $zabbix::params::agent_tlscertfile,
$tlsconnect = $zabbix::params::agent_tlsconnect,
$tlscrlfile = $zabbix::params::agent_tlscrlfile,
$tlskeyfile = $zabbix::params::agent_tlskeyfile,
$tlspskfile = $zabbix::params::agent_tlspskfile,
$tlspskidentity = $zabbix::params::agent_tlspskidentity,
$tlsservercertissuer = $zabbix::params::agent_tlsservercertissuer,
$tlsservercertsubject = $zabbix::params::agent_tlsservercertsubject,
String $agent_config_owner = $zabbix::params::agent_config_owner,
String $agent_config_group = $zabbix::params::agent_config_group,
Boolean $manage_selinux = $zabbix::params::manage_selinux,
Array[String] $selinux_require = $zabbix::params::selinux_require,
Hash[String, Array] $selinux_rules = $zabbix::params::selinux_rules,
String $additional_service_params = $zabbix::params::additional_service_params,
String $service_type = $zabbix::params::service_type,
) inherits zabbix::params {
# the following two codeblocks are a bit blargh. The correct default value for
# $real_additional_service_params and $type changes based on the value of $zabbix_version
# We handle this in the params.pp, but that doesn't work if somebody provides a specific
# value for $zabbix_version and overwrites our default :(
# the codeblocks set defaults for both variables if $zabbix_version got provided,
# but only if the variables aren't provided.
if $zabbix_version != $zabbix::params::zabbix_version and $additional_service_params == $zabbix::params::additional_service_params {
$real_additional_service_params = versioncmp($zabbix_version, '3.0') ? {
1 => '--foreground',
0 => '--foreground',
-1 => '',
}
} else {
$real_additional_service_params = $additional_service_params
}
if $zabbix_version != $zabbix::params::zabbix_version and $service_type == $zabbix::params::service_type {
$real_service_type = versioncmp($zabbix_version, '3.0') ? {
1 => 'simple',
0 => 'simple',
-1 => 'forking',
}
} else {
$real_service_type = $service_type
}
# Find if listenip is set. If not, we can set to specific ip or
# to network name. If more than 1 interfaces are available, we
# can find the ipaddress of this specific interface if listenip
# is set to for example "eth1" or "bond0.73".
$listen_ip = $listenip ? {
/^(e|lo|bond|lxc|tap|tun|virbr).*/ => fact("networking.interfaces.${listenip}.ip"),
'*' => undef,
default => $listenip,
}
# 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 {
if $monitored_by_proxy != '' {
$use_proxy = $monitored_by_proxy
} else {
$use_proxy = ''
}
class { 'zabbix::resources::agent':
hostname => $facts['fqdn'],
ipaddress => $listen_ip,
use_ip => $agent_use_ip,
port => $listenport,
group => $zbx_group,
group_create => $zbx_group_create,
templates => $zbx_templates,
proxy => $use_proxy,
}
}
# 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,
}
}
# Installing the package
package { $zabbix_package_agent:
ensure => $zabbix_package_state,
require => Class['zabbix::repo'],
tag => 'zabbix',
}
# Ensure that the correct config file is used.
zabbix::startup {$servicename:
pidfile => $pidfile,
agent_configfile_path => $agent_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
service_type => $real_service_type,
service_name => 'zabbix-agent',
require => Package[$zabbix_package_agent],
}
if $agent_configfile_path != '/etc/zabbix/zabbix_agentd.conf' {
file { '/etc/zabbix/zabbix_agentd.conf':
ensure => absent,
require => Package[$zabbix_package_agent],
}
}
# Controlling the 'zabbix-agent' service
if str2bool(getvar('::systemd')) {
$service_provider = 'systemd'
} else {
$service_provider = undef
}
service { $servicename:
ensure => running,
enable => true,
provider => $service_provider,
hasstatus => true,
hasrestart => true,
require => Package[$zabbix_package_agent],
}
# Configuring the zabbix-agent configuration file
file { $agent_configfile_path:
ensure => present,
owner => $agent_config_owner,
group => $agent_config_group,
mode => '0644',
notify => Service[$servicename],
require => Package[$zabbix_package_agent],
replace => true,
content => template('zabbix/zabbix_agentd.conf.erb'),
}
# Include dir for specific zabbix-agent checks.
file { $include_dir:
ensure => directory,
owner => $agent_config_owner,
group => $agent_config_group,
recurse => true,
purge => $include_dir_purge,
notify => Service[$servicename],
require => File[$agent_configfile_path],
}
# Manage firewall
if $manage_firewall {
firewall { '150 zabbix-agent':
dport => $listenport,
proto => 'tcp',
action => 'accept',
source => $server,
state => [
'NEW',
'RELATED',
'ESTABLISHED'],
}
}
# the agent doesn't work perfectly fine with selinux
# https://support.zabbix.com/browse/ZBX-11631
if $facts['selinux'] == true and $manage_selinux {
selinux::module{'zabbix-agent':
ensure => 'present',
content_te => template('zabbix/selinux/zabbix-agent.te.erb'),
before => Service[$servicename],
}
}
}
|