cloud-mu 3.6.10 → 3.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +2 -3
  3. data/Berksfile.lock +11 -14
  4. data/bin/mu-aws-setup +16 -4
  5. data/bin/mu-configure +2 -1
  6. data/cloud-mu.gemspec +2 -2
  7. data/cookbooks/mu-firewall/Berksfile +1 -1
  8. data/cookbooks/mu-firewall/attributes/default.rb +2 -2
  9. data/cookbooks/mu-firewall/metadata.rb +3 -3
  10. data/cookbooks/mu-firewall/recipes/default.rb +11 -2
  11. data/cookbooks/mu-master/Berksfile +1 -1
  12. data/cookbooks/mu-master/attributes/default.rb +14 -1
  13. data/cookbooks/mu-master/files/default/389ds-perl/ASDialogs.pm +173 -0
  14. data/cookbooks/mu-master/files/default/389ds-perl/AdminMigration.pm +569 -0
  15. data/cookbooks/mu-master/files/default/389ds-perl/AdminServer.pm +952 -0
  16. data/cookbooks/mu-master/files/default/389ds-perl/AdminUtil.pm +983 -0
  17. data/cookbooks/mu-master/files/default/389ds-perl/ConfigDSDialogs.pm +449 -0
  18. data/cookbooks/mu-master/files/default/389ds-perl/DSCreate.pm +1551 -0
  19. data/cookbooks/mu-master/files/default/389ds-perl/DSDialogs.pm +233 -0
  20. data/cookbooks/mu-master/files/default/389ds-perl/DSMigration.pm +1175 -0
  21. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdate.pm +534 -0
  22. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdateDialogs.pm +152 -0
  23. data/cookbooks/mu-master/files/default/389ds-perl/DSUtil.pm +1710 -0
  24. data/cookbooks/mu-master/files/default/389ds-perl/Dialog.pm +249 -0
  25. data/cookbooks/mu-master/files/default/389ds-perl/DialogManager.pm +212 -0
  26. data/cookbooks/mu-master/files/default/389ds-perl/FileConn.pm +461 -0
  27. data/cookbooks/mu-master/files/default/389ds-perl/Inf.pm +268 -0
  28. data/cookbooks/mu-master/files/default/389ds-perl/Migration.pm +327 -0
  29. data/cookbooks/mu-master/files/default/389ds-perl/RegDSDialogs.pm +94 -0
  30. data/cookbooks/mu-master/files/default/389ds-perl/Resource.pm +137 -0
  31. data/cookbooks/mu-master/files/default/389ds-perl/Setup.pm +240 -0
  32. data/cookbooks/mu-master/files/default/389ds-perl/SetupDialogs.pm +243 -0
  33. data/cookbooks/mu-master/files/default/389ds-perl/SetupLog.pm +82 -0
  34. data/cookbooks/mu-master/files/default/setCertName.ldif +4 -0
  35. data/cookbooks/mu-master/libraries/mu.rb +2 -2
  36. data/cookbooks/mu-master/metadata.rb +1 -1
  37. data/cookbooks/mu-master/recipes/389ds.rb +71 -32
  38. data/cookbooks/mu-master/recipes/basepackages.rb +5 -0
  39. data/cookbooks/mu-master/recipes/default.rb +16 -5
  40. data/cookbooks/mu-master/recipes/init.rb +36 -3
  41. data/cookbooks/mu-master/recipes/ssl-certs.rb +6 -0
  42. data/cookbooks/mu-master/recipes/sssd.rb +85 -62
  43. data/cookbooks/mu-master/recipes/update_nagios_only.rb +7 -1
  44. data/cookbooks/mu-master/templates/default/389-directory-setup.inf.erb +11 -26
  45. data/cookbooks/mu-master/templates/default/sssd.conf.erb +18 -8
  46. data/cookbooks/mu-tools/files/default/Mu_CA.pem +33 -0
  47. data/cookbooks/mu-tools/metadata.rb +0 -1
  48. data/cookbooks/mu-tools/recipes/set_local_fw.rb +7 -1
  49. data/cookbooks/mu-tools/templates/amazon/sshd_config.erb +5 -1
  50. data/cookbooks/nagios/CHANGELOG.md +679 -0
  51. data/cookbooks/nagios/LICENSE +201 -0
  52. data/cookbooks/nagios/README.md +340 -0
  53. data/cookbooks/nagios/attributes/config.rb +163 -0
  54. data/cookbooks/nagios/attributes/default.rb +204 -0
  55. data/cookbooks/nagios/libraries/base.rb +311 -0
  56. data/cookbooks/nagios/libraries/command.rb +68 -0
  57. data/cookbooks/nagios/libraries/contact.rb +229 -0
  58. data/cookbooks/nagios/libraries/contactgroup.rb +111 -0
  59. data/cookbooks/{firewall/recipes/disable_firewall.rb → nagios/libraries/custom_option.rb} +20 -7
  60. data/cookbooks/nagios/libraries/data_bag_helper.rb +23 -0
  61. data/cookbooks/nagios/libraries/default.rb +90 -0
  62. data/cookbooks/nagios/libraries/helpers.rb +229 -0
  63. data/cookbooks/nagios/libraries/host.rb +410 -0
  64. data/cookbooks/nagios/libraries/hostdependency.rb +178 -0
  65. data/cookbooks/nagios/libraries/hostescalation.rb +170 -0
  66. data/cookbooks/nagios/libraries/hostgroup.rb +117 -0
  67. data/cookbooks/nagios/libraries/nagios.rb +277 -0
  68. data/cookbooks/nagios/libraries/resource.rb +59 -0
  69. data/cookbooks/nagios/libraries/service.rb +449 -0
  70. data/cookbooks/nagios/libraries/servicedependency.rb +213 -0
  71. data/cookbooks/nagios/libraries/serviceescalation.rb +193 -0
  72. data/cookbooks/nagios/libraries/servicegroup.rb +142 -0
  73. data/cookbooks/nagios/libraries/timeperiod.rb +159 -0
  74. data/cookbooks/nagios/libraries/users_helper.rb +54 -0
  75. data/cookbooks/nagios/metadata.json +44 -0
  76. data/cookbooks/nagios/metadata.rb +22 -0
  77. data/cookbooks/nagios/recipes/_load_databag_config.rb +153 -0
  78. data/cookbooks/nagios/recipes/_load_default_config.rb +241 -0
  79. data/cookbooks/nagios/recipes/apache.rb +114 -0
  80. data/cookbooks/nagios/recipes/default.rb +41 -0
  81. data/cookbooks/nagios/recipes/nginx.rb +114 -0
  82. data/cookbooks/nagios/recipes/pagerduty.rb +95 -0
  83. data/cookbooks/nagios/recipes/server.rb +182 -0
  84. data/cookbooks/nagios/recipes/server_package.rb +85 -0
  85. data/cookbooks/nagios/recipes/server_source.rb +137 -0
  86. data/cookbooks/nagios/resources/command.rb +34 -0
  87. data/cookbooks/nagios/resources/conf.rb +52 -0
  88. data/cookbooks/nagios/resources/contact.rb +34 -0
  89. data/cookbooks/nagios/resources/contactgroup.rb +35 -0
  90. data/cookbooks/nagios/resources/host.rb +35 -0
  91. data/cookbooks/nagios/resources/hostdependency.rb +35 -0
  92. data/cookbooks/nagios/resources/hostescalation.rb +36 -0
  93. data/cookbooks/nagios/resources/hostgroup.rb +35 -0
  94. data/cookbooks/nagios/resources/resource.rb +34 -0
  95. data/cookbooks/nagios/resources/service.rb +35 -0
  96. data/cookbooks/nagios/resources/servicedependency.rb +35 -0
  97. data/cookbooks/nagios/resources/serviceescalation.rb +35 -0
  98. data/cookbooks/nagios/resources/servicegroup.rb +35 -0
  99. data/cookbooks/nagios/resources/timeperiod.rb +35 -0
  100. data/cookbooks/nagios/templates/apache2.conf.erb +102 -0
  101. data/cookbooks/nagios/templates/cgi.cfg.erb +266 -0
  102. data/cookbooks/nagios/templates/commands.cfg.erb +13 -0
  103. data/cookbooks/nagios/templates/contacts.cfg.erb +37 -0
  104. data/cookbooks/nagios/templates/hostgroups.cfg.erb +25 -0
  105. data/cookbooks/nagios/templates/hosts.cfg.erb +15 -0
  106. data/cookbooks/nagios/templates/htpasswd.users.erb +6 -0
  107. data/cookbooks/nagios/templates/nagios.cfg.erb +22 -0
  108. data/cookbooks/nagios/templates/nginx.conf.erb +80 -0
  109. data/cookbooks/nagios/templates/pagerduty.cgi.erb +185 -0
  110. data/cookbooks/nagios/templates/resource.cfg.erb +27 -0
  111. data/cookbooks/nagios/templates/servicedependencies.cfg.erb +15 -0
  112. data/cookbooks/nagios/templates/servicegroups.cfg.erb +14 -0
  113. data/cookbooks/nagios/templates/services.cfg.erb +14 -0
  114. data/cookbooks/nagios/templates/spawn-fcgi.erb +10 -0
  115. data/cookbooks/nagios/templates/templates.cfg.erb +31 -0
  116. data/cookbooks/nagios/templates/timeperiods.cfg.erb +13 -0
  117. data/extras/platform_berksfile_base +3 -3
  118. data/extras/python_rpm/build.sh +4 -4
  119. data/extras/python_rpm/muthon.spec +2 -4
  120. data/extras/vault_tools/export_vaults.sh +11 -1
  121. data/install/installer +1 -1
  122. data/modules/mu/kittens.rb +27523 -0
  123. data/modules/mu/master/ldap.rb +48 -31
  124. data/modules/mu/master.rb +69 -0
  125. data/modules/mu/mu.yaml.rb +351 -0
  126. data/modules/mu/providers/aws/firewall_rule.rb +3 -1
  127. data/modules/mu/providers/aws.rb +11 -5
  128. data/modules/mu.rb +5 -4
  129. metadata +99 -48
  130. data/cookbooks/firewall/CHANGELOG.md +0 -488
  131. data/cookbooks/firewall/LICENSE +0 -202
  132. data/cookbooks/firewall/README.md +0 -366
  133. data/cookbooks/firewall/TODO.md +0 -6
  134. data/cookbooks/firewall/attributes/default.rb +0 -5
  135. data/cookbooks/firewall/attributes/firewalld.rb +0 -8
  136. data/cookbooks/firewall/attributes/iptables.rb +0 -17
  137. data/cookbooks/firewall/attributes/ufw.rb +0 -12
  138. data/cookbooks/firewall/attributes/windows.rb +0 -8
  139. data/cookbooks/firewall/libraries/helpers.rb +0 -105
  140. data/cookbooks/firewall/libraries/helpers_firewalld.rb +0 -116
  141. data/cookbooks/firewall/libraries/helpers_firewalld_dbus.rb +0 -72
  142. data/cookbooks/firewall/libraries/helpers_iptables.rb +0 -112
  143. data/cookbooks/firewall/libraries/helpers_nftables.rb +0 -170
  144. data/cookbooks/firewall/libraries/helpers_ufw.rb +0 -142
  145. data/cookbooks/firewall/libraries/helpers_windows.rb +0 -129
  146. data/cookbooks/firewall/libraries/provider_firewall_firewalld.rb +0 -179
  147. data/cookbooks/firewall/libraries/provider_firewall_iptables.rb +0 -171
  148. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu.rb +0 -200
  149. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu1404.rb +0 -200
  150. data/cookbooks/firewall/libraries/provider_firewall_rule.rb +0 -34
  151. data/cookbooks/firewall/libraries/provider_firewall_ufw.rb +0 -138
  152. data/cookbooks/firewall/libraries/provider_firewall_windows.rb +0 -126
  153. data/cookbooks/firewall/libraries/resource_firewall.rb +0 -26
  154. data/cookbooks/firewall/libraries/resource_firewall_rule.rb +0 -52
  155. data/cookbooks/firewall/metadata.json +0 -40
  156. data/cookbooks/firewall/metadata.rb +0 -15
  157. data/cookbooks/firewall/recipes/default.rb +0 -76
  158. data/cookbooks/firewall/recipes/firewalld.rb +0 -87
  159. data/cookbooks/firewall/resources/firewalld.rb +0 -28
  160. data/cookbooks/firewall/resources/firewalld_config.rb +0 -39
  161. data/cookbooks/firewall/resources/firewalld_helpers.rb +0 -106
  162. data/cookbooks/firewall/resources/firewalld_icmptype.rb +0 -88
  163. data/cookbooks/firewall/resources/firewalld_ipset.rb +0 -104
  164. data/cookbooks/firewall/resources/firewalld_policy.rb +0 -115
  165. data/cookbooks/firewall/resources/firewalld_service.rb +0 -98
  166. data/cookbooks/firewall/resources/firewalld_zone.rb +0 -118
  167. data/cookbooks/firewall/resources/nftables.rb +0 -71
  168. data/cookbooks/firewall/resources/nftables_rule.rb +0 -113
  169. data/cookbooks/firewall/templates/default/ufw/default.erb +0 -13
  170. /data/cookbooks/{firewall → nagios}/chefignore +0 -0
  171. /data/cookbooks/{firewall → nagios}/renovate.json +0 -0
@@ -0,0 +1,311 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: base
5
+ #
6
+ # Copyright:: 2014, Sander Botman
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ class Nagios
22
+ # This class it the base for all other Nagios classes.
23
+ # It provides common methods to prevent code duplication.
24
+ class Base
25
+ attr_accessor :register,
26
+ :name,
27
+ :use,
28
+ :not_modifiers
29
+
30
+ def initialize
31
+ @add_modifiers = {}
32
+ @not_modifiers = Hash.new { |h, k| h[k] = {} }
33
+ end
34
+
35
+ def merge!(obj)
36
+ merge_members(obj)
37
+ merge_attributes(obj)
38
+ end
39
+
40
+ def merge_members!(obj)
41
+ merge_members(obj)
42
+ end
43
+
44
+ def register
45
+ return @register if blank?(@name)
46
+ 0
47
+ end
48
+
49
+ def register=(arg)
50
+ @register = check_bool(arg)
51
+ end
52
+
53
+ def use
54
+ default_template
55
+ end
56
+
57
+ private
58
+
59
+ def blank?(expr)
60
+ return true if expr.nil?
61
+ case expr
62
+ when 'String', String
63
+ return true if expr == ''
64
+ when 'Array', 'Hash', Array, Hash
65
+ return true if expr.empty?
66
+ else
67
+ false
68
+ end
69
+ false
70
+ end
71
+
72
+ def check_bool(arg)
73
+ return 1 if arg.class == TrueClass
74
+ return 1 if arg.to_s =~ /^y|yes|true|on|1$/i
75
+ 0
76
+ end
77
+
78
+ def check_integer(int)
79
+ return int.to_i if int.class == String
80
+ int
81
+ end
82
+
83
+ def check_state_option(arg, options, entry)
84
+ if options.include?(arg)
85
+ Chef::Log.debug("#{self.class} #{self} adding option #{arg} for entry #{entry}")
86
+ else
87
+ Chef::Log.fail("#{self.class} #{self} object error: Unknown option #{arg} for entry #{entry}")
88
+ raise 'Unknown option'
89
+ end
90
+ end
91
+
92
+ def check_state_options(arg, options, entry)
93
+ if arg.class == String
94
+ check_state_options(arg.split(','), options, entry)
95
+ elsif arg.class == Array
96
+ arg.each { |a| check_state_option(a.strip, options, entry) }.join(',')
97
+ else
98
+ arg
99
+ end
100
+ end
101
+
102
+ def check_use_and_name(default)
103
+ return if default.nil?
104
+ return if to_s == default.to_s
105
+ default
106
+ end
107
+
108
+ def default_template
109
+ return @use unless @use.nil?
110
+ return if @name
111
+ case self
112
+ when Nagios::Command
113
+ check_use_and_name(Nagios.instance.default_command)
114
+ when Nagios::Contactgroup
115
+ check_use_and_name(Nagios.instance.default_contactgroup)
116
+ when Nagios::Contact
117
+ check_use_and_name(Nagios.instance.default_contact)
118
+ when Nagios::Hostgroup
119
+ check_use_and_name(Nagios.instance.default_hostgroup)
120
+ when Nagios::Host
121
+ check_use_and_name(Nagios.instance.default_host)
122
+ when Nagios::Servicegroup
123
+ check_use_and_name(Nagios.instance.default_servicegroup)
124
+ when Nagios::Service
125
+ check_use_and_name(Nagios.instance.default_service)
126
+ when Nagios::Timeperiod
127
+ check_use_and_name(Nagios.instance.default_timeperiod)
128
+ end
129
+ end
130
+
131
+ def get_commands(obj)
132
+ obj.map(&:to_s).join(',')
133
+ end
134
+
135
+ def configured_option(method, option)
136
+ value = send(method)
137
+ return if blank?(value)
138
+ value = value.split(',') if value.is_a? String
139
+ value = value.map do |e|
140
+ (@not_modifiers[option][e] || '') + e
141
+ end.join(',') if value.is_a? Array
142
+ value
143
+ end
144
+
145
+ def configured_options
146
+ configured = {}
147
+ config_options.each do |m, o|
148
+ next if o.nil?
149
+ value = configured_option(m, o)
150
+ next if value.nil?
151
+ configured[o] = value
152
+ end
153
+ configured
154
+ end
155
+
156
+ def get_definition(options, group)
157
+ return if to_s == '*'
158
+ return if to_s == 'null'
159
+ return if to_s.start_with? '!'
160
+ d = ["define #{group} {"]
161
+ d += get_definition_options(options)
162
+ d += ['}']
163
+ d.join("\n")
164
+ end
165
+
166
+ def get_definition_options(options)
167
+ r = []
168
+ longest = get_longest_option(options)
169
+ options.each do |k, v|
170
+ k = k.to_s
171
+ v = (@add_modifiers[k] || '') + v.to_s
172
+ diff = longest - k.length
173
+ r.push(k.rjust(k.length + 2) + v.rjust(v.length + diff + 2))
174
+ end
175
+ r
176
+ end
177
+
178
+ def get_longest_option(options)
179
+ longest = 0
180
+ options.each do |k, _|
181
+ longest = k.length if longest < k.length
182
+ end
183
+ longest
184
+ end
185
+
186
+ def get_members(option, object)
187
+ members = []
188
+ case option
189
+ when String
190
+ members = object == Nagios::Command ? [option] : option.split(',')
191
+ members.map(&:strip!)
192
+ when Array
193
+ members = option
194
+ else
195
+ Chef::Log.fail("Nagios fail: Use an Array or comma seperated String for option: #{option} within #{self.class}")
196
+ raise 'Use an Array or comma seperated String for option'
197
+ end
198
+ members
199
+ end
200
+
201
+ def get_timeperiod(obj)
202
+ return if obj.nil?
203
+ return obj.to_s if obj.class == Nagios::Timeperiod
204
+ obj
205
+ end
206
+
207
+ def merge_attributes(obj)
208
+ config_options.each do |m, _|
209
+ n = obj.send(m)
210
+ next if n.nil?
211
+ m += '='
212
+ send(m, n) if respond_to?(m)
213
+ end
214
+ end
215
+
216
+ def merge_members(obj)
217
+ Chef::Log.debug("Nagios debug: The method merge_members is not supported by #{obj.class}")
218
+ end
219
+
220
+ def push(obj)
221
+ Chef::Log.debug("Nagios debug: Cannot push #{obj} into #{self.class}")
222
+ end
223
+
224
+ def push_object(obj, hash)
225
+ return if hash.key?('null')
226
+ if obj.to_s == 'null'
227
+ hash.clear
228
+ hash[obj.to_s] = obj
229
+ elsif hash[obj.to_s].nil?
230
+ hash[obj.to_s] = obj
231
+ else
232
+ Chef::Log.debug("Nagios debug: #{self.class} already contains #{obj.class} with name: #{obj}")
233
+ end
234
+ end
235
+
236
+ def pop_object(obj, hash)
237
+ if hash.key?(obj.to_s)
238
+ hash.delete(obj.to_s)
239
+ else
240
+ Chef::Log.debug("Nagios debug: #{self.class} does not contain #{obj.class} with name: #{obj}")
241
+ end
242
+ end
243
+
244
+ def notification_commands(obj)
245
+ commands = []
246
+ case obj
247
+ when Nagios::Command
248
+ commands.push(obj)
249
+ when Array
250
+ obj.each { |o| commands += notification_commands(o) }
251
+ when String
252
+ obj.split(',').each do |o|
253
+ c = Nagios::Command.new(o.strip)
254
+ n = Nagios.instance.find(c)
255
+ if c == n
256
+ Chef::Log.fail("#{self.class} fail: Cannot find command #{o} please define it first.")
257
+ raise "#{self.class} fail: Cannot find command #{o} please define it first."
258
+ else
259
+ commands.push(n)
260
+ end
261
+ end
262
+ end
263
+ commands
264
+ end
265
+
266
+ def hostname(name)
267
+ if Nagios.instance.normalize_hostname
268
+ name.downcase
269
+ else
270
+ name
271
+ end
272
+ end
273
+
274
+ def update_options(hash)
275
+ return if blank?(hash)
276
+ update_hash_options(hash) if hash.respond_to?('each_pair')
277
+ end
278
+
279
+ def update_hash_options(hash)
280
+ hash.each do |k, v|
281
+ push(Nagios::CustomOption.new(k.upcase, v)) if k.to_s.start_with?('_')
282
+ m = k.to_s + '='
283
+ send(m, v) if respond_to?(m)
284
+ end
285
+ end
286
+
287
+ def update_members(hash, option, object, remote = false)
288
+ return if blank?(hash) || hash[option].nil?
289
+ if hash[option].is_a?(String) && hash[option].to_s.start_with?('+')
290
+ @add_modifiers[option] = '+'
291
+ hash[option] = hash[option][1..-1]
292
+ end
293
+ get_members(hash[option], object).each do |member|
294
+ if member.start_with?('!')
295
+ member = member[1..-1]
296
+ @not_modifiers[option][member] = '!'
297
+ end
298
+ n = Nagios.instance.find(object.new(member))
299
+ push(n)
300
+ n.push(self) if remote
301
+ end
302
+ end
303
+
304
+ def update_dependency_members(hash, option, object)
305
+ return if blank?(hash) || hash[option].nil?
306
+ get_members(hash[option], object).each do |member|
307
+ push_dependency(Nagios.instance.find(object.new(member)))
308
+ end
309
+ end
310
+ end
311
+ end
@@ -0,0 +1,68 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: command
5
+ #
6
+ # Copyright:: 2014, Sander Botman
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'base'
21
+
22
+ class Nagios
23
+ #
24
+ # This class holds all methods with regard to command options,
25
+ # that are used within nagios configurations.
26
+ #
27
+ class Command < Nagios::Base
28
+ attr_reader :command_name
29
+ attr_accessor :command_line
30
+
31
+ def initialize(command_name)
32
+ cmd = command_name.split('!')
33
+ @command_name = cmd.shift
34
+ super()
35
+ end
36
+
37
+ def definition
38
+ if blank?(command_line)
39
+ "# Skipping #{command_name} because command_line is missing."
40
+ else
41
+ get_definition(configured_options, 'command')
42
+ end
43
+ end
44
+
45
+ def self.create(name)
46
+ Nagios.instance.find(Nagios::Command.new(name))
47
+ end
48
+
49
+ def import(hash)
50
+ @command_line = hash if hash.class == String
51
+ hash['command_line'] == hash['command'] unless hash['command'].nil?
52
+ update_options(hash)
53
+ end
54
+
55
+ def to_s
56
+ command_name
57
+ end
58
+
59
+ private
60
+
61
+ def config_options
62
+ {
63
+ 'command_name' => 'command_name',
64
+ 'command_line' => 'command_line',
65
+ }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,229 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: contact
5
+ #
6
+ # Copyright:: 2014, Sander Botman
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'base'
21
+
22
+ class Nagios
23
+ #
24
+ # This class holds all methods with regard to contact options,
25
+ # that are used within nagios configurations.
26
+ #
27
+ class Contact < Nagios::Base
28
+ attr_reader :contact_name,
29
+ :contactgroups,
30
+ :custom_options
31
+
32
+ attr_accessor :alias,
33
+ :host_notifications_enabled,
34
+ :service_notifications_enabled,
35
+ :host_notification_period,
36
+ :service_notification_period,
37
+ :host_notification_options,
38
+ :service_notification_options,
39
+ :host_notification_commands,
40
+ :service_notification_commands,
41
+ :email,
42
+ :pager,
43
+ :addressx,
44
+ :can_submit_commands,
45
+ :retain_status_information,
46
+ :retain_nonstatus_information
47
+
48
+ def initialize(contact_name)
49
+ @contact_name = contact_name
50
+ @contactgroups = {}
51
+ @host_notification_commands = []
52
+ @service_notification_commands = []
53
+ @custom_options = {}
54
+ super()
55
+ end
56
+
57
+ def contactgroups_list
58
+ @contactgroups.values.map(&:to_s).sort.join(',')
59
+ end
60
+
61
+ def definition
62
+ if email.nil? && name.nil? && pager.nil?
63
+ "# Skipping #{contact_name} because missing email/pager."
64
+ else
65
+ configured = configured_options
66
+ custom_options.each { |_, v| configured[v.to_s] = v.value }
67
+ get_definition(configured, 'contact')
68
+ end
69
+ end
70
+
71
+ def self.create(name)
72
+ Nagios.instance.find(Nagios::Contact.new(name))
73
+ end
74
+
75
+ def host_notification_commands
76
+ get_commands(@host_notification_commands)
77
+ end
78
+
79
+ def host_notification_commands=(obj)
80
+ @host_notification_commands = notification_commands(obj)
81
+ end
82
+
83
+ def host_notification_period
84
+ get_timeperiod(@host_notification_period)
85
+ end
86
+
87
+ def import(hash)
88
+ update_options(hash)
89
+ update_members(hash, 'contactgroups', Nagios::Contactgroup, true)
90
+ end
91
+
92
+ def push(obj)
93
+ case obj
94
+ when Nagios::Contactgroup
95
+ push_object(obj, @contactgroups)
96
+ when Nagios::Timeperiod
97
+ @host_notification_period = obj
98
+ @service_notification_period = obj
99
+ when Nagios::CustomOption
100
+ push_object(obj, @custom_options)
101
+ end
102
+ end
103
+
104
+ def pop(obj)
105
+ return if obj == self
106
+ case obj
107
+ when Nagios::Contactgroup
108
+ if @contactgroups.key?(obj.to_s)
109
+ pop_object(obj, @contactgroups)
110
+ pop(self, obj)
111
+ end
112
+ when Nagios::Timeperiod
113
+ @host_notification_period = nil if obj == @host_notification_period
114
+ @service_notification_period = nil if obj == @service_notification_period
115
+ when Nagios::CustomOption
116
+ if @custom_options.key?(obj.to_s)
117
+ pop_object(obj, @custom_options)
118
+ pop(self, obj)
119
+ end
120
+ end
121
+ end
122
+
123
+ def service_notification_commands
124
+ get_commands(@service_notification_commands)
125
+ end
126
+
127
+ def service_notification_commands=(obj)
128
+ @service_notification_commands = notification_commands(obj)
129
+ end
130
+
131
+ def service_notification_period
132
+ get_timeperiod(@service_notification_period)
133
+ end
134
+
135
+ def to_s
136
+ contact_name
137
+ end
138
+
139
+ # check the True/False options
140
+ # default = nil
141
+ def host_notifications_enabled=(arg)
142
+ @host_notifications_enabled = check_bool(arg)
143
+ end
144
+
145
+ def service_notifications_enabled=(arg)
146
+ @service_notifications_enabled = check_bool(arg)
147
+ end
148
+
149
+ def can_submit_commands=(arg)
150
+ @can_submit_commands = check_bool(arg)
151
+ end
152
+
153
+ def retain_status_information=(arg)
154
+ @retain_status_information = check_bool(arg)
155
+ end
156
+
157
+ def retain_nonstatus_information=(arg)
158
+ @retain_nonstatus_information = check_bool(arg)
159
+ end
160
+
161
+ # check other options
162
+ #
163
+ # host_notification_options
164
+ # This directive is used to define the host states for which notifications
165
+ # can be sent out to this contact.
166
+ # Valid options are a combination of one or more of the following:
167
+ # d = notify on DOWN host states,
168
+ # u = notify on UNREACHABLE host states,
169
+ # r = notify on host recoveries (UP states),
170
+ # f = notify when the host starts and stops flapping,
171
+ # s = send notifications when host or service scheduled downtime starts and ends.
172
+ #
173
+ # If you specify n (none) as an option, the contact will not receive any type of
174
+ # host notifications.
175
+ def host_notification_options=(arg)
176
+ @host_notification_options = check_state_options(
177
+ arg, %w(d u r f s n), 'host_notification_options')
178
+ end
179
+
180
+ # service_notification_options
181
+ # This directive is used to define the service states for which notifications
182
+ # can be sent out to this contact.
183
+ # Valid options are a combination of one or more of the following:
184
+ # w = notify on WARNING service states,
185
+ # u = notify on UNKNOWN service states,
186
+ # c = notify on CRITICAL service states,
187
+ # r = notify on service recoveries (OK states),
188
+ # f = notify when the service starts and stops flapping.
189
+ #
190
+ # If you specify n (none) as an option, the contact will not receive any type of
191
+ # service notifications.
192
+ def service_notification_options=(arg)
193
+ @service_notification_options = check_state_options(
194
+ arg, %w(w u c r f n), 'service_notification_options')
195
+ end
196
+
197
+ private
198
+
199
+ def config_options
200
+ {
201
+ 'name' => 'name',
202
+ 'use' => 'use',
203
+ 'contact_name' => 'contact_name',
204
+ 'contactgroups_list' => 'contactgroups',
205
+ 'alias' => 'alias',
206
+ 'host_notifications_enabled' => 'host_notifications_enabled',
207
+ 'service_notifications_enabled' => 'service_notifications_enabled',
208
+ 'host_notification_period' => 'host_notification_period',
209
+ 'service_notification_period' => 'service_notification_period',
210
+ 'host_notification_options' => 'host_notification_options',
211
+ 'service_notification_options' => 'service_notification_options',
212
+ 'host_notification_commands' => 'host_notification_commands',
213
+ 'service_notification_commands' => 'service_notification_commands',
214
+ 'email' => 'email',
215
+ 'pager' => 'pager',
216
+ 'addressx' => 'addressx',
217
+ 'can_submit_commands' => 'can_submit_commands',
218
+ 'retain_status_information' => 'retain_status_information',
219
+ 'retain_nonstatus_information' => 'retain_nonstatus_information',
220
+ 'register' => 'register',
221
+ }
222
+ end
223
+
224
+ def merge_members(obj)
225
+ obj.contactgroups.each { |m| push(m) }
226
+ obj.custom_options.each { |_, m| push(m) }
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: contactgroup
5
+ #
6
+ # Copyright:: 2014, Sander Botman
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'nagios'
21
+
22
+ class Nagios
23
+ #
24
+ # This class holds all methods with regard to contactgroup options,
25
+ # that are used within nagios configurations.
26
+ #
27
+ class Contactgroup < Nagios::Base
28
+ attr_reader :contactgroup_name,
29
+ :members,
30
+ :contactgroup_members
31
+
32
+ attr_accessor :alias
33
+
34
+ def initialize(contactgroup_name)
35
+ @contactgroup_name = contactgroup_name
36
+ @members = {}
37
+ @contactgroup_members = {}
38
+ super()
39
+ end
40
+
41
+ def contactgroup_members_list
42
+ @contactgroup_members.values.map(&:to_s).sort.join(',')
43
+ end
44
+
45
+ def self.create(name)
46
+ Nagios.instance.find(Nagios::Contactgroup.new(name))
47
+ end
48
+
49
+ def definition
50
+ get_definition(configured_options, 'contactgroup')
51
+ end
52
+
53
+ def import(hash)
54
+ update_options(hash)
55
+ update_members(hash, 'members', Nagios::Contact, true)
56
+ update_members(hash, 'contactgroups_members', Nagios::Contactgroup, true)
57
+ end
58
+
59
+ def members_list
60
+ @members.values.map(&:to_s).sort.join(',')
61
+ end
62
+
63
+ def push(obj)
64
+ case obj
65
+ when Nagios::Contact
66
+ push_object(obj, @members)
67
+ when Nagios::Contactgroup
68
+ push_object(obj, @contactgroup_members)
69
+ end
70
+ end
71
+
72
+ def pop(obj)
73
+ return if obj == self
74
+ case obj
75
+ when Nagios::Contact
76
+ if @members.key?(obj.to_s)
77
+ pop_object(obj, @members)
78
+ pop(self, obj)
79
+ end
80
+ when Nagios::Contactgroup
81
+ if @contactgroups_members.key?(obj.to_s)
82
+ pop_object(obj, @contactgroup_members)
83
+ pop(self, obj)
84
+ end
85
+ end
86
+ end
87
+
88
+ def to_s
89
+ contactgroup_name
90
+ end
91
+
92
+ private
93
+
94
+ def config_options
95
+ {
96
+ 'name' => 'name',
97
+ 'use' => 'use',
98
+ 'contactgroup_name' => 'contactgroup_name',
99
+ 'members_list' => 'members',
100
+ 'contactgroup_members_list' => 'contactgroup_members',
101
+ 'alias' => 'alias',
102
+ 'register' => 'register',
103
+ }
104
+ end
105
+
106
+ def merge_members(obj)
107
+ obj.members.each { |m| push(m) }
108
+ obj.contactgroup_members.each { |m| push(m) }
109
+ end
110
+ end
111
+ end