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,449 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: service
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
+ require_relative 'base'
22
+
23
+ class Nagios
24
+ #
25
+ # This class holds all methods with regard to servicedependency options,
26
+ # that are used within nagios configurations.
27
+ #
28
+ class Service < Nagios::Base
29
+ attr_reader :service_description,
30
+ :host_name,
31
+ :hostgroup_name,
32
+ :contacts,
33
+ :contact_groups,
34
+ :check_command,
35
+ :servicegroups,
36
+ :hostgroups,
37
+ :custom_options
38
+
39
+ attr_accessor :display_name,
40
+ :is_volatile,
41
+ :initial_state,
42
+ :max_check_attempts,
43
+ :check_interval,
44
+ :retry_interval,
45
+ :active_checks_enabled,
46
+ :passive_checks_enabled,
47
+ :check_period,
48
+ :obsess_over_service,
49
+ :check_freshness,
50
+ :freshness_threshold,
51
+ :event_handler,
52
+ :event_handler_enabled,
53
+ :low_flap_threshold,
54
+ :high_flap_threshold,
55
+ :flap_detection_enabled,
56
+ :flap_detection_options,
57
+ :process_perf_data,
58
+ :retain_status_information,
59
+ :retain_nonstatus_information,
60
+ :notification_interval,
61
+ :first_notification_delay,
62
+ :notification_period,
63
+ :notification_options,
64
+ :notifications_enabled,
65
+ :parallelize_check,
66
+ :stalking_options,
67
+ :notes,
68
+ :notes_url,
69
+ :action_url,
70
+ :icon_image,
71
+ :icon_image_alt
72
+
73
+ def initialize(service_description)
74
+ @service_description = service_description
75
+ srv = service_description.split('!')
76
+ @check_command = srv.shift
77
+ @arguments = srv
78
+ @servicegroups = {}
79
+ @contacts = {}
80
+ @contact_groups = {}
81
+ @hostgroups = {}
82
+ @hosts = {}
83
+ @custom_options = {}
84
+ super()
85
+ end
86
+
87
+ def check_command
88
+ if blank?(@arguments)
89
+ @check_command.to_s
90
+ else
91
+ @check_command.to_s + '!' + @arguments.join('!')
92
+ end
93
+ end
94
+
95
+ def check_command=(cmd)
96
+ cmd = cmd.split('!')
97
+ cmd.shift
98
+ @arguments = cmd
99
+ end
100
+
101
+ def check_period
102
+ get_timeperiod(@check_period)
103
+ end
104
+
105
+ # contacts
106
+ # This is a list of the short names of the contacts that should be notified
107
+ # whenever there are problems (or recoveries) with this host.
108
+ # Multiple contacts should be separated by commas.
109
+ # Useful if you want notifications to go to just a few people and don't want
110
+ # to configure contact groups.
111
+ # You must specify at least one contact or contact group in each host definition.
112
+ def contacts_list
113
+ @contacts.values.map(&:to_s).sort.join(',')
114
+ end
115
+
116
+ # contact_groups
117
+ # This is a list of the short names of the contact groups that should be notified
118
+ # whenever there are problems (or recoveries) with this host.
119
+ # Multiple contact groups should be separated by commas.
120
+ # You must specify at least one contact or contact group in each host definition.
121
+ def contact_groups_list
122
+ @contact_groups.values.map(&:to_s).sort.join(',')
123
+ end
124
+
125
+ def definition
126
+ if blank?(hostgroup_name_list) && blank?(host_name_list) && name.nil?
127
+ "# Skipping #{service_description} because host_name and hostgroup_name are missing."
128
+ else
129
+ configured = configured_options
130
+ custom_options.each { |_, v| configured[v.to_s] = v.value }
131
+ get_definition(configured, 'service')
132
+ end
133
+ end
134
+
135
+ # host_name
136
+ # This directive is used to return all host objects
137
+ def host_name
138
+ @hosts
139
+ end
140
+
141
+ # host_name_list
142
+ # This directive is used to specify the short name(s) of the host(s) that the service
143
+ # "runs" on or is associated with. Multiple hosts should be separated by commas.
144
+ def host_name_list
145
+ @hosts.values.map(&:to_s).sort.join(',')
146
+ end
147
+
148
+ # hostgroup_name
149
+ # This directive is used to return all hostgroup objects
150
+ def hostgroup_name
151
+ @hostgroups
152
+ end
153
+
154
+ # hostgroup_name_list
155
+ # This directive is used to specify the short name(s) of the hostgroup(s) that the
156
+ # service "runs" on or is associated with. Multiple hostgroups should be separated by commas.
157
+ # The hostgroup_name may be used instead of, or in addition to, the host_name directive.
158
+ def hostgroup_name_list
159
+ @hostgroups.values.map(&:to_s).sort.join(',')
160
+ end
161
+
162
+ def import(hash)
163
+ update_options(hash)
164
+ update_members(hash, 'contacts', Nagios::Contact)
165
+ update_members(hash, 'contact_groups', Nagios::Contactgroup)
166
+ update_members(hash, 'host_name', Nagios::Host)
167
+ update_members(hash, 'hostgroup_name', Nagios::Hostgroup)
168
+ update_members(hash, 'servicegroups', Nagios::Servicegroup, true)
169
+ update_members(hash, 'check_command', Nagios::Command)
170
+ end
171
+
172
+ def notification_period
173
+ get_timeperiod(@notification_period)
174
+ end
175
+
176
+ def push(obj)
177
+ case obj
178
+ when Nagios::Servicegroup
179
+ push_object(obj, @servicegroups)
180
+ when Nagios::Hostgroup
181
+ push_object(obj, @hostgroups)
182
+ when Nagios::Host
183
+ push_object(obj, @hosts)
184
+ when Nagios::Contact
185
+ push_object(obj, @contacts)
186
+ when Nagios::Contactgroup
187
+ push_object(obj, @contact_groups)
188
+ when Nagios::Command
189
+ @check_command = obj
190
+ when Nagios::Timeperiod
191
+ @check_period = obj
192
+ @notification_period = obj
193
+ when Nagios::CustomOption
194
+ push_object(obj, @custom_options)
195
+ end
196
+ end
197
+
198
+ def pop(obj)
199
+ return if obj == self
200
+ case obj
201
+ when Nagios::Servicegroup
202
+ if @servicegroups.key?(obj.to_s)
203
+ pop_object(obj, @servicegroups)
204
+ pop(self, obj)
205
+ end
206
+ when Nagios::Hostgroup
207
+ if @hostgroups.key?(obj.to_s)
208
+ pop_object(obj, @hostgroups)
209
+ pop(self, obj)
210
+ end
211
+ when Nagios::Host
212
+ if @hosts.key?(obj.to_s)
213
+ pop_object(obj, @hosts)
214
+ pop(self, obj)
215
+ end
216
+ when Nagios::Contact
217
+ if @contacts.key?(obj.to_s)
218
+ pop_object(obj, @contacts)
219
+ pop(self, obj)
220
+ end
221
+ when Nagios::Contactgroup
222
+ if @contact_groups.key?(obj.to_s)
223
+ pop_object(obj, @contact_groups)
224
+ pop(self, obj)
225
+ end
226
+ when Nagios::Command
227
+ @check_command = nil if @check_command == obj
228
+ when Nagios::Timeperiod
229
+ @check_period = nil if @check_command == obj
230
+ @notification_period = nil if @check_command == obj
231
+ when Nagios::CustomOption
232
+ if @custom_options.key?(obj.to_s)
233
+ pop_object(obj, @custom_options)
234
+ pop(self, obj)
235
+ end
236
+ end
237
+ end
238
+
239
+ # servicegroups
240
+ # This directive is used to define the description of the service, which may contain spaces,
241
+ # dashes, and colons (semicolons, apostrophes, and quotation marks should be avoided).
242
+ # No two services associated with the same host can have the same description.
243
+ # Services are uniquely identified with their host_name and service_description directives.
244
+ def servicegroups_list
245
+ @servicegroups.values.map(&:to_s).sort.join(',')
246
+ end
247
+
248
+ def self.create(name)
249
+ Nagios.instance.find(Nagios::Service.new(name))
250
+ end
251
+
252
+ def to_s
253
+ service_description
254
+ end
255
+
256
+ # check the integer options
257
+ # default = nil
258
+
259
+ def max_check_attempts=(int)
260
+ @max_check_attempts = check_integer(int)
261
+ end
262
+
263
+ def check_interval=(int)
264
+ @check_interval = check_integer(int)
265
+ end
266
+
267
+ def retry_interval=(int)
268
+ @retry_interval = check_integer(int)
269
+ end
270
+
271
+ def freshness_threshold=(int)
272
+ @freshness_threshold = check_integer(int)
273
+ end
274
+
275
+ def low_flap_threshold=(int)
276
+ @low_flap_threshold = check_integer(int)
277
+ end
278
+
279
+ def high_flap_threshold=(int)
280
+ @high_flap_threshold = check_integer(int)
281
+ end
282
+
283
+ def notification_interval=(int)
284
+ @notification_interval = check_integer(int)
285
+ end
286
+
287
+ def first_notification_delay=(int)
288
+ @first_notification_delay = check_integer(int)
289
+ end
290
+
291
+ # check the True/False options
292
+ # default = nil
293
+ def is_volatile=(arg)
294
+ @is_volatile = check_bool(arg)
295
+ end
296
+
297
+ def active_checks_enabled=(arg)
298
+ @active_checks_enabled = check_bool(arg)
299
+ end
300
+
301
+ def passive_checks_enabled=(arg)
302
+ @passive_checks_enabled = check_bool(arg)
303
+ end
304
+
305
+ def obsess_over_service=(arg)
306
+ @obsess_over_service = check_bool(arg)
307
+ end
308
+
309
+ def check_freshness=(arg)
310
+ @check_freshness = check_bool(arg)
311
+ end
312
+
313
+ def event_handler_enabled=(arg)
314
+ @event_handler_enabled = check_bool(arg)
315
+ end
316
+
317
+ def flap_detection_enabled=(arg)
318
+ @flap_detection_enabled = check_bool(arg)
319
+ end
320
+
321
+ def process_perf_data=(arg)
322
+ @process_perf_data = check_bool(arg)
323
+ end
324
+
325
+ def retain_status_information=(arg)
326
+ @retain_status_information = check_bool(arg)
327
+ end
328
+
329
+ def retain_nonstatus_information=(arg)
330
+ @retain_nonstatus_information = check_bool(arg)
331
+ end
332
+
333
+ def notifications_enabled=(arg)
334
+ @notifications_enabled = check_bool(arg)
335
+ end
336
+
337
+ def parallelize_check=(arg)
338
+ @parallelize_check = check_bool(arg)
339
+ end
340
+
341
+ # check other options
342
+
343
+ # flap_detection_options
344
+ # This directive is used to determine what service states the flap detection logic will use for this service.
345
+ # Valid options are a combination of one or more of the following:
346
+ # o = OK states,
347
+ # w = WARNING states,
348
+ # c = CRITICAL states,
349
+ # u = UNKNOWN states.
350
+
351
+ def flap_detection_options=(arg)
352
+ @flap_detection_options = check_state_options(arg, %w(o w u c), 'flap_detection_options')
353
+ end
354
+
355
+ # notification_options
356
+ # This directive is used to determine when notifications for the service should be sent out.
357
+ # Valid options are a combination of one or more of the following:
358
+ # w = send notifications on a WARNING state,
359
+ # u = send notifications on an UNKNOWN state,
360
+ # c = send notifications on a CRITICAL state,
361
+ # r = send notifications on recoveries (OK state),
362
+ # f = send notifications when the service starts and stops flapping,
363
+ # s = send notifications when scheduled downtime starts and ends.
364
+ #
365
+ # If you specify n (none) as an option, no service notifications will be sent out.
366
+ # If you do not specify any notification options, Nagios will assume that you want
367
+ # notifications to be sent out for all possible states.
368
+ #
369
+ # Example: If you specify w,r in this field, notifications will only be sent out when
370
+ # the service goes into a WARNING state and when it recovers from a WARNING state.
371
+
372
+ def notification_options=(arg)
373
+ @notification_options = check_state_options(arg, %w(w u c r f s n), 'notification_options')
374
+ end
375
+
376
+ # stalking_options
377
+ # This directive determines which service states "stalking" is enabled for.
378
+ # Valid options are a combination of one or more of the following:
379
+ # o = stalk on OK states,
380
+ # w = stalk on WARNING states,
381
+ # u = stalk on UNKNOWN states,
382
+ # c = stalk on CRITICAL states.
383
+ #
384
+ # More information on state stalking can be found here.
385
+
386
+ def stalking_options=(arg)
387
+ @stalking_options = check_state_options(arg, %w(o w u c), 'stalking_options')
388
+ end
389
+
390
+ private
391
+
392
+ def config_options
393
+ {
394
+ 'name' => 'name',
395
+ 'use' => 'use',
396
+ 'service_description' => 'service_description',
397
+ 'host_name_list' => 'host_name',
398
+ 'hostgroup_name_list' => 'hostgroup_name',
399
+ 'servicegroups_list' => 'servicegroups',
400
+ 'display_name' => 'display_name',
401
+ 'is_volatile' => 'is_volatile',
402
+ 'check_command' => 'check_command',
403
+ 'initial_state' => 'initial_state',
404
+ 'max_check_attempts' => 'max_check_attempts',
405
+ 'check_interval' => 'check_interval',
406
+ 'retry_interval' => 'retry_interval',
407
+ 'active_checks_enabled' => 'active_checks_enabled',
408
+ 'passive_checks_enabled' => 'passive_checks_enabled',
409
+ 'check_period' => 'check_period',
410
+ 'obsess_over_service' => 'obsess_over_service',
411
+ 'check_freshness' => 'check_freshness',
412
+ 'freshness_threshold' => 'freshness_threshold',
413
+ 'event_handler' => 'event_handler',
414
+ 'event_handler_enabled' => 'event_handler_enabled',
415
+ 'low_flap_threshold' => 'low_flap_threshold',
416
+ 'high_flap_threshold' => 'high_flap_threshold',
417
+ 'flap_detection_enabled' => 'flap_detection_enabled',
418
+ 'flap_detection_options' => 'flap_detection_options',
419
+ 'process_perf_data' => 'process_perf_data',
420
+ 'retain_status_information' => 'retain_status_information',
421
+ 'retain_nonstatus_information' => 'retain_nonstatus_information',
422
+ 'notification_interval' => 'notification_interval',
423
+ 'first_notification_delay' => 'first_notification_delay',
424
+ 'notification_period' => 'notification_period',
425
+ 'notification_options' => 'notification_options',
426
+ 'notifications_enabled' => 'notifications_enabled',
427
+ 'parallelize_check' => 'parallelize_check',
428
+ 'contacts_list' => 'contacts',
429
+ 'contact_groups_list' => 'contact_groups',
430
+ 'stalking_options' => 'stalking_options',
431
+ 'notes' => 'notes',
432
+ 'notes_url' => 'notes_url',
433
+ 'action_url' => 'action_url',
434
+ 'icon_image' => 'icon_image',
435
+ 'icon_image_alt' => 'icon_image_alt',
436
+ 'register' => 'register',
437
+ }
438
+ end
439
+
440
+ def merge_members(obj)
441
+ obj.contacts.each { |m| push(m) }
442
+ obj.host_name.each { |m| push(m) }
443
+ obj.servicegroups.each { |m| push(m) }
444
+ obj.hostgroup_name.each { |m| push(m) }
445
+ obj.contact_groups.each { |m| push(m) }
446
+ obj.custom_options.each { |_, m| push(m) }
447
+ end
448
+ end
449
+ end
@@ -0,0 +1,213 @@
1
+ #
2
+ # Author:: Sander Botman <sbotman@schubergphilis.com>
3
+ # Cookbook:: nagios
4
+ # Library:: servicedependency
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
+ require_relative 'base'
22
+
23
+ class Nagios
24
+ #
25
+ # This class holds all methods with regard to servicedependency options,
26
+ # that are used within nagios configurations.
27
+ #
28
+ class Servicedependency < Nagios::Base
29
+ attr_reader :service_description,
30
+ :dependency_period,
31
+ :dependent_host_name,
32
+ :dependent_hostgroup_name,
33
+ :dependent_servicegroup_name,
34
+ :host_name,
35
+ :hostgroup_name,
36
+ :servicegroup_name
37
+
38
+ attr_accessor :dependent_service_description,
39
+ :inherits_parent,
40
+ :execution_failure_criteria,
41
+ :notification_failure_criteria
42
+
43
+ def initialize(name)
44
+ @service_description = name
45
+ @host_name = {}
46
+ @hostgroup_name = {}
47
+ @servicegroup_name = {}
48
+ @dependent_host_name = {}
49
+ @dependent_hostgroup_name = {}
50
+ @dependent_servicegroup_name = {}
51
+ super()
52
+ end
53
+
54
+ def definition
55
+ get_definition(configured_options, 'servicedependency')
56
+ end
57
+
58
+ def dependent_host_name_list
59
+ @dependent_host_name.values.map(&:to_s).sort.join(',')
60
+ end
61
+
62
+ def dependent_hostgroup_name_list
63
+ @dependent_hostgroup_name.values.map(&:to_s).sort.join(',')
64
+ end
65
+
66
+ def dependent_servicegroup_name_list
67
+ @dependent_servicegroup_name.values.map(&:to_s).sort.join(',')
68
+ end
69
+
70
+ def host_name_list
71
+ @host_name.values.map(&:to_s).sort.join(',')
72
+ end
73
+
74
+ def hostgroup_name_list
75
+ @hostgroup_name.values.map(&:to_s).sort.join(',')
76
+ end
77
+
78
+ def servicegroup_name_list
79
+ @servicegroup_name.values.map(&:to_s).sort.join(',')
80
+ end
81
+
82
+ def import(hash)
83
+ update_options(hash)
84
+ update_members(hash, 'host_name', Nagios::Host)
85
+ update_members(hash, 'hostgroup_name', Nagios::Hostgroup)
86
+ update_members(hash, 'servicegroup_name', Nagios::Servicegroup)
87
+ update_dependency_members(hash, 'dependent_host_name', Nagios::Host)
88
+ update_dependency_members(hash, 'dependent_hostgroup_name', Nagios::Hostgroup)
89
+ update_dependency_members(hash, 'dependent_servicegroup_name', Nagios::Servicegroup)
90
+ end
91
+
92
+ def push(obj)
93
+ case obj
94
+ when Nagios::Host
95
+ push_object(obj, @host_name)
96
+ when Nagios::Hostgroup
97
+ push_object(obj, @hostgroup_name)
98
+ when Nagios::Servicegroup
99
+ push_object(obj, @servicegroup_name)
100
+ when Nagios::Timeperiod
101
+ @dependency_period = obj
102
+ end
103
+ end
104
+
105
+ def pop(obj)
106
+ return if obj == self
107
+ case obj
108
+ when Nagios::Host
109
+ if @host_name.key?(obj.to_s)
110
+ pop_object(obj, @host_name)
111
+ pop(self, obj)
112
+ end
113
+ when Nagios::Hostgroup
114
+ if @host_name.key?(obj.to_s)
115
+ pop_object(obj, @hostgroup_name)
116
+ pop(self, obj)
117
+ end
118
+ when Nagios::Servicegroup
119
+ if @host_name.key?(obj.to_s)
120
+ pop_object(obj, @servicegroup_name)
121
+ pop(self, obj)
122
+ end
123
+ when Nagios::Timeperiod
124
+ @dependency_period = nil if @dependency_period == obj
125
+ end
126
+ end
127
+
128
+ def pop_dependency(obj)
129
+ return if obj == self
130
+ case obj
131
+ when Nagios::Host
132
+ if @dependent_host_name.key?(obj.to_s)
133
+ pop_object(obj, @dependent_host_name)
134
+ obj.pop(self)
135
+ end
136
+ when Nagios::Hostgroup
137
+ if @dependent_hostgroup_name.key?(obj.to_s)
138
+ pop_object(obj, @dependent_hostgroup_name)
139
+ obj.pop(self)
140
+ end
141
+ when Nagios::Servicegroup
142
+ if @dependent_servicegroup_name.key?(obj.to_s)
143
+ pop_object(obj, @dependent_servicegroup_name)
144
+ obj.pop(self)
145
+ end
146
+ end
147
+ end
148
+
149
+ def push_dependency(obj)
150
+ case obj
151
+ when Nagios::Host
152
+ push_object(obj, @dependent_host_name)
153
+ when Nagios::Hostgroup
154
+ push_object(obj, @dependent_hostgroup_name)
155
+ when Nagios::Servicegroup
156
+ push_object(obj, @dependent_servicegroup_name)
157
+ end
158
+ end
159
+
160
+ def self.create(name)
161
+ Nagios.instance.find(Nagios::Servicedependency.new(name))
162
+ end
163
+
164
+ def to_s
165
+ service_description
166
+ end
167
+
168
+ # check the True/False options
169
+ # default = nil
170
+
171
+ def inherits_parent=(arg)
172
+ @inherits_parent = check_bool(arg)
173
+ end
174
+
175
+ # check other options
176
+
177
+ def execution_failure_criteria=(arg)
178
+ @execution_failure_criteria = check_state_options(arg, %w(o w u c p n), 'execution_failure_criteria')
179
+ end
180
+
181
+ def notification_failure_criteria=(arg)
182
+ @notification_failure_criteria = check_state_options(arg, %w(o w u c p n), 'notification_failure_criteria')
183
+ end
184
+
185
+ private
186
+
187
+ def config_options
188
+ {
189
+ 'dependency_period' => 'dependency_period',
190
+ 'dependent_host_name_list' => 'dependent_host_name',
191
+ 'dependent_hostgroup_name_list' => 'dependent_hostgroup_name',
192
+ 'dependent_servicegroup_name_list' => 'dependent_servicegroup_name',
193
+ 'service_description' => 'service_description',
194
+ 'servicegroup_name_list' => 'servicegroup_name',
195
+ 'dependent_service_description' => 'dependent_service_description',
196
+ 'host_name_list' => 'host_name',
197
+ 'hostgroup_name_list' => 'hostgroup_name',
198
+ 'inherits_parent' => 'inherits_parent',
199
+ 'execution_failure_criteria' => 'execution_failure_criteria',
200
+ 'notification_failure_criteria' => 'notification_failure_criteria',
201
+ }
202
+ end
203
+
204
+ def merge_members(obj)
205
+ obj.host_name.each { |m| push(m) }
206
+ obj.hostgroup_name.each { |m| push(m) }
207
+ obj.servicegroup_name.each { |m| push(m) }
208
+ obj.dependent_host_name.each { |m| push_dependency(m) }
209
+ obj.dependent_hostgroup_name.each { |m| push_dependency(m) }
210
+ obj.dependent_servicegroup_name.each { |m| dependent_servicegroup_name(m) }
211
+ end
212
+ end
213
+ end