Skip to content

Commit

Permalink
Merge pull request #681 from trustchk/nut
Browse files Browse the repository at this point in the history
Add support for nut plugin (#621)
  • Loading branch information
bastelfreak authored May 20, 2018
2 parents d95540c + 3364978 commit c49a059
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ documentation for each plugin for configurable attributes.
* `nfs` (see [collectd::plugin::nfs](#class-collectdpluginnfs) below)
* `nginx` (see [collectd::plugin::nginx](#class-collectdpluginnginx) below)
* `ntpd` (see [collectd::plugin::ntpd](#class-collectdpluginntpd) below)
* `nut` (see [collectd::plugin::nut](#class-collectdpluginnut) below)
* `openldap` (see [collectd::plugin::openldap](#class-collectdpluginopenldap) below)
* `openvpn` (see [collectd::plugin::openvpn](#class-collectdpluginopenvpn) below)
* `perl` (see [collectd::plugin::perl](#class-collectdpluginperl) below)
Expand Down Expand Up @@ -1118,6 +1119,13 @@ class { 'collectd::plugin::ntpd':
includeunitid => false,
}
```
#### Class: `collectd::plugin::nut`

```puppet
class { 'collectd::plugin::nut':
upss => [ 'ups@localhost:port' ]
}
```

#### Class: `collectd::plugin::openldap`

Expand Down
18 changes: 18 additions & 0 deletions manifests/plugin/nut.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://collectd.org/wiki/index.php/Plugin:Nut
class collectd::plugin::nut (
$ensure = 'present',
$upss = { },
) {

include collectd


collectd::plugin { 'nut':
ensure => $ensure,
}
$upss.each |String $ups| {
collectd::plugin::nut::ups { $upss:
ensure => $ensure,
}
}
}
19 changes: 19 additions & 0 deletions manifests/plugin/nut/ups.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
define collectd::plugin::nut::ups (
$ensure = 'present',
) {

include collectd
include collectd::plugin::nut

$conf_dir = $collectd::plugin_conf_dir

file { "${conf_dir}/nut-ups-${name}.conf":
ensure => $ensure,
mode => $collectd::config_mode,
owner => $collectd::config_owner,
group => $collectd::config_group,
content => template('collectd/plugin/nut/ups.conf.erb'),
notify => Service['collectd'],
}
}
37 changes: 37 additions & 0 deletions spec/classes/collectd_plugin_nut_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

describe 'collectd::plugin::nut', type: :class do
let :pre_condition do
'include ::collectd'
end

on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

context ':ensure => present, default params' do
it 'Will create /etc/collectd.d/10-nut.conf' do
is_expected.to contain_file('nut.load').
with(ensure: 'present',
path: '/etc/collectd.d/10-nut.conf',
content: %r{LoadPlugin nut})
end
end

context ':ensure => present, single entry' do
let :params do
{ upss: ['ups1@localhost'] }
end

it 'Will create /etc/collectd.d/[email protected]' do
is_expected.to contain_file('/etc/collectd.d/[email protected]').
with(ensure: 'present',
path: '/etc/collectd.d/[email protected]',
content: %r{UPS "ups1@localhost"})
end
end
end
end
end
3 changes: 3 additions & 0 deletions templates/plugin/nut/ups.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Plugin nut>
UPS "<%= @name %>"
</Plugin>

0 comments on commit c49a059

Please sign in to comment.