forked from coderanger/chef-collectd
-
Notifications
You must be signed in to change notification settings - Fork 10
/
default.rb
119 lines (103 loc) · 2.59 KB
/
default.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#
# Cookbook Name:: collectd
# Recipe:: default
#
# Copyright 2010, Atari, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if platform_family?("rhel")
include_recipe "yum::epel"
end
platform_options = node["collectd"]["platform"]
platform_options["collectd_packages"].each do |pkg|
package pkg do
action :install
options platform_options["package_options"]
end
end
service "collectd" do
supports :restart => true, :status => true
action :enable
end
cookbook_file "/etc/init.d/collectd" do
source "collectd-init"
owner "root"
group "root"
mode "755"
only_if { platform?(%w(ubuntu debian)) }
end
directory "/etc/collectd" do
owner "root"
group "root"
mode "755"
end
directory "/etc/collectd/plugins" do
owner "root"
group "root"
mode "755"
end
directory "/etc/collectd/thresholds" do
owner "root"
group "root"
mode "755"
end
directory platform_options["collectd_base_dir"] do
owner "root"
group "root"
mode "755"
recursive true
end
directory platform_options["collectd_plugin_dir"] do
owner "root"
group "root"
mode "755"
recursive true
end
template platform_options["collectd_config_file"] do
source "collectd.conf.erb"
owner "root"
group "root"
mode "0644"
variables("collectd_base_dir" => platform_options["collectd_base_dir"],
"collectd_plugin_dir" => platform_options["collectd_plugin_dir"]
)
end
%w(collection thresholds).each do |file|
template "/etc/collectd/#{file}.conf" do
source "#{file}.conf.erb"
owner "root"
group "root"
mode "644"
notifies :restart, "service[collectd]"
end
end
Chef::Log.info("Running old plugin deleterator")
conf_files = Dir['/etc/collectd/plugins/*.conf'] \
+ Dir['/etc/collectd/thresholds/*.conf']
conf_files.each do |path|
autogen = false
File.open(path).each_line do |line|
if line.start_with?('#') and line.include?('autogenerated')
autogen = true
break
end
end
if autogen
if not node["monitoring"]["configs"].include?(path)
Chef::Log.info("Deleting old config in #{path}")
File.unlink(path)
end
end
end
node.set["monitoring"]["configs"] = []