From 8b86deae5e591d7199d3fc50166b8f59ba4c0174 Mon Sep 17 00:00:00 2001 From: D0298630 Date: Wed, 14 Aug 2024 09:50:46 +0200 Subject: [PATCH] Add configuration parameters to Server and Agent - Server: - making StartHistoryPollers configurable - adding TrendFunctionCacheSize parameter to config file - Agent: - adding controlsocket and persistantbuffer parameters --- REFERENCE.md | 63 ++++++++++++++++++++++++++++++++ manifests/agent.pp | 10 +++++ manifests/params.pp | 7 ++++ manifests/server.pp | 4 ++ spec/classes/agent_spec.rb | 10 ++++- spec/classes/server_spec.rb | 13 +++++++ templates/zabbix_agentd.conf.erb | 38 +++++++++++++++++++ templates/zabbix_server.conf.erb | 11 +++++- 8 files changed, 153 insertions(+), 3 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 92e260d7..954fe682 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1391,6 +1391,7 @@ The following parameters are available in the `zabbix::agent` class: * [`server`](#-zabbix--agent--server) * [`listenport`](#-zabbix--agent--listenport) * [`listenip`](#-zabbix--agent--listenip) +* [`statusport`](#-zabbix--agent--statusport) * [`startagents`](#-zabbix--agent--startagents) * [`serveractive`](#-zabbix--agent--serveractive) * [`service_ensure`](#-zabbix--agent--service_ensure) @@ -1404,6 +1405,9 @@ The following parameters are available in the `zabbix::agent` class: * [`refreshactivechecks`](#-zabbix--agent--refreshactivechecks) * [`buffersend`](#-zabbix--agent--buffersend) * [`buffersize`](#-zabbix--agent--buffersize) +* [`enablepersistentbuffer`](#-zabbix--agent--enablepersistentbuffer) +* [`persistentbufferperiod`](#-zabbix--agent--persistentbufferperiod) +* [`persistentbufferfile`](#-zabbix--agent--persistentbufferfile) * [`maxlinespersecond`](#-zabbix--agent--maxlinespersecond) * [`allowroot`](#-zabbix--agent--allowroot) * [`zabbix_user`](#-zabbix--agent--zabbix_user) @@ -1438,6 +1442,7 @@ The following parameters are available in the `zabbix::agent` class: * [`include_dir_purge`](#-zabbix--agent--include_dir_purge) * [`unsafeuserparameters`](#-zabbix--agent--unsafeuserparameters) * [`userparameter`](#-zabbix--agent--userparameter) +* [`controlsocket`](#-zabbix--agent--controlsocket) * [`loadmodulepath`](#-zabbix--agent--loadmodulepath) * [`loadmodule`](#-zabbix--agent--loadmodule) * [`manage_startup_script`](#-zabbix--agent--manage_startup_script) @@ -1712,6 +1717,14 @@ if more than 1 interface is on the server. Default value: `$zabbix::params::agent_listenip` +##### `statusport` + +Data type: `Optional[Integer]` + +Agent will listen on this port for HTTP status requests. + +Default value: `$zabbix::params::agent_statusport` + ##### `startagents` Data type: `Any` @@ -1818,6 +1831,30 @@ Maximum number of values in a memory buffer. Default value: `$zabbix::params::agent_buffersize` +##### `enablepersistentbuffer` + +Data type: `Optional[Integer[0,1]]` + +Use persistent buffer (set to 1), or in-memory buffer is used (default). + +Default value: `$zabbix::params::agent_enablepersistentbuffer` + +##### `persistentbufferperiod` + +Data type: `Optional[String[1]]` + +Zabbix Agent2 will keep data for this time period in case of no connectivity with Zabbix server or proxy. + +Default value: `$zabbix::params::agent_persistentbufferperiod` + +##### `persistentbufferfile` + +Data type: `Optional[Stdlib::Absolutepath]` + +Full filename. Zabbix Agent2 will keep SQLite database in this file. + +Default value: `$zabbix::params::agent_persistentbufferfile` + ##### `maxlinespersecond` Data type: `Any` @@ -2096,6 +2133,14 @@ User-defined parameter to monitor. Default value: `$zabbix::params::agent_userparameter` +##### `controlsocket` + +Data type: `Optional[Stdlib::Absolutepath]` + +The control socket, used to send runtime commands with '-R' option. + +Default value: `$zabbix::params::agent_controlsocket` + ##### `loadmodulepath` Data type: `Optional[String[1]]` @@ -3986,6 +4031,7 @@ The following parameters are available in the `zabbix::server` class: * [`startalerters`](#-zabbix--server--startalerters) * [`startdiscoverers`](#-zabbix--server--startdiscoverers) * [`startescalators`](#-zabbix--server--startescalators) +* [`starthistorypollers`](#-zabbix--server--starthistorypollers) * [`starthttppollers`](#-zabbix--server--starthttppollers) * [`starttimers`](#-zabbix--server--starttimers) * [`javagateway`](#-zabbix--server--javagateway) @@ -4012,6 +4058,7 @@ The following parameters are available in the `zabbix::server` class: * [`historycachesize`](#-zabbix--server--historycachesize) * [`historyindexcachesize`](#-zabbix--server--historyindexcachesize) * [`trendcachesize`](#-zabbix--server--trendcachesize) +* [`trendfunctioncachesize`](#-zabbix--server--trendfunctioncachesize) * [`valuecachesize`](#-zabbix--server--valuecachesize) * [`timeout`](#-zabbix--server--timeout) * [`tlscafile`](#-zabbix--server--tlscafile) @@ -4422,6 +4469,14 @@ Number of pre-forked instances of escalators. Default value: `$zabbix::params::server_startescalators` +##### `starthistorypollers` + +Data type: `Optional[Integer[0, 100]]` + +Number of pre-forked instances of history pollers. + +Default value: `$zabbix::params::server_starthistorypollers` + ##### `starthttppollers` Data type: `Any` @@ -4636,6 +4691,14 @@ Size of trend cache, in bytes. Default value: `$zabbix::params::server_trendcachesize` +##### `trendfunctioncachesize` + +Data type: `Optional[String[1]]` + +Size of trend function cache, in bytes. + +Default value: `$zabbix::params::server_trendfunctioncachesize` + ##### `valuecachesize` Data type: `Any` diff --git a/manifests/agent.pp b/manifests/agent.pp index 9db33a8e..edcd1c1b 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -53,6 +53,7 @@ # It will find out which ip is configured for this ipaddress. Can be handy # if more than 1 interface is on the server. # +# @param statusport Agent will listen on this port for HTTP status requests. # @param startagents Number of pre-forked instances of zabbix_agentd that process passive checks. # @param serveractive List of comma delimited ip:port (or hostname:port) pairs of zabbix servers for active checks. # @param 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) @@ -70,6 +71,9 @@ # @param refreshactivechecks How often list of active checks is refreshed, in seconds. # @param buffersend Do not keep data longer than n seconds in buffer. # @param buffersize Maximum number of values in a memory buffer. +# @param enablepersistentbuffer Use persistent buffer (set to 1), or in-memory buffer is used (default). +# @param persistentbufferperiod Zabbix Agent2 will keep data for this time period in case of no connectivity with Zabbix server or proxy. +# @param persistentbufferfile Full filename. Zabbix Agent2 will keep SQLite database in this file. # @param maxlinespersecond Maximum number of new lines the agent will send per second to zabbix server or proxy processing. # @param allowroot Allow the agent to run as 'root'. # @param zabbix_user Drop privileges to a specific, existing user on the system. Only has effect if run as 'root' and AllowRoot is disabled. @@ -116,6 +120,7 @@ # @param include_dir_purge Include dir to purge. # @param unsafeuserparameters Allow all characters to be passed in arguments to user-defined parameters. # @param userparameter User-defined parameter to monitor. +# @param controlsocket The control socket, used to send runtime commands with '-R' option. # @param loadmodulepath Full path to location of agent modules. # @param loadmodule Module to load at agent startup. # @param manage_startup_script @@ -179,6 +184,7 @@ $server = $zabbix::params::agent_server, $listenport = $zabbix::params::agent_listenport, $listenip = $zabbix::params::agent_listenip, + Optional[Integer] $statusport = $zabbix::params::agent_statusport, $startagents = $zabbix::params::agent_startagents, $serveractive = $zabbix::params::agent_serveractive, Stdlib::Ensure::Service $service_ensure = $zabbix::params::agent_service_ensure, @@ -192,6 +198,9 @@ $refreshactivechecks = $zabbix::params::agent_refreshactivechecks, $buffersend = $zabbix::params::agent_buffersend, $buffersize = $zabbix::params::agent_buffersize, + Optional[Integer[0,1]] $enablepersistentbuffer = $zabbix::params::agent_enablepersistentbuffer, + Optional[Stdlib::Absolutepath] $persistentbufferfile = $zabbix::params::agent_persistentbufferfile, + Optional[String[1]] $persistentbufferperiod = $zabbix::params::agent_persistentbufferperiod, $maxlinespersecond = $zabbix::params::agent_maxlinespersecond, Optional[Array] $zabbix_alias = $zabbix::params::agent_zabbix_alias, $timeout = $zabbix::params::agent_timeout, @@ -201,6 +210,7 @@ $include_dir_purge = $zabbix::params::agent_include_purge, $unsafeuserparameters = $zabbix::params::agent_unsafeuserparameters, $userparameter = $zabbix::params::agent_userparameter, + Optional[Stdlib::Absolutepath] $controlsocket = $zabbix::params::agent_controlsocket, Optional[String[1]] $loadmodulepath = $zabbix::params::agent_loadmodulepath, $loadmodule = $zabbix::params::agent_loadmodule, Optional[Variant[Array[Enum['unencrypted','psk','cert']],Enum['unencrypted','psk','cert']]] $tlsaccept = $zabbix::params::agent_tlsaccept, diff --git a/manifests/params.pp b/manifests/params.pp index 9e671857..ae61c3f5 100755 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -245,6 +245,7 @@ $server_startalerters = 3 $server_startdiscoverers = '1' $server_startescalators = 1 + $server_starthistorypollers = 5 $server_starthttppollers = '1' $server_startipmipollers = '0' $server_startjavapollers = '5' @@ -280,6 +281,7 @@ $server_tmpdir = '/tmp' $server_trappertimeout = '300' $server_trendcachesize = '4M' + $server_trendfunctioncachesize = undef $server_unavailabledelay = '60' $server_unreachabledelay = '15' $server_unreachableperiod = '45' @@ -298,9 +300,11 @@ $agent_allowroot = '0' $agent_buffersend = '5' $agent_buffersize = '100' + $agent_controlsocket = undef $agent_debuglevel = '3' $agent_allowkey = undef $agent_denykey = undef + $agent_enablepersistentbuffer = undef $agent_enableremotecommands = '0' $agent_hostmetadata = undef $agent_hostmetadataitem = undef @@ -311,9 +315,12 @@ $agent_include_purge = true $agent_listenip = undef $agent_listenport = '10050' + $agent_statusport = undef $agent_loadmodule = undef $agent_logremotecommands = '0' $agent_maxlinespersecond = '100' + $agent_persistentbufferfile = undef + $agent_persistentbufferperiod = undef $agent_refreshactivechecks = '120' $agent_server = '127.0.0.1' $agent_serveractive = undef diff --git a/manifests/server.pp b/manifests/server.pp index 1aea8780..74d0b054 100755 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -57,6 +57,7 @@ # @param startalerters Number of pre-forked instances of alerters. # @param startdiscoverers Number of pre-forked instances of discoverers. # @param startescalators Number of pre-forked instances of escalators. +# @param starthistorypollers Number of pre-forked instances of history pollers. # @param starthttppollers Number of pre-forked instances of http pollers. # @param starttimers Number of pre-forked instances of timers. # @param javagateway IP address (or hostname) of zabbix java gateway. @@ -91,6 +92,7 @@ # @param historycachesize Size of history cache, in bytes. # @param historyindexcachesize Size of history index cache, in bytes. # @param trendcachesize Size of trend cache, in bytes. +# @param trendfunctioncachesize Size of trend function cache, in bytes. # @param valuecachesize Size of history value cache, in bytes. # @param timeout Specifies how long we wait for agent, snmp device or external check (in seconds). # @param tlscafile Full pathname of a file containing the top-level CA(s) certificates for peer certificate verification. @@ -214,6 +216,7 @@ Integer[1, 100] $startalerters = $zabbix::params::server_startalerters, $startdiscoverers = $zabbix::params::server_startdiscoverers, Integer[1, 100] $startescalators = $zabbix::params::server_startescalators, + Optional[Integer[0, 100]] $starthistorypollers = $zabbix::params::server_starthistorypollers, $starthttppollers = $zabbix::params::server_starthttppollers, $starttimers = $zabbix::params::server_starttimers, $javagateway = $zabbix::params::server_javagateway, @@ -239,6 +242,7 @@ $historycachesize = $zabbix::params::server_historycachesize, $historyindexcachesize = $zabbix::params::server_historyindexcachesize, $trendcachesize = $zabbix::params::server_trendcachesize, + Optional[String[1]] $trendfunctioncachesize = $zabbix::params::server_trendfunctioncachesize, $valuecachesize = $zabbix::params::server_valuecachesize, $timeout = $zabbix::params::server_timeout, $tlscafile = $zabbix::params::server_tlscafile, diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 1f23d224..b128c8af 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -292,6 +292,7 @@ agent_configfile_path: '/etc/zabbix/zabbix_agentd.conf', buffersend: '5', buffersize: '100', + controlsocket: '/tmp/agent.sock', debuglevel: '4', allowkey: 'system.run[*]', denykey: 'system.run[*]', @@ -334,6 +335,7 @@ it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ControlSocket=/tmp/agent.sock$} } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowKey=system.run\[\*\]$} } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DenyKey=system.run\[\*\]$} } @@ -499,7 +501,9 @@ maxlinespersecond: 1, allowroot: 1, zabbix_user: 'root', loadmodulepath: '/tmp', allowkey: 'system.run[*]', denykey: 'system.run[*]', enableremotecommands: 1, - logremotecommands: 1 + logremotecommands: 1, enablepersistentbuffer: 1, + persistentbufferfile: '/var/lib/zabbix/zabbix_agent2.zbxtmp', + persistentbufferperiod: '1h', } end @@ -509,7 +513,9 @@ is_expected.not_to contain_file(config_path).with_content( %r{^(LogRemoteCommands|StartAgents|MaxLinesPerSecond |AllowRoot|User|LoadModulePath| - EnableRemoteCommands|LogRemoteCommands)} + EnableRemoteCommands|LogRemoteCommands| + EnablePersistentBuffer|PersistentBufferFile| + PersistentBufferPeriod)} ) end end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 05ba1ccc..37573d26 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -261,6 +261,7 @@ tmpdir: '/tmp', trappertimeout: '30', trendcachesize: '4M', + trendfunctioncachesize: '4M', unavailabledelay: '30', unreachabledelay: '30', unreachableperiod: '30', @@ -338,6 +339,7 @@ it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TmpDir=/tmp} } it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrapperTimeout=30} } it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendCacheSize=4M} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendFunctionCacheSize=4M} } it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnavailableDelay=30} } it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachableDelay=30} } it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachablePeriod=30} } @@ -352,6 +354,17 @@ it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCipherAll13=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128:kECDHEPSK\+AES128:kPSK\+AES128$} } end + context 'with zabbix_server.conf and version 7.0' do + let :params do + { + starthistorypollers: 5, + zabbix_version: '7.0' + } + end + + it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartHistoryPollers=5} } + end + context 'with zabbix_server.conf and version 5.0' do next if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '9' diff --git a/templates/zabbix_agentd.conf.erb b/templates/zabbix_agentd.conf.erb index d4d509db..a357ebb6 100644 --- a/templates/zabbix_agentd.conf.erb +++ b/templates/zabbix_agentd.conf.erb @@ -126,6 +126,13 @@ ListenPort=<%= @listenport %> # Mandatory: no <% if @listen_ip %>ListenIP=<%= @listen_ip %><% end %> +### Option: StatusPort +# Agent will listen on this port for HTTP status requests. +# +# Mandatory: no +# Range: 1024-32767 +<% if @statusport %>StatusPort=<%= @statusport %><% end %> + <% unless @agent2 %> ### Option: StartAgents # Number of pre-forked instances of zabbix_agentd that process passive checks. @@ -241,6 +248,31 @@ BufferSend=<%= @buffersend %> # Range: 2-65535 BufferSize=<%= @buffersize %> +### Option: EnablePersistentBuffer: +# 0 - disabled, in-memory buffer is used (default); +# 1 - use persistent buffer +# Mandatory: no +# Range: 0-1 +<% if @enablepersistentbuffer %>EnablePersistentBuffer=<%= @enablepersistentbuffer %><% end %> + +<% unless @enablepersistentbuffer %> +### Option: PersistentBufferPeriod +# Zabbix Agent2 will keep data for this time period in case of no +# connectivity with Zabbix server or proxy. Older data will be lost. Log data will be preserved. +# Option is valid if EnablePersistentBuffer=1 +# +# Mandatory: no +# Range: 1m-365d +<% if @persistentbufferperiod %>PersistentBufferPeriod=<%= @persistentbufferperiod %><% end %> + +### Option: PersistentBufferFile +# full filename. Zabbix Agent2 will keep SQLite database in this file +# Option is valid if EnablePersistentBuffer=1 +# +# Mandatory: no +<% if @persistentbufferfile %>PersistentBufferFile=<%= @persistentbufferfile %><% end %> + +<% end %> <% unless @agent2 %> ### Option: MaxLinesPerSecond # Maximum number of new lines the agent will send per second to Zabbix Server @@ -326,6 +358,12 @@ UnsafeUserParameters=<%= @unsafeuserparameters %> # # Disabled. A configuration file should be placed on directory: <%= @include %> +### Option: ControlSocket +# The control socket, used to send runtime commands with '-R' option. +# +# Mandatory: no +<% if @controlsocket %>ControlSocket=<%= @controlsocket %><% end %> + ####### LOADABLE MODULES ####### <% if @kernel != 'windows' and !@agent2 %> ### Option: LoadModulePath diff --git a/templates/zabbix_server.conf.erb b/templates/zabbix_server.conf.erb index 9aaba7fd..0b21f077 100755 --- a/templates/zabbix_server.conf.erb +++ b/templates/zabbix_server.conf.erb @@ -251,6 +251,7 @@ StartPollersUnreachable=<%= @startpollersunreachable %> # Range: 0-1000 # Default: # StartHistoryPollers=5 +<% if @starthistorypollers %>StartHistoryPollers=<%= @starthistorypollers %><% end %> <% end %> <% if @zabbix_version.to_f >= 6.0 %> @@ -472,6 +473,14 @@ HistoryCacheSize=<%= @historycachesize %> # Range: 128K-2G TrendCacheSize=<%= @trendcachesize %> +### Option: TrendFunctionCacheSize +# Size of trend function cache, in bytes. +# Shared memory size for caching calculated trend function data +# +# Mandatory: no +# Range: 128K-2G +<% if @trendfunctioncachesize %>TrendFunctionCacheSize=<%= @trendfunctioncachesize %><% end %> + ### Option: ValueCacheSize # Size of history value cache, in bytes. # Shared memory size for caching item history data requests. @@ -1017,4 +1026,4 @@ LoadModulePath=<%= @loadmodulepath %> # Default: # StartBrowserPollers=1 -<% end %> \ No newline at end of file +<% end %>