-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
agent.pp
499 lines (483 loc) · 19 KB
/
agent.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# == Class: zabbix::agent
#
# This will install and configure the zabbix-agent deamon
#
# === Requirements
#
# If 'manage_resources' is set to true, you'll need to configure
# storeconfigs/exported resources.
#
# Otherwise no requirements.
#
# === Parameters
#
# [*zabbix_version*]
# This is the zabbix version.
#
# [*zabbix_package_state*]
# The state of the package that needs to be installed: present or latest.
# Default: present
#
# [*zabbix_package_agent*]
# The name of the agent package that we manage
#
# [*manage_firewall*]
# When true, it will create iptables rules.
#
# [*manage_repo*]
# When true, it will create repository for installing the agent.
#
# [*manage_choco*]
# When true on windows, it will use chocolatey to install the agent.
# The module chocolatey is required https://forge.puppet.com/puppetlabs/chocolatey.
#
# [*zabbix_package_provider*]
# Which package's provider to use to install the agent.
# It is undef for all linux os and set to 'chocolatey' on windows.
#
# [*manage_resources*]
# When true, it will export resources to something like puppetdb.
# When set to true, you'll need to configure 'storeconfigs' to make
# this happen. Default is set to false, as not everyone has this
# enabled.
#
# [*monitored_by_proxy*]
# When this is monitored by an proxy, please fill in the name of this proxy.
# If the proxy is also installed via this module, please fill in the FQDN
#
# [*agent_use_ip*]
# When true, when creating hosts via the zabbix-api, it will configure that
# connection should me made via ip, not fqdn.
#
# [*zbx_group*]
# Deprecated! Name of the hostgroup where this host needs to be added.
#
# [*zbx_groups*]
# An array of hostgroups where this host needs to be added.
#
# [*zbx_templates*]
# List of templates which will be added when host is configured.
#
# [*zbx_macros*]
# List of macros which will be added when host is configured.
#
# [*agent_configfile_path*]
# Agent config file path defaults to /etc/zabbix/zabbix_agentd.conf
#
# [*pidfile*]
# Name of pid file.
#
# [*logfile*]
# Name of log file.
#
# [*logfilesize*]
# Maximum size of log file in MB.
#
# [*debuglevel*]
# Specifies debug level.
#
# [*sourceip*]
# Source ip address for outgoing connections.
#
# [*enableremotecommands*]
# Whether remote commands from zabbix server are allowed.
#
# [*logremotecommands*]
# Enable logging of executed shell commands as warnings.
#
# [*server*]
# List of comma delimited ip addresses (or hostnames) of zabbix servers.
#
# [*listenport*]
# Agent will listen on this port for connections from the server.
#
# [*listenip*]
# List of comma delimited ip addresses that the agent should listen on.
# You can also specify which network interface it should listen on.
#
# Example:
# listenip => 'eth0', or
# listenip => 'bond0.73',
#
# It will find out which ip is configured for this ipaddress. Can be handy
# if more than 1 interface is on the server.
#
# [*startagents*]
# Number of pre-forked instances of zabbix_agentd that process passive checks.
#
# [*serveractive*]
# List of comma delimited ip:port (or hostname:port) pairs of zabbix servers for active checks.
#
# [*service_ensure*]
# Start / stop the agent service. E.g. to preconfigure a hosts agent and turn on the service
# at a later time (when the server reaches production SLA)
# Default: 'running'
#
# [*service_enable*]
# Automatically start the agent on system boot
# Default: true
#
# [*hostname*]
# Unique, case sensitive hostname.
#
# [*hostnameitem*]
# Item used for generating hostname if it is undefined.
#
# [*hostmetadata*]
# Optional parameter that defines host metadata.
#
# [*hostmetadataitem*]
# Optional parameter that defines an item used for getting host metadata.
#
# [*hostinterface*]
# Optional parameter that defines host metadata. Host metadata is used only at host
# auto-registration process (active agent).
#
# [*hostinterfaceitem*]
# Optional parameter that defines an item used for getting host interface.
# Host interface is used at host auto-registration process.
#
# [*refreshactivechecks*]
# How often list of active checks is refreshed, in seconds.
#
# [*buffersend*]
# Do not keep data longer than n seconds in buffer.
#
# [*buffersize*]
# Maximum number of values in a memory buffer.
#
# [*maxlinespersecond*]
# Maximum number of new lines the agent will send per second to zabbix server
# or proxy processing.
#
# [*allowroot*]
# Allow the agent to run as 'root'.
#
# [*zabbix_user*]
# Drop privileges to a specific, existing user on the system.
# Only has effect if run as 'root' and AllowRoot is disabled.
#
# [*zabbix_alias*]
# Sets an alias for parameter.
#
# [*timeout*]
# Spend no more than timeout seconds on processing.
#
# [*tlsaccept*]
# What incoming connections to accept from Zabbix server. Used for a passive proxy, ignored on an active proxy.
#
# [*tlscafile*]
# Full pathname of a file containing the top-level CA(s) certificates for peer certificate verification.
#
# [*tlscertfile*]
# Full pathname of a file containing the proxy certificate or certificate chain.
#
# [*tlsconnect*]
# How the proxy should connect to Zabbix server. Used for an active proxy, ignored on a passive proxy.
#
# [*tlscrlfile*]
# Full pathname of a file containing revoked certificates.
#
# [*tlskeyfile*]
# Full pathname of a file containing the proxy private key.
#
# [*tlspskfile*]
# Full pathname of a file containing the pre-shared key.
#
# [*tlspskidentity*]
# Unique, case sensitive string used to identify the pre-shared key.
#
# [*tlsservercertissuer*]
# Allowed server certificate issuer.
#
# [*tlsservercertsubject*]
# Allowed server certificate subject.
#
# [*include_dir*]
# You may include individual files or all files in a directory in the configuration file.
#
# [*unsafeuserparameters*]
# Allow all characters to be passed in arguments to user-defined parameters.
#
# [*userparameter*]
# User-defined parameter to monitor.
#
# [*loadmodulepath*]
# Full path to location of agent modules.
#
# [*loadmodule*]
# Module to load at agent startup.
#
# [*manage_startup_script*]
# If the init script should be managed by this module. Attention: This might
# cause problems with some config options of this module (e.g
# agent_configfile_path)
#
# === Example
#
# Basic installation:
# class { 'zabbix::agent':
# zabbix_version => '2.2',
# server => '192.168.1.1',
# }
#
# Exported resources:
# class { 'zabbix::agent':
# manage_resources => true,
# monitored_by_proxy => 'my_proxy_host',
# server => '192.168.1.1',
# }
#
# === Authors
#
# Author Name: [email protected]
#
# === Copyright
#
# Copyright 2014 Werner Dijkerman
#
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,
Optional[String[1]] $zabbix_package_provider = $zabbix::params::zabbix_package_provider,
Boolean $manage_choco = $zabbix::params::manage_choco,
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,
Variant[String[1],Array[String[1]]] $zbx_groups = $zabbix::params::agent_zbx_groups,
$zbx_group_create = $zabbix::params::agent_zbx_group_create,
$zbx_templates = $zabbix::params::agent_zbx_templates,
Array[Hash] $zbx_macros = [],
$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,
Stdlib::Ensure::Service $service_ensure = $zabbix::params::agent_service_ensure,
Boolean $service_enable = $zabbix::params::agent_service_enable,
$hostname = $zabbix::params::agent_hostname,
$hostnameitem = $zabbix::params::agent_hostnameitem,
$hostmetadata = $zabbix::params::agent_hostmetadata,
$hostmetadataitem = $zabbix::params::agent_hostmetadataitem,
Optional[Stdlib::Fqdn] $hostinterface = $zabbix::params::agent_hostinterface,
Optional[Stdlib::Fqdn] $hostinterfaceitem = $zabbix::params::agent_hostinterfaceitem,
$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,
Optional[String[1]] $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,
Optional[String[1]] $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,
Optional[String[1]] $agent_config_owner = $zabbix::params::agent_config_owner,
Optional[String[1]] $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,
Boolean $manage_startup_script = $zabbix::params::manage_startup_script,
) 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 {
# Migrate deprecated zbx_group parameter
if $zbx_group == $zabbix::params::agent_zbx_group and $zbx_groups == $zabbix::params::agent_zbx_groups {
$groups = $zabbix::params::agent_zbx_groups
} else {
if $zbx_group != $zabbix::params::agent_zbx_group and $zbx_groups != $zabbix::params::agent_zbx_groups {
fail("Seems like you have filled zbx_group and zbx_groups with custom values. This isn't support! Please use zbx_groups only.")
}
if $zbx_group != $zabbix::params::agent_zbx_group {
warning('Passing zbx_group to zabbix::agent is deprecated and will be removed. Use zbx_groups instead.')
$groups = Array($zbx_group)
} else {
$groups = $zbx_groups
}
}
if $monitored_by_proxy != '' {
$use_proxy = $monitored_by_proxy
} else {
$use_proxy = ''
}
$_hostname = pick($hostname, $facts['networking']['fqdn'])
class { 'zabbix::resources::agent':
hostname => $_hostname,
ipaddress => $listen_ip,
use_ip => $agent_use_ip,
port => $listenport,
groups => [$groups].flatten(),
group_create => $zbx_group_create,
templates => $zbx_templates,
macros => $zbx_macros,
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,
}
}
if $facts['kernel'] == 'windows' and $manage_choco {
package { $zabbix_package_agent:
ensure => $zabbix_version,
provider => $zabbix_package_provider,
tag => 'zabbix',
}
}
else {
# Installing the package
package { $zabbix_package_agent:
ensure => $zabbix_package_state,
require => Class['zabbix::repo'],
tag => 'zabbix',
provider => $zabbix_package_provider,
}
}
# Ensure that the correct config file is used.
if $manage_startup_script {
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' and $facts['kernel'] != 'windows' {
file { '/etc/zabbix/zabbix_agentd.conf':
ensure => absent,
require => Package[$zabbix_package_agent],
}
}
# Controlling the 'zabbix-agent' service
service { $servicename:
ensure => $service_ensure,
enable => $service_enable,
require => Package[$zabbix_package_agent],
}
# Override the service provider on AIX
# Doing it this way allows overriding it on other platforms
if $facts['os']['name'] == 'AIX' {
Service[$servicename] {
service_provider => 'init',
service_path => '/etc/rc.d/init.d',
}
}
# Configuring the zabbix-agent configuration file
file { $agent_configfile_path:
ensure => file,
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 {
$servers = split($server, ',')
$servers.each |$_server| {
firewall { "150 zabbix-agent from ${_server}":
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 fact('os.selinux.enabled') == true and $manage_selinux {
selinux::module { 'zabbix-agent':
ensure => 'present',
content_te => template('zabbix/selinux/zabbix-agent.te.erb'),
before => Service[$servicename],
}
}
}