Skip to content

Commit 877981e

Browse files
author
Henri Nougayrede
committed
feat: add Zabbix 7 API compatibility and proxy group support
Update the zabbix_host provider to use the new Zabbix 7 API fields: - Replace deprecated proxy_hostid with proxyid - Add proxy_groupid and monitored_by fields for proxy group support - Add proxygroup property to zabbix_host type - Fix interfacedetails insync? comparison to use sorted comparison - Add monitored_by_group parameter to agent class and resources
1 parent 86dc242 commit 877981e

6 files changed

Lines changed: 66 additions & 9 deletions

File tree

REFERENCE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ The following parameters are available in the `zabbix::agent` class:
13761376
* [`zabbix_package_source`](#-zabbix--agent--zabbix_package_source)
13771377
* [`manage_resources`](#-zabbix--agent--manage_resources)
13781378
* [`monitored_by_proxy`](#-zabbix--agent--monitored_by_proxy)
1379+
* [`monitored_by_group`](#-zabbix--agent--monitored_by_group)
13791380
* [`agent_use_ip`](#-zabbix--agent--agent_use_ip)
13801381
* [`zbx_groups`](#-zabbix--agent--zbx_groups)
13811382
* [`zbx_group_create`](#-zabbix--agent--zbx_group_create)
@@ -1535,6 +1536,14 @@ If the proxy is also installed via this module, please fill in the FQDN
15351536

15361537
Default value: `$zabbix::params::monitored_by_proxy`
15371538

1539+
##### <a name="-zabbix--agent--monitored_by_group"></a>`monitored_by_group`
1540+
1541+
Data type: `Any`
1542+
1543+
When this is monitored by a proxy group, please fill in the name of this proxy group.
1544+
1545+
Default value: `$zabbix::params::monitored_by_group`
1546+
15381547
##### <a name="-zabbix--agent--agent_use_ip"></a>`agent_use_ip`
15391548

15401549
Data type: `Any`
@@ -3677,6 +3686,7 @@ The following parameters are available in the `zabbix::resources::agent` class:
36773686
* [`templates`](#-zabbix--resources--agent--templates)
36783687
* [`macros`](#-zabbix--resources--agent--macros)
36793688
* [`proxy`](#-zabbix--resources--agent--proxy)
3689+
* [`proxygroup`](#-zabbix--resources--agent--proxygroup)
36803690
* [`interfacetype`](#-zabbix--resources--agent--interfacetype)
36813691
* [`interfacedetails`](#-zabbix--resources--agent--interfacedetails)
36823692
* [`tls_connect`](#-zabbix--resources--agent--tls_connect)
@@ -3756,6 +3766,14 @@ Whether it is monitored by an proxy or not.
37563766

37573767
Default value: `undef`
37583768

3769+
##### <a name="-zabbix--resources--agent--proxygroup"></a>`proxygroup`
3770+
3771+
Data type: `Any`
3772+
3773+
Whether it is monitored by a proxy group or not.
3774+
3775+
Default value: `undef`
3776+
37593777
##### <a name="-zabbix--resources--agent--interfacetype"></a>`interfacetype`
37603778

37613779
Data type: `Any`
@@ -6115,6 +6133,10 @@ The port that the zabbix agent is listening on.
61156133

61166134
Whether it is monitored by an proxy or not.
61176135

6136+
##### `proxygroup`
6137+
6138+
Whether it is monitored by a proxy group or not.
6139+
61186140
##### `templates`
61196141

61206142
List of templates which should be loaded for this host.

lib/puppet/provider/zabbix_host/ruby.rb

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
def self.instances
99
proxies = zbx.proxies.all
10+
proxygroups = zbx.proxygroup.all
11+
1012
api_hosts = zbx.query(
1113
method: 'host.get',
1214
params: {
1315
selectParentTemplates: ['host'],
1416
selectInterfaces: %w[interfaceid type main ip port useip details],
1517
selectGroups: ['name'],
1618
selectMacros: %w[macro value],
17-
output: %w[host proxy_hostid tls_accept tls_connect tls_issuer tls_subject]
19+
output: %w[host proxyid proxy_groupid tls_accept tls_connect tls_issuer tls_subject]
1820
}
1921
)
2022

@@ -23,8 +25,10 @@ def self.instances
2325
# there is only 1 interface that can be default
2426
interface = h['interfaces'].select { |i| i['main'].to_i == 1 }.first
2527
use_ip = !interface['useip'].to_i.zero?
26-
proxy_select = proxies.select { |_name, id| id == h['proxy_hostid'] }.keys.first
28+
proxy_select = proxies.select { |_name, id| id == h['proxyid'] }.keys.first
2729
proxy_select = '' if proxy_select.nil?
30+
proxygroup_select = proxygroups.select { |_name, id| id == h['proxy_groupid'] }.keys.first
31+
proxygroup_select = '' if proxygroup_select.nil?
2832
new(
2933
ensure: :present,
3034
id: h['hostid'].to_i,
@@ -38,6 +42,7 @@ def self.instances
3842
templates: h['parentTemplates'].map { |x| x['host'] },
3943
macros: h['macros'].map { |macro| { macro['macro'] => macro['value'] } },
4044
proxy: proxy_select,
45+
proxygroup: proxygroup_select,
4146
interfacetype: interface['type'].to_i,
4247
interfacedetails: interface['details'],
4348
tls_accept: h['tls_accept'].to_i,
@@ -63,15 +68,18 @@ def create
6368
gids = get_groupids(@resource[:groups], @resource[:group_create])
6469
groups = transform_to_array_hash('groupid', gids)
6570

66-
proxy_hostid = @resource[:proxy].nil? || @resource[:proxy].empty? ? nil : zbx.proxies.get_id(host: @resource[:proxy])
71+
proxyid = @resource[:proxy].nil? || @resource[:proxy].empty? ? nil : zbx.proxies.get_id(name: @resource[:proxy])
72+
proxy_groupid = @resource[:proxygroup].nil? || @resource[:proxygroup].empty? ? nil : zbx.proxygroup.get_id(name: @resource[:proxygroup])
73+
monitored_by = proxy_groupid && proxyid.nil? ? 2 : 1
6774

6875
tls_accept = @resource[:tls_accept].nil? ? 1 : @resource[:tls_accept]
6976
tls_connect = @resource[:tls_connect].nil? ? 1 : @resource[:tls_connect]
7077

71-
# Now we create the host
72-
zbx.hosts.create(
78+
host_params = {
7379
host: @resource[:hostname],
74-
proxy_hostid: proxy_hostid,
80+
proxyid: proxyid,
81+
proxy_groupid: proxy_groupid,
82+
monitored_by: monitored_by,
7583
interfaces: [
7684
{
7785
type: @resource[:interfacetype].nil? ? 1 : @resource[:interfacetype],
@@ -89,7 +97,13 @@ def create
8997
tls_accept: tls_accept,
9098
tls_issuer: @resource[:tls_issuer].nil? ? '' : @resource[:tls_issuer],
9199
tls_subject: @resource[:tls_subject].nil? ? '' : @resource[:tls_subject]
92-
)
100+
}
101+
102+
host_params.delete(:proxyid) if host_params[:proxy_groupid] || host_params[:proxyid].nil?
103+
host_params.delete(:proxy_groupid) if host_params[:proxy_groupid].nil?
104+
105+
# Now we create the host
106+
zbx.hosts.create(host_params)
93107
end
94108

95109
def exists?
@@ -233,7 +247,16 @@ def macros=(array)
233247
def proxy=(string)
234248
zbx.hosts.create_or_update(
235249
host: @resource[:hostname],
236-
proxy_hostid: zbx.proxies.get_id(host: string)
250+
monitored_by: '1',
251+
proxyid: zbx.proxies.get_id(name: string)
252+
)
253+
end
254+
255+
def proxygroup=(string)
256+
zbx.hosts.create_or_update(
257+
host: @resource[:hostname],
258+
monitored_by: '2',
259+
proxy_groupid: zbx.proxygroup.get_id(name: string)
237260
)
238261
end
239262

lib/puppet/type/zabbix_host.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def munge_encryption(value)
6565
desc 'Additional interface details.'
6666

6767
def insync?(is)
68-
is.to_s == should.to_s
68+
is.sort.to_s == should.sort.to_s
6969
end
7070
end
7171

@@ -121,6 +121,10 @@ def insync?(is)
121121
desc 'Whether it is monitored by an proxy or not.'
122122
end
123123

124+
newproperty(:proxygroup) do
125+
desc 'Whether it is monitored by a proxy group or not.'
126+
end
127+
124128
newproperty(:tls_connect) do
125129
desc 'How the server connect to the client (unencrypted, psk or cert)'
126130
def insync?(is)

manifests/agent.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# @param monitored_by_proxy
2121
# When this is monitored by an proxy, please fill in the name of this proxy.
2222
# If the proxy is also installed via this module, please fill in the FQDN
23+
# @param monitored_by_group
24+
# When this is monitored by a proxy group, please fill in the name of this proxy group.
2325
# @param agent_use_ip
2426
# When true, when creating hosts via the zabbix-api, it will configure that
2527
# connection should me made via ip, not fqdn.
@@ -157,6 +159,7 @@
157159
Boolean $manage_repo = $zabbix::params::manage_repo,
158160
Boolean $manage_resources = $zabbix::params::manage_resources,
159161
$monitored_by_proxy = $zabbix::params::monitored_by_proxy,
162+
$monitored_by_group = $zabbix::params::monitored_by_group,
160163
$agent_use_ip = $zabbix::params::agent_use_ip,
161164
Variant[String[1],Array[String[1]]] $zbx_groups = $zabbix::params::agent_zbx_groups,
162165
$zbx_group_create = $zabbix::params::agent_zbx_group_create,
@@ -266,6 +269,7 @@
266269
interfacetype => $zbx_interface_type,
267270
interfacedetails => $zbx_interface_details,
268271
proxy => $use_proxy,
272+
proxygroup => $monitored_by_group,
269273
tls_accept => $tlsaccept,
270274
tls_connect => $tlsconnect,
271275
tls_issuer => $tlscertissuer,

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@
350350
$agent_zbx_templates = ['Template OS Linux', 'Template App SSH Service']
351351
$apache_status = false
352352
$monitored_by_proxy = undef
353+
$monitored_by_group = undef
353354
# provided by puppet/systemd
354355
if $facts['systemd'] {
355356
$agent_logtype = 'system'

manifests/resources/agent.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# @param templates List of templates which should be attached to this host.
99
# @param macros Array of hashes (macros) which should be attached to this host.
1010
# @param proxy Whether it is monitored by an proxy or not.
11+
# @param proxygroup Whether it is monitored by a proxy group or not.
1112
# @param interfacetype Internally used identifier for the host interface.
1213
# @param interfacedetails Hash with interface details for SNMP when interface type is 2.
1314
# @param tls_connect How the server must connect to the agent
@@ -24,6 +25,7 @@
2425
$templates = undef,
2526
$macros = undef,
2627
$proxy = undef,
28+
$proxygroup = undef,
2729
$interfacetype = 1,
2830
Variant[Array, Hash] $interfacedetails = [],
2931
Optional[Enum['unencrypted','psk','cert']] $tls_connect = undef,
@@ -40,6 +42,7 @@
4042
templates => $templates,
4143
macros => $macros,
4244
proxy => $proxy,
45+
proxygroup => $proxygroup,
4346
interfacetype => $interfacetype,
4447
interfacedetails => $interfacedetails,
4548
tls_connect => $tls_connect,

0 commit comments

Comments
 (0)