-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #827 from sileht/master
Add tail_csv plugin
- Loading branch information
Showing
6 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]], | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]], | ||
}] |