This repository has been archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic collectd.conf handling for single and multiple-value directives
This is the basic type and provider for managing the collectd.conf file.
- Loading branch information
0 parents
commit d8226d6
Showing
5 changed files
with
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Exec { path => '/sbin:/bin:/usr/sbin:/usr/bin' } | ||
|
||
filebucket { 'server': } | ||
|
||
import "common" | ||
import "collectd" | ||
|
||
include collectd | ||
|
||
collectd_conf { | ||
'BaseDir': value => 'foo'; | ||
'Server': value => [ '"foo" 1000', '"foo2" 2000' ]; | ||
} |
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,3 @@ | ||
Include "/var/lib/puppet/modules/collectd/main.conf" | ||
Include "/var/lib/puppet/modules/collectd/plugins/*.conf" | ||
Include "/var/lib/puppet/modules/collectd/tresholds/*.conf" |
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,49 @@ | ||
# collectd/manifests/init.pp - statistics collection and monitoring daemon | ||
# (C) Copyright: 2008, David Schmitt <david@dasz.at> | ||
|
||
class collectd { | ||
|
||
modules_dir { ['collectd', 'collectd/plugins', 'collectd/thresholds' ]: } | ||
|
||
package { | ||
'collectd': | ||
ensure => installed; | ||
} | ||
|
||
service { | ||
'collectd': | ||
ensure => running, | ||
enable => true, | ||
hasrestart => true, | ||
pattern => collectd, | ||
require => Package['collectd']; | ||
} | ||
|
||
config_file { | ||
'/etc/collectd/collectd.conf': | ||
ensure => present, | ||
require => Package['collectd'], | ||
notify => Service['collectd']; | ||
} | ||
|
||
collectd_conf { | ||
'Include': | ||
value => [ | ||
'"/var/lib/puppet/modules/collectd/plugins/*.conf"', | ||
'"/var/lib/puppet/modules/collectd/thresholds/*.conf"' | ||
]; | ||
} | ||
|
||
# add customisations for distributions here | ||
case $operatingsystem { | ||
'debian': { | ||
case $debianversion { | ||
'etch': { | ||
} | ||
} | ||
} | ||
default: { | ||
# no changes needed | ||
} | ||
} | ||
} |
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,58 @@ | ||
require 'puppet/provider/parsedfile' | ||
|
||
Puppet::Type.type(:collectd_conf).provide(:parsed, | ||
:parent => Puppet::Provider::ParsedFile, | ||
:default_target => "/etc/collectd/collectd.conf" | ||
) do | ||
|
||
text_line :comment, :match => %r{^#} | ||
|
||
text_line :blank, :match => %r{^\s*$} | ||
|
||
config = record_line :parsed, :fields => %w{name value}, | ||
:match => %r{^\s*(\S+)\s+(.*)$} | ||
|
||
class << config | ||
def to_line(record) | ||
values = [ record[:value] ] | ||
if record[:value].is_a? Array | ||
values = record[:value] | ||
end | ||
values.collect do |v| "%s %s" % [ record[:name], v ] end.join("\n") | ||
end | ||
end | ||
|
||
# coalesce configuration directives with multiple values | ||
def self.prefetch_hook(records) | ||
|
||
sorted_records = {} | ||
|
||
records.each { |record| | ||
|
||
value = nil | ||
if record[:value] | ||
unless record[:value].is_a?(Array) | ||
value = [ record[:value] ] | ||
else | ||
value = record[:value] | ||
end | ||
end | ||
|
||
real_record = nil | ||
if sorted_records[record[:name]] | ||
real_record = sorted_records[record[:name]] | ||
value += real_record[:value] | ||
else | ||
real_record = record | ||
end | ||
|
||
real_record[:value] = value | ||
sorted_records[record[:name]] = real_record | ||
} | ||
|
||
sorted_records.values.collect { |record| | ||
record | ||
} | ||
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,41 @@ | ||
|
||
Puppet::Type.newtype(:collectd_conf) do | ||
@doc = "Manages the basic statements collectd.conf file" | ||
|
||
ensurable | ||
|
||
newparam(:key) do | ||
desc "The configuration key" | ||
isnamevar | ||
end | ||
|
||
newproperty(:target) do | ||
desc "Which file to write to." | ||
defaultto "/etc/collectd/collectd.conf" | ||
end | ||
|
||
newproperty(:value, :array_matching => :all) do | ||
desc "The value to set. Use an array to set a key multiple times" | ||
|
||
def should_to_s(newvalue = @should) | ||
val_to_s(newvalue) | ||
end | ||
|
||
def is_to_s(currentvalue = @is) | ||
val_to_s(currentvalue) | ||
end | ||
|
||
# format an array of values for display | ||
def val_to_s(val) | ||
if val | ||
unless val.is_a?(Array) | ||
val = [val] | ||
end | ||
val.join(",") | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
|