Skip to content

Commit

Permalink
Merge pull request #604 from jkroepke/multiple_types
Browse files Browse the repository at this point in the history
Fixes #549: Unable to define a multi-value type
  • Loading branch information
bastelfreak authored Feb 12, 2017
2 parents 479f40a + d9508dc commit dd182b4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
46 changes: 26 additions & 20 deletions manifests/type.pp
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
define collectd::type (
$target,
$ds_type,
$ds = $title,
$min = 'U',
$max = 'U',
$ds_name = 'value',
) {
validate_string($ds_name)
$upper_ds_type = upcase($ds_type)

validate_re($upper_ds_type,
['^ABSOLUTE$', '^COUNTER$', '^DERIVE$', '^GAUGE$'])
String $target,
String $ds = $name,
# BC compatible ....
Optional[Enum['ABSOLUTE', 'COUNTER', 'DERIVE', 'GAUGE']] $ds_type = undef,
Variant[Numeric, Enum['U']] $min = 'U',
Variant[Numeric, Enum['U']] $max = 'U',
String $ds_name = 'value',
# BC compatible .... ending

if $min != 'U' {
validate_numeric($min)
}

if $max != 'U' {
validate_numeric($max)
Array[Struct[{
min => Variant[Numeric, Enum['U']],
max => Variant[Numeric, Enum['U']],
ds_type => Enum['ABSOLUTE', 'COUNTER', 'DERIVE', 'GAUGE'],
ds_name => String,
}]] $types = [],
) {
if empty($types) {
$_types = [{
min => $min,
max => $max,
ds_type => $ds_type,
ds_name => $ds_name,
}]
} else {
$_types = $types
}

$content = "${ds}\t${ds_name}:${upper_ds_type}:${min}:${max}"
$content = $_types.map |$type| { "${type['ds_name']}:${type['ds_type']}:${type['min']}:${type['max']}" }.join(', ')

concat::fragment { "${target}/${ds}":
content => $content,
content => "${ds}\t${content}",
target => $target,
order => $ds,
}
Expand Down
28 changes: 28 additions & 0 deletions spec/defines/collectd_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,32 @@
content: "index\tsome_name:ABSOLUTE:4:5")
end
end

context 'define a multiple type' do
let(:title) { 'index' }
let :params do
{
target: '/etc/collectd/types.db',
types: [
{
'ds_type' => 'ABSOLUTE',
'min' => 4,
'max' => 5,
'ds_name' => 'some_name'
},
{
'ds_type' => 'COUNTER',
'min' => 7,
'max' => 'U',
'ds_name' => 'other_name'
}
]
}
end

it 'creates an entry' do
is_expected.to contain_concat__fragment('/etc/collectd/types.db/index').with(target: '/etc/collectd/types.db',
content: "index\tsome_name:ABSOLUTE:4:5, other_name:COUNTER:7:U")
end
end
end

0 comments on commit dd182b4

Please sign in to comment.