Skip to content

Commit 6e86dab

Browse files
authored
Add option to specify type of interface in agent class (#697)
* Add option to specify type of interface in agent class * Fix arrow alignment in agent.pp and resources/agent.pp * Remove comma from last parameter of a function * Supress 'corrective changed' messages * Enforce correct values for zbx_interface_type * Add comment * Fix travis check
1 parent c52c0be commit 6e86dab

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

lib/puppet/provider/zabbix_host/ruby.rb

+18-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ def self.instances
1616
)
1717

1818
api_hosts.map do |h|
19-
interface = h['interfaces'].select { |i| i['type'].to_i == 1 && i['main'].to_i == 1 }.first
19+
# only select the default interface for given host
20+
# there is only 1 interface that can be default
21+
interface = h['interfaces'].select { |i| i['main'].to_i == 1 }.first
2022
use_ip = !interface['useip'].to_i.zero?
23+
proxy_select = proxies.select { |_name, id| id == h['proxy_hostid'] }.keys.first
24+
proxy_select = '' if proxy_select.nil?
2125
new(
2226
ensure: :present,
2327
id: h['hostid'].to_i,
@@ -30,7 +34,8 @@ def self.instances
3034
group_create: nil,
3135
templates: h['parentTemplates'].map { |x| x['host'] },
3236
macros: h['macros'].map { |macro| { macro['macro'] => macro['value'] } },
33-
proxy: proxies.select { |_name, id| id == h['proxy_hostid'] }.keys.first
37+
proxy: proxy_select,
38+
interfacetype: interface['type'].to_i
3439
)
3540
end
3641
end
@@ -58,7 +63,7 @@ def create
5863
proxy_hostid: proxy_hostid,
5964
interfaces: [
6065
{
61-
type: 1,
66+
type: @resource[:interfacetype].nil? ? 1 : @resource[:interfacetype],
6267
main: 1,
6368
ip: @resource[:ipaddress],
6469
dns: @resource[:hostname],
@@ -142,6 +147,16 @@ def port=(int)
142147
)
143148
end
144149

150+
def interfacetype=(int)
151+
zbx.query(
152+
method: 'hostinterface.update',
153+
params: {
154+
interfaceid: @property_hash[:interfaceid],
155+
type: int
156+
}
157+
)
158+
end
159+
145160
def groups=(hostgroups)
146161
gids = get_groupids(hostgroups, @resource[:group_create])
147162
groups = transform_to_array_hash('groupid', gids)

lib/puppet/type/zabbix_host.rb

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def munge_boolean(value)
4848
desc 'The IP address of the machine running zabbix agent.'
4949
end
5050

51+
newproperty(:interfacetype, int: 1) do
52+
desc 'Interface type. 1 for zabbix agent.'
53+
end
54+
5155
newproperty(:use_ip, boolean: true) do
5256
desc 'Using ipadress instead of dns to connect.'
5357

manifests/agent.pp

+14-9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
# [*zbx_macros*]
6262
# List of macros which will be added when host is configured.
6363
#
64+
# [*zbx_interface_type*]
65+
# Integer specifying type of interface to be created
66+
#
6467
# [*agent_configfile_path*]
6568
# Agent config file path defaults to /etc/zabbix/zabbix_agentd.conf
6669
#
@@ -253,6 +256,7 @@
253256
$zbx_group_create = $zabbix::params::agent_zbx_group_create,
254257
$zbx_templates = $zabbix::params::agent_zbx_templates,
255258
Array[Hash] $zbx_macros = [],
259+
Integer[1,4] $zbx_interface_type = 1,
256260
$agent_configfile_path = $zabbix::params::agent_configfile_path,
257261
$pidfile = $zabbix::params::agent_pidfile,
258262
$servicename = $zabbix::params::agent_servicename,
@@ -374,15 +378,16 @@
374378
$_hostname = pick($hostname, $facts['networking']['fqdn'])
375379

376380
class { 'zabbix::resources::agent':
377-
hostname => $_hostname,
378-
ipaddress => $listen_ip,
379-
use_ip => $agent_use_ip,
380-
port => $listenport,
381-
groups => [$groups].flatten(),
382-
group_create => $zbx_group_create,
383-
templates => $zbx_templates,
384-
macros => $zbx_macros,
385-
proxy => $use_proxy,
381+
hostname => $_hostname,
382+
ipaddress => $listen_ip,
383+
use_ip => $agent_use_ip,
384+
port => $listenport,
385+
groups => [$groups].flatten(),
386+
group_create => $zbx_group_create,
387+
templates => $zbx_templates,
388+
macros => $zbx_macros,
389+
interfacetype => $zbx_interface_type,
390+
proxy => $use_proxy,
386391
}
387392
}
388393

manifests/resources/agent.pp

+10-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$templates = undef,
2525
$macros = undef,
2626
$proxy = undef,
27+
$interfacetype = 1,
2728
) {
2829
if $group and $groups {
2930
fail("Got group and groups. This isn't support! Please use groups only.")
@@ -37,13 +38,14 @@
3738
}
3839

3940
@@zabbix_host { $hostname:
40-
ipaddress => $ipaddress,
41-
use_ip => $use_ip,
42-
port => $port,
43-
groups => $groups,
44-
group_create => $group_create,
45-
templates => $templates,
46-
macros => $macros,
47-
proxy => $proxy,
41+
ipaddress => $ipaddress,
42+
use_ip => $use_ip,
43+
port => $port,
44+
groups => $groups,
45+
group_create => $group_create,
46+
templates => $templates,
47+
macros => $macros,
48+
proxy => $proxy,
49+
interfacetype => $interfacetype,
4850
}
4951
}

0 commit comments

Comments
 (0)