]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/providers/plugin.rb
e469acb6d1610a70e4d8c7d3a74f9189c666b1fa
[chef.git] / cookbooks / munin / providers / plugin.rb
1 #
2 # Cookbook Name:: 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 #     http://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 def whyrun_supported?
21   true
22 end
23
24 use_inline_resources
25
26 action :create do
27   link_action = case target_path
28                 when nil then :delete
29                 else :create
30                 end
31
32   link plugin_path do
33     action link_action
34     to target_path
35   end
36
37   if new_resource.conf # ~FC023
38     munin_plugin_conf new_resource.name do
39       cookbook new_resource.conf_cookbook
40       template new_resource.conf
41       variables new_resource.conf_variables
42     end
43   end
44 end
45
46 action :delete do
47   link plugin_path do
48     action :delete
49   end
50
51   if new_resource.conf # ~FC023
52     munin_plugin_conf new_resource.name do
53       action :delete
54     end
55   end
56 end
57
58 def plugin_path
59   "/etc/munin/plugins/#{new_resource.name}"
60 end
61
62 def target_path
63   case
64   when ::File.exist?(target)
65     target
66   when ::File.exist?("/usr/local/share/munin/plugins/#{target}")
67     "/usr/local/share/munin/plugins/#{target}"
68   when ::File.exist?("/usr/share/munin/plugins/#{target}")
69     "/usr/share/munin/plugins/#{target}"
70   end
71 end
72
73 def target
74   new_resource.target || new_resource.name
75 end