Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
Basic collectd.conf handling for single and multiple-value directives
Browse files Browse the repository at this point in the history
This is the basic type and provider for managing the collectd.conf file.
  • Loading branch information
DavidS committed Jun 30, 2008
0 parents commit d8226d6
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/example.pp
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' ];
}
3 changes: 3 additions & 0 deletions files/collectd.conf
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"
49 changes: 49 additions & 0 deletions manifests/init.pp
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
}
}
}
58 changes: 58 additions & 0 deletions plugins/puppet/provider/collectd_conf/parsed.rb
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

41 changes: 41 additions & 0 deletions plugins/puppet/type/collectd_conf.rb
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

0 comments on commit d8226d6

Please sign in to comment.