Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap agent2 support (continued) - Waiting for postgresql fix #868

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
5. [Usage - Configuration options and additional functionality](#usage)
* [zabbix-server](#usage-zabbix-server)
* [zabbix-agent](#usage-zabbix-agent)
* [zabbix-agent2](#usage-zabbix-agent2)
* [zabbix-proxy](#usage-zabbix-proxy)
* [zabbix-javagateway](#usage-zabbix-javagateway)
* [zabbix-sender](#usage-zabbix-sender)
Expand Down Expand Up @@ -206,6 +207,21 @@ class { 'zabbix::agent':
}
```

### Usage zabbix-agent2

To use Zabbix agent2 you need to define some parameters

```ruby
class { 'zabbix::agent':
package_name => 'zabbix-agent2',
agent_configfile_path => '/etc/zabbix/zabbix_agent2.d',
pidfile => '/var/run/zabbix/zabbix_agentd2.pid',
servicename => 'zabbix-agent2',
zabbix_package_agent => 'zabbix-agent2',
binary_location => '/usr/sbin/zabbix_agent2'
}
```

### Usage zabbix-proxy

Like the zabbix-server, the zabbix-proxy can also be used in 2 ways:
Expand Down
31 changes: 31 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ class { 'zabbix':
}
```

##### Using Zabbix Agent 2

```puppet
class { 'zabbix::agent':
package_name => 'zabbix-agent2',
agent_configfile_path => '/etc/zabbix/zabbix_agent2.d',
pidfile => '/var/run/zabbix/zabbix_agentd2.pid',
servicename => 'zabbix-agent2',
zabbix_package_agent => 'zabbix-agent2',
binary_location => '/usr/sbin/zabbix_agent2'
}
```

#### Parameters

The following parameters are available in the `zabbix` class:
Expand Down Expand Up @@ -1418,6 +1431,7 @@ The following parameters are available in the `zabbix::agent` class:
* [`userparameter`](#-zabbix--agent--userparameter)
* [`loadmodulepath`](#-zabbix--agent--loadmodulepath)
* [`loadmodule`](#-zabbix--agent--loadmodule)
* [`binary_location`](#-zabbix--agent--binary_location)
* [`manage_startup_script`](#-zabbix--agent--manage_startup_script)

##### <a name="-zabbix--agent--zabbix_version"></a>`zabbix_version`
Expand Down Expand Up @@ -2098,6 +2112,14 @@ Module to load at agent startup.

Default value: `$zabbix::params::agent_loadmodule`

##### <a name="-zabbix--agent--binary_location"></a>`binary_location`

Data type: `Optional[Stdlib::Absolutepath]`

Location of th binary file, this feature is available only for systemd startup script

Default value: `$zabbix::params::agent_binary_location`

##### <a name="-zabbix--agent--manage_startup_script"></a>`manage_startup_script`

Data type: `Boolean`
Expand Down Expand Up @@ -5628,6 +5650,7 @@ The following parameters are available in the `zabbix::startup` defined type:
* [`service_type`](#-zabbix--startup--service_type)
* [`manage_database`](#-zabbix--startup--manage_database)
* [`service_name`](#-zabbix--startup--service_name)
* [`binary_location`](#-zabbix--startup--binary_location)

##### <a name="-zabbix--startup--pidfile"></a>`pidfile`

Expand Down Expand Up @@ -5703,6 +5726,14 @@ Name of the service. Defaults to the resource name

Default value: `$name`

##### <a name="-zabbix--startup--binary_location"></a>`binary_location`

Data type: `Optional[Stdlib::Absolutepath]`

This params is use for define a specific binary location. This is actually only available for zabbix agent and systemd

Default value: `undef`

### <a name="zabbix--template"></a>`zabbix::template`

This will upload an Zabbix Template (XML format)
Expand Down
27 changes: 27 additions & 0 deletions lib/facter/apache_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

Facter.add(:apache_version) do
confine kernel: %w[FreeBSD Linux]
setcode do
apache_version = nil

if Facter::Core::Execution.which('httpd')
apache_version = Facter::Core::Execution.execute('httpd -V 2>&1')
Facter.debug "Matching httpd '#{apache_version}'"
elsif Facter::Core::Execution.which('apache2')
apache_version = Facter::Core::Execution.execute('apache2 -V 2>&1')
Facter.debug "Matching apache2 '#{apache_version}'"
elsif Facter::Core::Execution.which('apachectl')
apache_version = Facter::Core::Execution.execute('apachectl -v 2>&1')
Facter.debug "Matching apachectl '#{apache_version}'"
elsif Facter::Core::Execution.which('apache2ctl')
apache_version = Facter::Core::Execution.execute('apache2ctl -v 2>&1')
Facter.debug "Matching apache2ctl '#{apache_version}'"
end

unless apache_version.nil?
match = %r{^Server version: Apache/(\d+.\d+(.\d+)?)}.match(apache_version)
match[1] unless match.nil?
end
end
end
5 changes: 5 additions & 0 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
# @param userparameter User-defined parameter to monitor.
# @param loadmodulepath Full path to location of agent modules.
# @param loadmodule Module to load at agent startup.
# @param binary_location Location of th binary file, this feature is available only for systemd startup script
# @param manage_startup_script
# If the init script should be managed by this module. Attention: This might
# cause problems with some config options of this module (e.g
Expand Down Expand Up @@ -220,13 +221,16 @@
String $additional_service_params = $zabbix::params::additional_service_params,
String $service_type = $zabbix::params::service_type,
Boolean $manage_startup_script = $zabbix::params::manage_startup_script,
Optional[Stdlib::Absolutepath] $binary_location = $zabbix::params::agent_binary_location,
) inherits zabbix::params {
if $facts['os']['family'] == 'Debian' and versioncmp($facts['os']['release']['major'], '11') == 0 {
if versioncmp($zabbix_version, '5.2') == 0 {
fail('Zabbix 5.2 is not supported on Debian 11!')
}
}

$agent2 = $zabbix_package_agent == 'zabbix-agent2'

# Find if listenip is set. If not, we can set to specific ip or
# to network name. If more than 1 interfaces are available, we
# can find the ipaddress of this specific interface if listenip
Expand Down Expand Up @@ -329,6 +333,7 @@
additional_service_params => $additional_service_params,
service_type => $service_type,
service_name => 'zabbix-agent',
binary_location => $binary_location,
require => Package[$zabbix_package_agent],
}
}
Expand Down
13 changes: 13 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,31 @@
# @param saml_sp_cert The location of the SAML Service Provider Certificate.
# @param saml_idp_cert The location of the SAML Identity Provider Certificate.
# @param saml_settings A hash of additional SAML SSO settings.
#
# @example Single host setup:
# class { 'zabbix':
# zabbix_url => 'zabbix.dj-wasabi.nl',
# }
#
#
# @example This assumes that you want to use the postgresql database. If not and you want to supply your own database crendentials:
# class { 'zabbix':
# zabbix_url => 'zabbix.dj-wasabi.nl',
# database_type => 'mysql',
# database_user => 'zabbix',
# database_password => 'ThisIsVeryDifficult.nl',
# }
#
# @example Using Zabbix Agent 2
# class { 'zabbix::agent':
# package_name => 'zabbix-agent2',
# agent_configfile_path => '/etc/zabbix/zabbix_agent2.d',
# pidfile => '/var/run/zabbix/zabbix_agentd2.pid',
# servicename => 'zabbix-agent2',
# zabbix_package_agent => 'zabbix-agent2',
# binary_location => '/usr/sbin/zabbix_agent2'
# }
#
# @author Werner Dijkerman [email protected]
class zabbix (
$zabbix_url = '',
Expand Down
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@
$server_socketdir = undef

# Agent specific params
$agent_binary_location = $facts['kernel'] ? {
'Linux' => '/usr/sbin/zabbix_agentd',
default => undef,
}
$agent_allowroot = '0'
$agent_buffersend = '5'
$agent_buffersize = '100'
Expand Down
6 changes: 5 additions & 1 deletion manifests/startup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# @param service_type Systemd service type
# @param manage_database When true, it will configure the database and execute the sql scripts.
# @param service_name Name of the service. Defaults to the resource name
# @param binary_location This params is use for define a specific binary location. This is actually only available for zabbix agent and systemd
# @example
# zabbix::startup { 'agent': }
#
Expand All @@ -27,6 +28,7 @@
String $service_type = 'simple',
Optional[Boolean] $manage_database = undef,
Optional[String] $service_name = $name,
Optional[Stdlib::Absolutepath] $binary_location = undef,
) {
case $title.downcase {
/agent/: {
Expand All @@ -41,8 +43,10 @@
fail('we currently only support a title that contains agent or server')
}
}
# provided by camp2camp/systemd
if $facts['systemd'] {
if $name =~ /^zabbix-agent2?$/ {
assert_type(Stdlib::Absolutepath, $binary_location)
}
contain systemd
systemd::unit_file { "${name}.service":
content => template("zabbix/${service_name}-systemd.init.erb"),
Expand Down
9 changes: 9 additions & 0 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@
default => $zabbix_api_access.map |$host| { "host ${host}" },
}

# Check which version of Apache we're using
if versioncmp($facts['apache_version'], '2.4') >= 0 {
$directory_allow = { 'require' => 'all granted', }
$directory_deny = { 'require' => 'all denied', }
} else {
$directory_allow = { 'allow' => 'from all', 'order' => 'Allow,Deny', }
$directory_deny = { 'deny' => 'from all', 'order' => 'Deny,Allow', }
}

apache::vhost { $zabbix_url:
docroot => '/usr/share/zabbix',
ip => $apache_listen_ip,
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
end
end

context 'when binary_location is define', if: facts[:kernel] == 'Linux' do
it do
is_expected.to contain_zabbix__startup(service_name).with(
binary_location: '/usr/sbin/zabbix_agentd'
)
end
end

context 'when declaring manage_repo is true' do
let :params do
{
Expand Down Expand Up @@ -427,6 +435,28 @@
end
end
end

context 'when zabbix_package_agent is zabbix-agent2' do
let :params do
{
zabbix_package_agent: 'zabbix-agent2', startagents: 1,
maxlinespersecond: 1, allowroot: 1, zabbix_user: 'root',
loadmodulepath: '/tmp', allowkey: 'system.run[*]',
denykey: 'system.run[*]', enableremotecommands: 1,
logremotecommands: 1
}
end

it { is_expected.to contain_package('zabbix-agent2') }

it do
is_expected.not_to contain_file(config_path).with_content(
%r{^(LogRemoteCommands|StartAgents|MaxLinesPerSecond
|AllowRoot|User|LoadModulePath|AllowKey|DenyKey|
EnableRemoteCommands|LogRemoteCommands)}
)
end
end
end
end
end
4 changes: 1 addition & 3 deletions spec/classes/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
next if facts[:os]['name'] == 'windows'

context "on #{os}" do
let :facts do
facts
end
let(:facts) { facts }

let :pre_condition do
<<-EOS
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

context "on #{os}" do
let :facts do
facts
facts.deep_merge({ apache_version: '2.4' })
end

context 'with all defaults' do
Expand Down
3 changes: 2 additions & 1 deletion spec/defines/startup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
{
agent_configfile_path: '/something',
pidfile: '/somethingelse',
additional_service_params: '--foreground'
additional_service_params: '--foreground',
binary_location: '/usr/sbin/zabbix_agentd'
}
end

Expand Down
37 changes: 37 additions & 0 deletions spec/unit/facter/util/fact_apache_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require 'spec_helper'

describe Facter::Util::Fact do
before do
Facter.clear
end

describe 'apache_version' do
context 'with value' do
before do
Facter.fact(:kernel).stubs(:value).returns('Linux')
Facter::Core::Execution.stubs(:which).with('httpd').returns(true)
Facter::Core::Execution.stubs(:execute).with('httpd -V 2>&1').returns('Server version: Apache/2.4.16 (Unix)\nServer built: Jul 31 2015 15:53:26')
end

it 'returns the correct version' do
expect(Facter.fact(:apache_version).value).to eq('2.4.16')
end
end
end

describe 'apache_version with empty OS' do
context 'with value' do
before do
Facter.fact(:kernel).stubs(:value).returns('Linux')
Facter::Core::Execution.stubs(:which).with('httpd').returns(true)
Facter::Core::Execution.stubs(:execute).with('httpd -V 2>&1').returns('Server version: Apache/2.4.6 ()\nServer built: Nov 21 2015 05:34:59')
end

it 'returns the correct version' do
expect(Facter.fact(:apache_version).value).to eq('2.4.6')
end
end
end
end
2 changes: 1 addition & 1 deletion templates/zabbix-agent-systemd.init.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ After=network.target
Restart=on-failure
<% if @pidfile %>PIDFile=<%= @pidfile %><% end %>
KillMode=control-group
ExecStart=/usr/sbin/zabbix_agentd <%= @additional_service_params %> -c <%= @agent_configfile_path %>
ExecStart=<%= @binary_location %> <%= @additional_service_params %> -c <%= @agent_configfile_path %>
<% if @zabbix_user %>User=<%= @zabbix_user %><% end %>
RestartSec=10s

Expand Down
Loading
Loading