Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tail_csv plugin #827

Merged
merged 1 commit into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,29 @@ collectd::plugin::tail::file { 'exim-log':
}
```

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

```puppet
class { '::collectd::plugin::tail_csv':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use the leading ::. This is a puppet 3 relic that isn't needed anymore.

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]],
}]