2 changes: 2 additions & 0 deletions .fixtures-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ fixtures:
repo: git://github.com/voxpupuli/puppet-archive.git
windows_env:
repo: git://github.com/voxpupuli/puppet-windows_env.git
systemd:
repo: git://github.com/camptocamp/puppet-systemd.git
symlinks:
sensu: "#{source_dir}"
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ fixtures:
windows_env:
repo: git://github.com/voxpupuli/puppet-windows_env.git
ref: 'v3.0.0'
systemd:
repo: git://github.com/camptocamp/puppet-systemd.git
ref: '2.0.0'
symlinks:
sensu: "#{source_dir}"
21 changes: 12 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v5.3.0](https://github.com/sensu/sensu-puppet/tree/v5.3.0) (2020-10-28)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v5.2.1...v5.3.0)

### Added

- Improved handling of changes to sensu::etc\_dir [\#1280](https://github.com/sensu/sensu-puppet/pull/1280) ([treydock](https://github.com/treydock))

### Fixed

- Fix sensu\_agent\_entity\_config purging to not purge entity subscription [\#1281](https://github.com/sensu/sensu-puppet/pull/1281) ([treydock](https://github.com/treydock))

## [v5.2.1](https://github.com/sensu/sensu-puppet/tree/v5.2.1) (2020-10-17)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v5.2.0...v5.2.1)
Expand Down Expand Up @@ -269,20 +281,11 @@
- Updates to travis-ci [\#1186](https://github.com/sensu/sensu-puppet/pull/1186) ([treydock](https://github.com/treydock))
- Support PDK [\#1184](https://github.com/sensu/sensu-puppet/pull/1184) ([treydock](https://github.com/treydock))
- Update default resources to match Sensu Go defaults [\#1181](https://github.com/sensu/sensu-puppet/pull/1181) ([treydock](https://github.com/treydock))
- Move PostgresConfig to a type [\#1176](https://github.com/sensu/sensu-puppet/pull/1176) ([treydock](https://github.com/treydock))

### Fixed

- Only execute future release Rake function when generating changelog or release [\#1179](https://github.com/sensu/sensu-puppet/pull/1179) ([treydock](https://github.com/treydock))

## [v3.12.0](https://github.com/sensu/sensu-puppet/tree/v3.12.0) (2019-11-25)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.11.0...v3.12.0)

### Fixed

- Add lint plugin [\#1177](https://github.com/sensu/sensu-puppet/pull/1177) ([ghoneycutt](https://github.com/ghoneycutt))

## [v3.11.0](https://github.com/sensu/sensu-puppet/tree/v3.11.0) (2019-11-12)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.10.0...v3.11.0)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ group :system_tests do
gem 'beaker-puppet_install_helper', :require => false
gem 'beaker-rspec', :require => false
gem 'serverspec', :require => false
gem 'simp-beaker-helpers', :require => false
end

group :development do
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ Beginning with Sensu Go 6, some changes to `agent.yml` will only bootstrap an ag
If you wish to make changes to values such as `subscriptions`, `labels` or `annotations` after a host is added to Sensu this must be done
via the Sensu Go API. To support this it's now required that agents have the ability to make API calls.

In order to ensure agents can make API calls either via API or sensuctl the agent must be told about the admin password:
In order to ensure agents can make API calls either via API or sensuctl the agent must be told about the admin password and API host:

```
class { 'sensu':
api_host => 'sensu-backend.example.com',
agent_entity_config_password => 'supersecret',
}
class { 'sensu::agent':
Expand Down Expand Up @@ -324,6 +325,10 @@ sensu::agent_entity_config_password: supersecret
This module supports Windows Sensu Go agent via chocolatey beginning with version 5.12.0.
```puppet
class { 'sensu':
api_host => 'sensu-backend.example.com',
agent_entity_config_password => 'supersecret',
}
class { 'sensu::agent':
backends => ['sensu-backend.example.com:8081'],
subscriptions => ['windows'],
Expand Down Expand Up @@ -1220,6 +1225,8 @@ Examples can be found in the [examples](https://github.com/sensu/sensu-puppet/tr

## Limitations

Changing `sensu::etc_dir` is only supported on systems using systemd.

The type `sensu_user` does not at this time support `ensure => absent` due to a limitation with sensuctl, see [sensu-go#2540](https://github.com/sensu/sensu-go/issues/2540).

When changing the `sensu::password` value, it's necessary to run Puppet on the backend first to update the `admin` password.
Expand Down
16 changes: 16 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ Sensu agent service enable value.

Default value: ``true``

##### `service_path`

Data type: `Stdlib::Absolutepath`

The path to sensu-agent service executable

Default value: `'/usr/sbin/sensu-agent'`

##### `config_hash`

Data type: `Hash`
Expand Down Expand Up @@ -547,6 +555,14 @@ Sensu backend service enable value.

Default value: ``true``

##### `service_path`

Data type: `Stdlib::Absolutepath`

The path to sensu-backend service executable

Default value: `'/usr/sbin/sensu-backend'`

##### `state_dir`

Data type: `Stdlib::Absolutepath`
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/sensu_cluster_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end
end
rule.each_pair do |k,v|
if ! v.is_a?(Array)
if ! v.nil? && ! v.is_a?(Array)
raise ArgumentError, "Rule's #{k} must be an Array"
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ def check_agent_entity_config(resource)
if resource[:key] == 'sensu.io/managed_by'
return false
end
# Do not purge entity subscription as it can not be deleted
# https://github.com/sensu/sensu-puppet/pull/1280
if resource[:config] == 'subscriptions' && resource[:value] == "entity:#{resource[:entity]}"
return false
end
if ! self[:agent_entity_configs].nil? && ! self[:agent_entity_configs].include?(resource[:config])
return false
end
Expand Down
19 changes: 17 additions & 2 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
# Sensu agent service ensure value.
# @param service_enable
# Sensu agent service enable value.
# @param service_path
# The path to sensu-agent service executable
# @param config_hash
# Sensu agent configuration hash used to define agent.yml.
# @param backends
Expand Down Expand Up @@ -81,6 +83,7 @@
String $service_name = 'sensu-agent',
String $service_ensure = 'running',
Boolean $service_enable = true,
Stdlib::Absolutepath $service_path = '/usr/sbin/sensu-agent',
Hash $config_hash = {},
Optional[Array[Sensu::Backend_URL]] $backends = undef,
String[1] $entity_name = $facts['networking']['fqdn'],
Expand Down Expand Up @@ -217,8 +220,8 @@
# Only necessary for Puppet < 6.1.0,
# See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4
if versioncmp($facts['puppetversion'],'6.1.0') < 0 and $facts['service_provider'] == 'systemd' {
Package['sensu-go-agent'] ~> Exec['sensu systemctl daemon-reload']
Exec['sensu systemctl daemon-reload'] -> Service['sensu-agent']
Package['sensu-go-agent'] ~> Class['systemd::systemctl::daemon_reload']
Class['systemd::systemctl::daemon_reload'] -> Service['sensu-agent']
}

package { 'sensu-go-agent':
Expand Down Expand Up @@ -281,6 +284,18 @@
}
}

if $facts['service_provider'] == 'systemd' {
systemd::dropin_file { 'sensu-agent-start.conf':
unit => 'sensu-agent.service',
content => join([
'[Service]',
'ExecStart=',
"ExecStart=${service_path} start -c ${sensu::agent_config_path}",
], "\n"),
notify => Service['sensu-agent'],
}
}

service { 'sensu-agent':
ensure => $service_ensure,
enable => $service_enable,
Expand Down
19 changes: 17 additions & 2 deletions manifests/backend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# Sensu backend service ensure value.
# @param service_enable
# Sensu backend service enable value.
# @param service_path
# The path to sensu-backend service executable
# @param state_dir
# Sensu backend state directory path.
# @param config_hash
Expand Down Expand Up @@ -128,6 +130,7 @@
String $service_name = 'sensu-backend',
String $service_ensure = 'running',
Boolean $service_enable = true,
Stdlib::Absolutepath $service_path = '/usr/sbin/sensu-backend',
Stdlib::Absolutepath $state_dir = '/var/lib/sensu/sensu-backend',
Hash $config_hash = {},
Optional[String] $ssl_cert_source = $facts['puppet_hostcert'],
Expand Down Expand Up @@ -234,8 +237,8 @@
# Only necessary for Puppet < 6.1.0,
# See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4
if versioncmp($facts['puppetversion'],'6.1.0') < 0 and $facts['service_provider'] == 'systemd' {
Package['sensu-go-backend'] ~> Exec['sensu systemctl daemon-reload']
Exec['sensu systemctl daemon-reload'] -> Service['sensu-backend']
Package['sensu-go-backend'] ~> Class['systemd::systemctl::daemon_reload']
Class['systemd::systemctl::daemon_reload'] -> Service['sensu-backend']
}

sensu_user { 'admin':
Expand Down Expand Up @@ -352,6 +355,18 @@
}
}

if $facts['service_provider'] == 'systemd' {
systemd::dropin_file { 'sensu-backend-start.conf':
unit => 'sensu-backend.service',
content => join([
'[Service]',
'ExecStart=',
"ExecStart=${service_path} start -c ${sensu::etc_dir}/backend.yml",
], "\n"),
notify => Service['sensu-backend'],
}
}

service { 'sensu-backend':
ensure => $service_ensure,
enable => $service_enable,
Expand Down
9 changes: 2 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
$os_package_require = []
}
'Debian': {
$os_package_require = [Class['::apt::update']]
$os_package_require = [Class['apt::update']]
}
'windows': {
$os_package_require = []
Expand All @@ -142,16 +142,11 @@
# $package_require is used by sensu::agent and sensu::backend
# package resources
if $manage_repo {
$package_require = [Class['::sensu::repo']] + $os_package_require
$package_require = [Class['sensu::repo']] + $os_package_require
} else {
$package_require = undef
}

include sensu::resources

exec { 'sensu systemctl daemon-reload':
path => '/usr/bin:/bin:/usr/sbin:/sbin',
command => 'systemctl daemon-reload',
refreshonly => true,
}
}
6 changes: 5 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensu-sensu",
"version": "5.2.1",
"version": "5.3.0",
"author": "sensu",
"summary": "A module to install the Sensu monitoring framework",
"license": "MIT",
Expand All @@ -19,6 +19,10 @@
{
"name": "puppetlabs/postgresql",
"version_requirement": ">= 6.4.0 < 7.0.0"
},
{
"name": "camptocamp/systemd",
"version_requirement": ">= 2.0.0 < 3.0.0"
}
],
"operatingsystem_support": [
Expand Down
38 changes: 38 additions & 0 deletions spec/acceptance/00_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ class { 'sensu::backend':
end
end

# This test verifies non-standard location is used by setting agent-port
# and then checking that port gets used by the daemon
context 'etc_dir change', if: (['base','full'].include?(RSpec.configuration.sensu_mode) && pfact_on(node, 'service_provider') == 'systemd') do
it 'should work without errors' do
pp = <<-EOS
class { '::sensu':
etc_dir => '/etc/sensugo',
password => 'supersecret',
}
class { 'sensu::backend':
config_hash => {
'agent-port' => 9081,
},
}
EOS

if RSpec.configuration.sensu_use_agent
site_pp = "node 'sensu-backend' { #{pp} }"
puppetserver = hosts_as('puppetserver')[0]
create_remote_file(puppetserver, "/etc/puppetlabs/code/environments/production/manifests/site.pp", site_pp)
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0,2]
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0]
else
# Run it twice and test for idempotency
apply_manifest_on(node, pp, :catch_failures => true)
apply_manifest_on(node, pp, :catch_changes => true)
end
end

describe service('sensu-backend'), :node => node do
it { should be_enabled }
it { should be_running }
end
describe port(9081), :node => node do
it { should be_listening }
end
end

context 'backend and agent' do
it 'should work without errors' do
pp = <<-EOS
Expand Down
52 changes: 52 additions & 0 deletions spec/acceptance/01_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,58 @@ class { 'sensu::agent':
end
end

# This test verifies non-standard location is used by setting api-port
# and then checking that port gets used by the daemon
context 'etc_dir changed', if: (['base','full'].include?(RSpec.configuration.sensu_mode) && pfact_on(node, 'service_provider') == 'systemd') do
it 'should work without errors' do
pp = <<-EOS
class { '::sensu':
etc_dir => '/etc/sensugo',
}
class { 'sensu::agent':
backends => ['sensu-backend:8081'],
entity_name => 'sensu-agent',
subscriptions => ['base'],
labels => { 'foo' => 'bar' },
annotations => { 'contacts' => 'dev@example.com' },
config_hash => {
'log-level' => 'info',
'keepalive-interval' => 30,
'api-port' => 4041,
}
}
sensu::agent::subscription { 'linux': }
sensu::agent::label { 'cpu.warning': value => '90' }
sensu::agent::label { 'cpu.critical': value => '95' }
sensu::agent::label { 'bar': value => 'baz2', redact => true }
sensu::agent::annotation { 'foobar': value => 'bar' }
sensu::agent::annotation { 'cpu.message': value => 'bar' }
sensu::agent::config_entry { 'keepalive-interval': value => 20 }
EOS

if RSpec.configuration.sensu_use_agent
site_pp = "node 'sensu-agent' { #{pp} }"
puppetserver = hosts_as('puppetserver')[0]
create_remote_file(puppetserver, "/etc/puppetlabs/code/environments/production/manifests/site.pp", site_pp)
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0,2]
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0]
else
# Run it twice and test for idempotency
apply_manifest_on(node, pp, :catch_failures => true)
apply_manifest_on(node, pp, :catch_changes => true)
end
end

describe service('sensu-agent'), :node => node do
it { should be_enabled }
it { should be_running }
end

describe port(4041), :node => node do
it { should be_listening }
end
end

context 'updates' do
it 'should work without errors' do
pp = <<-EOS
Expand Down
Loading