Skip to content

Commit

Permalink
Merge pull request #711 from ekohl/clean-zabbix-agent
Browse files Browse the repository at this point in the history
Reduce configuration on agent service
  • Loading branch information
igalic authored Sep 18, 2020
2 parents 4dea0bc + 73e6da0 commit 29042e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
29 changes: 12 additions & 17 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -432,24 +432,19 @@
}

# Controlling the 'zabbix-agent' service
if str2bool(getvar('::systemd')) {
$service_provider = 'systemd'
$service_path = undef
} elsif $facts['os']['name'] == 'AIX' {
$service_provider = 'init'
$service_path = '/etc/rc.d/init.d'
} else {
$service_provider = undef
$service_path = undef
}
service { $servicename:
ensure => $service_ensure,
enable => $service_enable,
path => $service_path,
provider => $service_provider,
hasstatus => true,
hasrestart => true,
require => Package[$zabbix_package_agent],
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
Expand Down
36 changes: 16 additions & 20 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,21 @@
end
else
it do
is_expected.to contain_package(package_name).with(
ensure: 'present',
require: 'Class[Zabbix::Repo]',
tag: 'zabbix'
)
is_expected.to contain_package(package_name).
with_ensure('present').
with_tag('zabbix').
that_requires('Class[zabbix::repo]')
end
it do
is_expected.to contain_service(service_name).with(
ensure: 'running',
enable: true,
hasstatus: true,
hasrestart: true,
require: "Package[#{package_name}]"
)
is_expected.to contain_service(service_name).
with_ensure('running').
with_enable(true).
with_service_provider(facts[:osfamily] == 'AIX' ? 'init' : nil).
that_requires("Package[#{package_name}]")
end

it { is_expected.to contain_file(include_dir).with_ensure('directory') }
it { is_expected.to contain_zabbix__startup(service_name).with(require: "Package[#{package_name}]") }
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('zabbix::params') }
end
Expand All @@ -104,11 +101,11 @@
when 'Debian'
# rubocop:disable RSpec/RepeatedExample
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_package('zabbix-agent').that_requires('Class[Zabbix::Repo]') }
it { is_expected.to contain_apt__source('zabbix') }
when 'RedHat'
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_package('zabbix-agent').that_requires('Class[Zabbix::Repo]') }
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
it { is_expected.to contain_yumrepo('zabbix') }
# rubocop:enable RSpec/RepeatedExample
Expand Down Expand Up @@ -347,11 +344,10 @@
end

it do
is_expected.to contain_service(service_name).with(
ensure: 'stopped',
enable: false,
require: "Package[#{package_name}]"
)
is_expected.to contain_service(service_name).
with_ensure('stopped').
with_enable(false).
that_requires("Package[#{package_name}]")
end
end
end
Expand Down

0 comments on commit 29042e9

Please sign in to comment.