]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/resources/plugin.rb
hardware: do not fail if node[:hardware][:pci] is undefined (tests)
[chef.git] / cookbooks / munin / resources / plugin.rb
1 #
2 # Cookbook:: munin
3 # Provider:: munin_plugin
4 #
5 # Copyright:: 2013, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 unified_mode true
21
22 default_action :create
23
24 property :plugin, :kind_of => String, :name_property => true
25 property :target, :kind_of => String
26 property :conf, :kind_of => String
27 property :conf_cookbook, :kind_of => String
28 property :conf_variables, :kind_of => Hash, :default => {}
29 property :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
30
31 action :create do
32   link_action = case target_path
33                 when nil then :delete
34                 else :create
35                 end
36
37   link plugin_path do
38     action link_action
39     to target_path
40   end
41
42   if new_resource.conf
43     munin_plugin_conf new_resource.plugin do
44       cookbook new_resource.conf_cookbook
45       template new_resource.conf
46       variables new_resource.conf_variables
47       restart_munin false
48     end
49   end
50 end
51
52 action :delete do
53   link plugin_path do
54     action :delete
55   end
56
57   if new_resource.conf
58     munin_plugin_conf new_resource.plugin do
59       action :delete
60       restart_munin false
61     end
62   end
63 end
64
65 action_class do
66   def plugin_path
67     "/etc/munin/plugins/#{new_resource.plugin}"
68   end
69
70   def target_path
71     if ::File.exist?(target)
72       target
73     elsif ::File.exist?("/usr/local/share/munin/plugins/#{target}")
74       "/usr/local/share/munin/plugins/#{target}"
75     elsif ::File.exist?("/usr/share/munin/plugins/#{target}")
76       "/usr/share/munin/plugins/#{target}"
77     end
78   end
79
80   def target
81     new_resource.target || new_resource.plugin
82   end
83 end
84
85 def after_created
86   notifies :restart, "service[munin-node]" if restart_munin
87 end