Skip to content

Commit

Permalink
Allow to configure blocks with the same name
Browse files Browse the repository at this point in the history
Change most data types from Hash to Array to allow multiple blocks with
the same name.  The key of each Hash is now the 'name' of each Struct.

While here, add an usage example to the README.
  • Loading branch information
smortex committed Jul 13, 2018
1 parent 49173a3 commit 10220d7
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 71 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,42 @@ class { '::collectd::plugin::thermal':

```puppet
class { 'collectd::plugin::threshold':
hosts => [
{
name => 'example.com',
plugins => [
{
name => 'load',
types => [
{
name => 'load',
data_source => 'shortterm',
warning_max => $facts.dig('processors', 'count') * 1.2,
failure_max => $facts.dig('processors', 'count') * 1.9,
},
{
name => 'load',
data_source => 'midterm',
warning_max => $facts.dig('processors', 'count') * 1.1,
failure_max => $facts.dig('processors', 'count') * 1.7,
},
{
name => 'load',
data_source => 'longterm',
warning_max => $facts.dig('processors', 'count'),
failure_max => $facts.dig('processors', 'count') * 1.5,
},
],
},
],
},
],
plugins => [
# See plugin definition above
],
types => [
# See types definition above
],
}
```

Expand Down
6 changes: 3 additions & 3 deletions manifests/plugin/threshold.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
class collectd::plugin::threshold (
$ensure = 'present',
$interval = undef,
Hash[String[1], Collectd::Threshold::Type] $types = {},
Hash[String[1], Collectd::Threshold::Plugin] $plugins = {},
Hash[String[1], Collectd::Threshold::Host] $hosts = {},
Array[Collectd::Threshold::Type] $types = [],
Array[Collectd::Threshold::Plugin] $plugins = [],
Array[Collectd::Threshold::Host] $hosts = [],
) {

include ::collectd
Expand Down
52 changes: 30 additions & 22 deletions spec/classes/collectd_plugin_threshold_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,61 @@

let :params do
{
'types' => {
'foo' => {
'types' => [
{
'name' => 'foo',
'warning_min' => 0.00,
'warning_max' => 1000.00,
'failure_min' => 0.00,
'failure_max' => 1200.00,
'invert' => false,
'instance' => 'bar'
}
},
'plugins' => {
'interface' => {
],
'plugins' => [
{
'name' => 'interface',
'instance' => 'eth0',
'types' => {
'if_octets' => {
'types' => [
{
'name' => 'if_octets',
'failure_max' => 10_000_000,
'data_source' => 'rx'
}
}
]
}
},
'hosts' => {
'hostname' => {
'types' => {
'cpu' => {
],
'hosts' => [
{
'name' => 'hostname',
'types' => [
{
'name' => 'cpu',
'instance' => 'idle',
'failure_min' => 10
},
'load' => {
{
'name' => 'load',
'data_source' => 'midterm',
'failure_max' => 4,
'hits' => 3,
'hysteresis' => 3
}
},
'plugins' => {
'memory' => {
'types' => {
'memory' => {
],
'plugins' => [
{
'name' => 'memory',
'types' => [
{
'name' =>'memory',
'instance' => 'cached',
'warning_min' => 100_000_000
}
}
]
}
}
]
}
}
]
}
end

Expand Down
12 changes: 6 additions & 6 deletions templates/plugin/threshold.conf.epp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Plugin "threshold">
<%- $collectd::plugin::threshold::hosts.each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/host.epp', {name => $name, values => $values })) -%>
<%- $collectd::plugin::threshold::hosts.each |$host| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/host.epp', { host => $host })) -%>
<%- } -%>
<%- $collectd::plugin::threshold::plugins.each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/plugin.epp', {name => $name, values => $values })) -%>
<%- $collectd::plugin::threshold::plugins.each |$plugin| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/plugin.epp', { plugin => $plugin })) -%>
<%- } -%>
<%- $collectd::plugin::threshold::types.each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', {name => $name, values => $values })) -%>
<%- $collectd::plugin::threshold::types.each |$type| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', { type => $type })) -%>
<%- } -%>
</Plugin>
10 changes: 5 additions & 5 deletions templates/plugin/threshold/host.epp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Host "<%= $name %>">
<%- $values['plugins'].each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/plugin.epp', {name => $name, values => $values })) -%>
<Host "<%= $host['name'] %>">
<%- $host['plugins'].each |$plugin| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/plugin.epp', { plugin => $plugin })) -%>
<%- } -%>
<%- $values['types'].each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', {name => $name, values => $values })) -%>
<%- $host['types'].each |$type| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', { type => $type })) -%>
<%- } -%>
</Host>
10 changes: 5 additions & 5 deletions templates/plugin/threshold/plugin.epp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Plugin "<%= $name %>">
<%- if $values['instance'] != undef { -%>
Instance "<%= $values['instance'] %>"
<Plugin "<%= $plugin['name'] %>">
<%- if $plugin['instance'] != undef { -%>
Instance "<%= $plugin['instance'] %>"
<%- } -%>
<%- $values['types'].each |$name, $values| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', {name => $name, values => $values })) -%>
<%- $plugin['types'].each |$type| { -%>
<%= collectd::indent(epp('collectd/plugin/threshold/type.epp', { type => $type })) -%>
<%- } -%>
</Plugin>
54 changes: 27 additions & 27 deletions templates/plugin/threshold/type.epp
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
<Type "<%= $name %>">
<%- if $values['instance'] != undef { -%>
Instance "<%= $values['instance'] %>"
<Type "<%= $type['name'] %>">
<%- if $type['instance'] != undef { -%>
Instance "<%= $type['instance'] %>"
<%- } -%>
<%- if $values['failure_max'] != undef { -%>
FailureMax <%= $values['failure_max'] %>
<%- if $type['failure_max'] != undef { -%>
FailureMax <%= $type['failure_max'] %>
<%- } -%>
<%- if $values['failure_min'] != undef { -%>
FailureMin <%= $values['failure_min'] %>
<%- if $type['failure_min'] != undef { -%>
FailureMin <%= $type['failure_min'] %>
<%- } -%>
<%- if $values['warning_max'] != undef { -%>
WarningMax <%= $values['warning_max'] %>
<%- if $type['warning_max'] != undef { -%>
WarningMax <%= $type['warning_max'] %>
<%- } -%>
<%- if $values['warning_min'] != undef { -%>
WarningMin <%= $values['warning_min'] %>
<%- if $type['warning_min'] != undef { -%>
WarningMin <%= $type['warning_min'] %>
<%- } -%>
<%- if $values['data_source'] != undef { -%>
DataSource "<%= $values['data_source'] %>"
<%- if $type['data_source'] != undef { -%>
DataSource "<%= $type['data_source'] %>"
<%- } -%>
<%- if $values['invert'] != undef { -%>
Invert <%= $values['invert'] %>
<%- if $type['invert'] != undef { -%>
Invert <%= $type['invert'] %>
<%- } -%>
<%- if $values['persist'] != undef { -%>
Persist <%= $values['persist'] %>
<%- if $type['persist'] != undef { -%>
Persist <%= $type['persist'] %>
<%- } -%>
<%- if $values['persist_ok'] != undef { -%>
PersistOK <%= $values['persist_ok'] %>
<%- if $type['persist_ok'] != undef { -%>
PersistOK <%= $type['persist_ok'] %>
<%- } -%>
<%- if $values['percentage'] != undef { -%>
Percentage <%= $values['percentage'] %>
<%- if $type['percentage'] != undef { -%>
Percentage <%= $type['percentage'] %>
<%- } -%>
<%- if $values['hits'] != undef { -%>
Hits <%= $values['hits'] %>
<%- if $type['hits'] != undef { -%>
Hits <%= $type['hits'] %>
<%- } -%>
<%- if $values['hysteresis'] != undef { -%>
Hysteresis <%= $values['hysteresis'] %>
<%- if $type['hysteresis'] != undef { -%>
Hysteresis <%= $type['hysteresis'] %>
<%- } -%>
<%- if $values['interesting'] != undef { -%>
Interesting <%= $values['interesting'] %>
<%- if $type['interesting'] != undef { -%>
Interesting <%= $type['interesting'] %>
<%- } -%>
</Type>
5 changes: 3 additions & 2 deletions types/threshold/host.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Collectd::Threshold::Host = Struct[{
plugins => Hash[String[1], Collectd::Threshold::Plugin],
types => Hash[String[1], Collectd::Threshold::Type],
name => String[1],
plugins => Array[Collectd::Threshold::Plugin],
types => Array[Collectd::Threshold::Type],
}]
3 changes: 2 additions & 1 deletion types/threshold/plugin.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Collectd::Threshold::Plugin = Struct[{
name => String[1],
instance => Optional[String[1]],
types => Hash[String[1], Collectd::Threshold::Type],
types => Array[Collectd::Threshold::Type],
}]
1 change: 1 addition & 0 deletions types/threshold/type.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Collectd::Threshold::Type = Struct[{
name => String[1],
instance => Optional[String[1]],
failure_max => Optional[Numeric],
warning_max => Optional[Numeric],
Expand Down

0 comments on commit 10220d7

Please sign in to comment.