Skip to content

Commit

Permalink
Merge pull request #827 from sileht/master
Browse files Browse the repository at this point in the history
Add tail_csv plugin
  • Loading branch information
bastelfreak committed Jul 10, 2018
2 parents b3d30c3 + ed3fc1f commit 5748e4a
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,29 @@ collectd::plugin::tail::file { 'exim-log':
}
```

#### Class: `collectd::plugin::tail_csv`

```puppet
class { '::collectd::plugin::tail_csv':
metrics => {
'snort-dropped' => {
'type' => 'gauge',
'values_from' => 1,
'instance' => "dropped"
},
},
files => {
'/var/log/snort/snort.stats' => {
'collect' => ['snort-dropped'],
'plugin' => 'snortstats',
'instance' => 'eth0',
'interval' => 600,
'time_from' => 5,
}
}
}
```

#### Class: `collectd::plugin::thermal`

```puppet
Expand Down
15 changes: 15 additions & 0 deletions manifests/plugin/tail_csv.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_tail_csv
class collectd::plugin::tail_csv (
Hash[String, Collectd::Tail_Csv::Metric, 1] $metrics,
Hash[String, Collectd::Tail_Csv::File, 1] $files,
Enum['present', 'absent'] $ensure = 'present',
Integer $order = 10,
) {
include collectd

collectd::plugin { 'tail_csv':
ensure => $ensure,
content => epp('collectd/plugin/tail_csv.conf.epp'),
order => $order,
}
}
123 changes: 123 additions & 0 deletions spec/classes/collectd_plugin_tail_csv_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
require 'spec_helper'

describe 'collectd::plugin::tail_csv', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

options = os_specific_options(facts)
context 'Minimal attributes' do
let :params do
{
'metrics' => {
'snort-dropped' => {
'type' => 'percent',
'value_from' => 1
}
},
'files' => {
'/var/log/snort/snort.stats' => {
'collect' => %w[snort-dropped]
}
}
}
end

it 'overrides defaults' do
content = <<EOS
# Generated by Puppet
<LoadPlugin tail_csv>
Globals false
</LoadPlugin>
<Plugin "tail_csv">
<Metric "snort-dropped">
Type "percent"
ValueFrom 1
</Metric>
<File "/var/log/snort/snort.stats">
Collect "snort-dropped"
</File>
</Plugin>
EOS

is_expected.to compile.with_all_deps
is_expected.to contain_class('collectd')
is_expected.to contain_file('tail_csv.load').with(
content: content,
path: "#{options[:plugin_conf_dir]}/10-tail_csv.conf"
)
end
end

context 'All attributes' do
let :params do
{
'metrics' => {
'snort-dropped' => {
'type' => 'percent',
'value_from' => 1,
'instance' => 'dropped'
},
'snort-reject' => {
'type' => 'percent',
'value_from' => 2,
'instance' => 'reject'
}
},
'files' => {
'/var/log/snort/snort.stats' => {
'collect' => %w[snort-dropped snort-reject],
'plugin' => 'snortstats',
'instance' => 'eth0',
'interval' => 600,
'time_from' => 5
}
}
}
end

it 'overrides defaults' do
content = <<EOS
# Generated by Puppet
<LoadPlugin tail_csv>
Globals false
</LoadPlugin>
<Plugin "tail_csv">
<Metric "snort-dropped">
Type "percent"
Instance "dropped"
ValueFrom 1
</Metric>
<Metric "snort-reject">
Type "percent"
Instance "reject"
ValueFrom 2
</Metric>
<File "/var/log/snort/snort.stats">
Plugin "snortstats"
Instance "eth0"
Collect "snort-dropped"
Collect "snort-reject"
Interval 600
TimeFrom 5
</File>
</Plugin>
EOS

is_expected.to compile.with_all_deps
is_expected.to contain_class('collectd')
is_expected.to contain_file('tail_csv.load').with(
content: content,
path: "#{options[:plugin_conf_dir]}/10-tail_csv.conf"
)
end
end
end
end
end
34 changes: 34 additions & 0 deletions templates/plugin/tail_csv.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Plugin "tail_csv">
<% $collectd::plugin::tail_csv::metrics.each |$name, $metric| { -%>
<Metric "<%= $name %>">
<% unless $metric['type'] =~ Undef { -%>
Type "<%= $metric['type'] %>"
<% } -%>
<% unless $metric['instance'] =~ Undef { -%>
Instance "<%= $metric['instance'] %>"
<% } -%>
<% unless $metric['value_from'] =~ Undef { -%>
ValueFrom <%= $metric['value_from'] %>
<% } -%>
</Metric>
<% } -%>
<% $collectd::plugin::tail_csv::files.each |$path, $file| { -%>
<File "<%= $path %>">
<% unless $file['plugin'] =~ Undef { -%>
Plugin "<%= $file['plugin'] %>"
<% } -%>
<% unless $file['instance'] =~ Undef { -%>
Instance "<%= $file['instance'] %>"
<% } -%>
<% $file['collect'].each |$collect| { -%>
Collect "<%= $collect %>"
<% } -%>
<% unless $file['interval'] =~ Undef { -%>
Interval <%= $file['interval'] %>
<% } -%>
<% unless $file['time_from'] =~ Undef { -%>
TimeFrom <%= $file['time_from'] %>
<% } -%>
</File>
<% } -%>
</Plugin>
8 changes: 8 additions & 0 deletions types/tail_csv/file.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_tail_csv
type Collectd::Tail_Csv::File = Struct[{
'collect' => Array[String, 1],
'plugin' => Optional[String[1]],
'instance' => Optional[String[1]],
'interval' => Optional[Numeric],
'time_from' => Optional[Integer[0]],
}]
6 changes: 6 additions & 0 deletions types/tail_csv/metric.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_tail_csv
type Collectd::Tail_Csv::Metric = Struct[{
'type' => String[1],
'value_from' => Integer[0],
'instance' => Optional[String[1]],
}]

0 comments on commit 5748e4a

Please sign in to comment.