Skip to content

Commit e4bdc34

Browse files
committed
Add parameter and default for Option SocketDir
Added the parameter socketdir to be able to override Option SocketDir in both zabbix_server.conf and zabbix_proxy.conf via an ENC (such as Foreman). It was added in zabbix_server.conf for completeness, however, in Zabbix 5.0 the proxy service creates a Unix socket for preprocessing called zabbix_proxy_preprocessing.sock. In the default location, /tmp, SELinux violations on creating the socket prevented the zabbix-proxy service from starting in my deployment on CentOS 7. My workaround was to override SocketDir, which was added to zabbix_proxy.conf in 5.0, to change the directory that this socket is created in from the default to /var/run/zabbix. Because it only exists when the service is running, /var/run seemed the appropriate place, and /var/run/zabbix already existed and had appropriate SELinux labels due to the agent and proxy PID files. To resolve this issue without explicitly setting the parameter, I set the default for socketdir within zabbix::proxy to be /var/run/zabbix if zabbix_version is >= 5.0. That seems a safe and sane enough default that works when both SELinux is enabled or disabled so that it's not necessary to do a boolean and comparison against both zabbix_version and facts('os.selinux.enabled').
1 parent 75e975b commit e4bdc34

File tree

8 files changed

+61
-0
lines changed

8 files changed

+61
-0
lines changed

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
$include_dir = $zabbix::params::server_include,
177177
$loadmodulepath = $zabbix::params::server_loadmodulepath,
178178
$loadmodule = $zabbix::params::server_loadmodule,
179+
Stdlib::Absolutepath $socketdir = $zabbix::params::server_socketdir,
179180
Boolean $manage_selinux = $zabbix::params::manage_selinux,
180181
String $additional_service_params = $zabbix::params::additional_service_params,
181182
Optional[String[1]] $zabbix_user = $zabbix::params::server_zabbix_user,

manifests/params.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
$server_vmwarecachesize = '8M'
285285
$server_vmwarefrequency = '60'
286286
$server_vmwaretimeout = undef
287+
$server_socketdir = '/tmp'
287288

288289
# Agent specific params
289290
$agent_allowroot = '0'
@@ -425,6 +426,10 @@
425426
$proxy_zabbix_server_host = undef
426427
$proxy_zabbix_server_port = '10051'
427428
$proxy_zbx_templates = ['Template App Zabbix Proxy']
429+
$proxy_socketdir = versioncmp($zabbix_version, '5.0') ? {
430+
-1 => '/tmp',
431+
default => '/var/run/zabbix',
432+
}
428433

429434
# Java Gateway specific params
430435
$javagateway_listenip = '0.0.0.0'

manifests/proxy.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@
264264
# [*loadmodule*]
265265
# Module to load at server startup.
266266
#
267+
# [*socketdir*]
268+
# IPC socket directory.
269+
# Directory to store IPC sockets used by internal Zabbix services.
270+
#
267271
# === Example
268272
#
269273
# When you want to run everything on one machine, you can use the following
@@ -423,6 +427,7 @@
423427
$loadmodulepath = $zabbix::params::proxy_loadmodulepath,
424428
$loadmodule = $zabbix::params::proxy_loadmodule,
425429
Boolean $manage_selinux = $zabbix::params::manage_selinux,
430+
Stdlib::Absolutepath $socketdir = $zabbix::params::proxy_socketdir,
426431
) inherits zabbix::params {
427432
# check osfamily, Arch is currently not supported for web
428433
if $facts['os']['family'] == 'Archlinux' {

manifests/server.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@
261261
# [*manage_startup_script*]
262262
# If the init script should be managed by this module. Attention: This might cause problems with some config options of this module (e.g server_configfile_path)
263263
#
264+
# [*socketdir*]
265+
# IPC socket directory.
266+
# Directory to store IPC sockets used by internal Zabbix services.
267+
#
264268
# === Example
265269
#
266270
# When running everything on a single node, please check
@@ -383,6 +387,7 @@
383387
String $additional_service_params = $zabbix::params::additional_service_params,
384388
Optional[String[1]] $zabbix_user = $zabbix::params::server_zabbix_user,
385389
Boolean $manage_startup_script = $zabbix::params::manage_startup_script,
390+
Stdlib::Absolutepath $socketdir = $zabbix::params::server_socketdir,
386391
) inherits zabbix::params {
387392
# the following codeblock is a bit blargh. The correct default value for
388393
# $real_additional_service_params changes based on the value of $zabbix_version

spec/classes/proxy_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,17 @@
367367
it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^EnableRemoteCommands=1$} }
368368
it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogRemoteCommands=1$} }
369369
end
370+
371+
context 'with zabbix_proxy.conf and version 5.0' do
372+
let :params do
373+
{
374+
socketdir: '/var/run/zabbix',
375+
zabbix_version: '5.0'
376+
}
377+
end
378+
379+
it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SocketDir=/var/run/zabbix} }
380+
end
370381
end
371382
end
372383
end

spec/classes/server_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@
385385
it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryIndexCacheSize=4M} }
386386
end
387387

388+
context 'with zabbix_server.conf and version 5.0' do
389+
let :params do
390+
{
391+
socketdir: '/var/run/zabbix',
392+
zabbix_version: '5.0'
393+
}
394+
end
395+
396+
it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SocketDir=/var/run/zabbix} }
397+
end
398+
388399
context 'with zabbix_server.conf and system as logtype' do
389400
let :params do
390401
{

templates/zabbix_proxy.conf.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ DebugLevel=<%= @debuglevel %>
9595
#
9696
PidFile=<%= @pidfile %>
9797

98+
<% if @zabbix_version.to_f >= 5.0 %>
99+
### Option: SocketDir
100+
# IPC socket directory.
101+
# Directory to store IPC sockets used by internal Zabbix services.
102+
#
103+
# Mandatory: no
104+
# Default:
105+
106+
SocketDir=<%= @socket_dir %>
107+
<% end %>
108+
98109
### Option: DBHost
99110
# Database host name.
100111
# If set to localhost, socket is used for MySQL.

templates/zabbix_server.conf.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ DebugLevel=<%= @debuglevel %>
7777
#
7878
PidFile=<%= @pidfile %>
7979

80+
<% if @zabbix_version.to_f >= 3.4 %>
81+
### Option: SocketDir
82+
# IPC socket directory.
83+
# Directory to store IPC sockets used by internal Zabbix services.
84+
#
85+
# Mandatory: no
86+
# Default:
87+
88+
SocketDir=<%= @socket_dir %>
89+
<% end %>
90+
8091
### Option: DBHost
8192
# Database host name.
8293
# If set to localhost, socket is used for MySQL.
@@ -516,3 +527,4 @@ LoadModulePath=<%= @loadmodulepath %>
516527
<% if @tlskeyfile %>TLSKeyFile=<%= @tlskeyfile %><% end %>
517528

518529
<% end %>
530+

0 commit comments

Comments
 (0)