Showing with 68 additions and 8 deletions.
  1. +11 −7 CHANGELOG.md
  2. +5 −0 REFERENCE.md
  3. +23 −0 lib/puppet/type/sensu_check.rb
  4. +1 −1 metadata.json
  5. +9 −0 spec/acceptance/sensu_check_spec.rb
  6. +19 −0 spec/unit/sensu_check_spec.rb
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

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

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

### Added

- Add output\_metric\_tags property to sensu\_check [\#1275](https://github.com/sensu/sensu-puppet/pull/1275) ([treydock](https://github.com/treydock))

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

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v5.0.0...v5.1.0)
Expand Down Expand Up @@ -126,6 +134,7 @@

- Allow agents to have subscriptions defined as a resource [\#1227](https://github.com/sensu/sensu-puppet/pull/1227) ([treydock](https://github.com/treydock))
- Support bonsai version with v prefix [\#1223](https://github.com/sensu/sensu-puppet/pull/1223) ([treydock](https://github.com/treydock))
- Manage license through sensu\_license type [\#1218](https://github.com/sensu/sensu-puppet/pull/1218) ([treydock](https://github.com/treydock))

### Fixed

Expand All @@ -142,7 +151,6 @@

### Added

- Manage license through sensu\_license type [\#1218](https://github.com/sensu/sensu-puppet/pull/1218) ([treydock](https://github.com/treydock))
- Add more examples [\#1214](https://github.com/sensu/sensu-puppet/pull/1214) ([treydock](https://github.com/treydock))
- Better organization of class variables [\#1213](https://github.com/sensu/sensu-puppet/pull/1213) ([treydock](https://github.com/treydock))
- Better documentation of private types [\#1212](https://github.com/sensu/sensu-puppet/pull/1212) ([treydock](https://github.com/treydock))
Expand Down Expand Up @@ -184,18 +192,15 @@

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

### Added

- Support Sensu Go secrets features [\#1203](https://github.com/sensu/sensu-puppet/pull/1203) ([treydock](https://github.com/treydock))
- Better support for Sensu Go upgrades [\#1201](https://github.com/sensu/sensu-puppet/pull/1201) ([treydock](https://github.com/treydock))

## [v4.2.1](https://github.com/sensu/sensu-puppet/tree/v4.2.1) (2020-01-29)

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

### Added

- Remove workaround for sensuctl command json formatting [\#1204](https://github.com/sensu/sensu-puppet/pull/1204) ([treydock](https://github.com/treydock))
- Support Sensu Go secrets features [\#1203](https://github.com/sensu/sensu-puppet/pull/1203) ([treydock](https://github.com/treydock))
- Better support for Sensu Go upgrades [\#1201](https://github.com/sensu/sensu-puppet/pull/1201) ([treydock](https://github.com/treydock))

### Fixed

Expand Down Expand Up @@ -266,7 +271,6 @@
### Added

- Improve name validations to match Sensu Go [\#1173](https://github.com/sensu/sensu-puppet/pull/1173) ([treydock](https://github.com/treydock))
- Add bolt task to manage API keys [\#1171](https://github.com/sensu/sensu-puppet/pull/1171) ([treydock](https://github.com/treydock))

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,11 @@ Valid values: `/.*/`, `absent`

An array of Sensu handlers to use for events created by the check.

##### `output_metric_tags`

Custom tags you can apply to enrich metric points produced by check output metric extraction."
Consists of Array of Hashes, each Hash must contain `name` and `value` keys.

##### `proxy_entity_name`

Valid values: `/^[\w\.\-]+$/`, `absent`
Expand Down
23 changes: 23 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@
newvalues(/.*/, :absent)
end

newproperty(:output_metric_tags, :array_matching => :all, :parent => PuppetX::Sensu::ArrayOfHashesProperty) do
desc <<-EOS
Custom tags you can apply to enrich metric points produced by check output metric extraction."
Consists of Array of Hashes, each Hash must contain `name` and `value` keys.
EOS

validate do |tag|
if ! tag.is_a?(Hash)
raise ArgumentError, "Each tag must be a Hash not #{tag.class}"
end
required_keys = ['name','value']
keys = tag.keys.map { |k| k.to_s }
if required_keys.sort != keys.sort
raise ArgumentError, "tag must contain only 'name' and 'value' keys"
end
tag.each_pair do |key, value|
if ! value.is_a?(String)
raise ArgumentError, "#{key} must be a String, not #{value.class}"
end
end
end
end

newproperty(:max_output_size, :parent => PuppetX::Sensu::IntegerProperty) do
desc 'Maximum size, in bytes, of stored check outputs.'
end
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensu-sensu",
"version": "5.1.0",
"version": "5.2.0",
"author": "sensu",
"summary": "A module to install the Sensu monitoring framework",
"license": "MIT",
Expand Down
9 changes: 9 additions & 0 deletions spec/acceptance/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'entity_attributes' => ["entity.Class == 'proxy'"],
},
output_metric_format => 'nagios_perfdata',
output_metric_tags => [{'name' => 'instance', 'value' => '{{ .name }}'}],
labels => { 'foo' => 'baz' },
secrets => [
{'name' => 'TEST', 'secret' => 'test'}
Expand Down Expand Up @@ -76,6 +77,7 @@
expect(data['check_hooks']).to eq([{'0' => ['always.sh']},{'1' => ['test.sh']},{'critical' => ['httpd-restart']}])
expect(data['proxy_requests']['entity_attributes']).to eq(["entity.Class == 'proxy'"])
expect(data['output_metric_format']).to eq('nagios_perfdata')
expect(data['output_metric_tags']).to eq([{'name' => 'instance', 'value' => '{{ .name }}'}])
expect(data['metadata']['labels']['foo']).to eq('baz')
expect(data['secrets']).to eq([{'name' => 'TEST', 'secret' => 'test'}])
end
Expand Down Expand Up @@ -161,6 +163,10 @@ class { 'sensu::cli':
'entity_attributes' => ['System.OS==linux'],
},
output_metric_format => 'graphite_plaintext',
output_metric_tags => [
{'name' => 'instance', 'value' => '{{ .name }}'},
{'name' => 'prometheus_type', 'value' => 'gauge'},
],
labels => { 'foo' => 'bar' },
secrets => [
{'name' => 'TEST', 'secret' => 'test2'}
Expand Down Expand Up @@ -201,6 +207,9 @@ class { 'sensu::cli':
expect(data['check_hooks']).to eq([{'critical' => ['httpd-restart']},{'warning' => ['httpd-restart']}])
expect(data['proxy_requests']['entity_attributes']).to eq(['System.OS==linux'])
expect(data['output_metric_format']).to eq('graphite_plaintext')
expect(data['output_metric_tags']).to include({'name' => 'instance', 'value' => '{{ .name }}'})
expect(data['output_metric_tags']).to include({'name' => 'prometheus_type', 'value' => 'gauge'})
expect(data['output_metric_tags'].size).to eq(2)
expect(data['metadata']['labels']['foo']).to eq('bar')
expect(data['secrets']).to eq([{'name' => 'TEST', 'secret' => 'test2'}])
end
Expand Down
19 changes: 19 additions & 0 deletions spec/unit/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,25 @@
end
end

describe 'output_metric_tags' do
it 'should accept a valid value' do
config[:output_metric_tags] = [{'name' => 'instance', 'value' => '{{ .name }}'}]
expect(check[:output_metric_tags]).to eq([{'name' => 'instance', 'value' => '{{ .name }}'}])
end
it 'requires hash for each tag' do
config[:output_metric_tags] = ['foo']
expect { check }.to raise_error(Puppet::Error, /must be a Hash/)
end
it 'requires valid keys for tag' do
config[:output_metric_tags] = [{'name' => 'instance'}]
expect { check }.to raise_error(Puppet::Error, /tag must contain/)
end
it 'requires strings for values' do
config[:output_metric_tags] = [{'name' => 'instance', 'value' => false}]
expect { check }.to raise_error(Puppet::Error, /must be a String/)
end
end

describe 'proxy_requests' do
it 'accepts valid value' do
config[:proxy_requests] = {'entity_attributes' => ['foo==bar'],'splay' => true, 'splay_coverage' => 60}
Expand Down