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.
- checksums.yaml +4 -4
- data/Berksfile +2 -3
- data/Berksfile.lock +11 -14
- data/bin/mu-aws-setup +16 -4
- data/bin/mu-configure +2 -1
- data/cloud-mu.gemspec +2 -2
- data/cookbooks/mu-firewall/Berksfile +1 -1
- data/cookbooks/mu-firewall/attributes/default.rb +2 -2
- data/cookbooks/mu-firewall/metadata.rb +3 -3
- data/cookbooks/mu-firewall/recipes/default.rb +11 -2
- data/cookbooks/mu-master/Berksfile +1 -1
- data/cookbooks/mu-master/attributes/default.rb +14 -1
- data/cookbooks/mu-master/files/default/389ds-perl/ASDialogs.pm +173 -0
- data/cookbooks/mu-master/files/default/389ds-perl/AdminMigration.pm +569 -0
- data/cookbooks/mu-master/files/default/389ds-perl/AdminServer.pm +952 -0
- data/cookbooks/mu-master/files/default/389ds-perl/AdminUtil.pm +983 -0
- data/cookbooks/mu-master/files/default/389ds-perl/ConfigDSDialogs.pm +449 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSCreate.pm +1551 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSDialogs.pm +233 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSMigration.pm +1175 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSUpdate.pm +534 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSUpdateDialogs.pm +152 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DSUtil.pm +1710 -0
- data/cookbooks/mu-master/files/default/389ds-perl/Dialog.pm +249 -0
- data/cookbooks/mu-master/files/default/389ds-perl/DialogManager.pm +212 -0
- data/cookbooks/mu-master/files/default/389ds-perl/FileConn.pm +461 -0
- data/cookbooks/mu-master/files/default/389ds-perl/Inf.pm +268 -0
- data/cookbooks/mu-master/files/default/389ds-perl/Migration.pm +327 -0
- data/cookbooks/mu-master/files/default/389ds-perl/RegDSDialogs.pm +94 -0
- data/cookbooks/mu-master/files/default/389ds-perl/Resource.pm +137 -0
- data/cookbooks/mu-master/files/default/389ds-perl/Setup.pm +240 -0
- data/cookbooks/mu-master/files/default/389ds-perl/SetupDialogs.pm +243 -0
- data/cookbooks/mu-master/files/default/389ds-perl/SetupLog.pm +82 -0
- data/cookbooks/mu-master/files/default/setCertName.ldif +4 -0
- data/cookbooks/mu-master/libraries/mu.rb +2 -2
- data/cookbooks/mu-master/metadata.rb +1 -1
- data/cookbooks/mu-master/recipes/389ds.rb +71 -32
- data/cookbooks/mu-master/recipes/basepackages.rb +5 -0
- data/cookbooks/mu-master/recipes/default.rb +16 -5
- data/cookbooks/mu-master/recipes/init.rb +36 -3
- data/cookbooks/mu-master/recipes/ssl-certs.rb +6 -0
- data/cookbooks/mu-master/recipes/sssd.rb +85 -62
- data/cookbooks/mu-master/recipes/update_nagios_only.rb +7 -1
- data/cookbooks/mu-master/templates/default/389-directory-setup.inf.erb +11 -26
- data/cookbooks/mu-master/templates/default/sssd.conf.erb +18 -8
- data/cookbooks/mu-tools/files/default/Mu_CA.pem +33 -0
- data/cookbooks/mu-tools/metadata.rb +0 -1
- data/cookbooks/mu-tools/recipes/set_local_fw.rb +7 -1
- data/cookbooks/mu-tools/templates/amazon/sshd_config.erb +5 -1
- data/cookbooks/nagios/CHANGELOG.md +679 -0
- data/cookbooks/nagios/LICENSE +201 -0
- data/cookbooks/nagios/README.md +340 -0
- data/cookbooks/nagios/attributes/config.rb +163 -0
- data/cookbooks/nagios/attributes/default.rb +204 -0
- data/cookbooks/nagios/libraries/base.rb +311 -0
- data/cookbooks/nagios/libraries/command.rb +68 -0
- data/cookbooks/nagios/libraries/contact.rb +229 -0
- data/cookbooks/nagios/libraries/contactgroup.rb +111 -0
- data/cookbooks/{firewall/recipes/disable_firewall.rb → nagios/libraries/custom_option.rb} +20 -7
- data/cookbooks/nagios/libraries/data_bag_helper.rb +23 -0
- data/cookbooks/nagios/libraries/default.rb +90 -0
- data/cookbooks/nagios/libraries/helpers.rb +229 -0
- data/cookbooks/nagios/libraries/host.rb +410 -0
- data/cookbooks/nagios/libraries/hostdependency.rb +178 -0
- data/cookbooks/nagios/libraries/hostescalation.rb +170 -0
- data/cookbooks/nagios/libraries/hostgroup.rb +117 -0
- data/cookbooks/nagios/libraries/nagios.rb +277 -0
- data/cookbooks/nagios/libraries/resource.rb +59 -0
- data/cookbooks/nagios/libraries/service.rb +449 -0
- data/cookbooks/nagios/libraries/servicedependency.rb +213 -0
- data/cookbooks/nagios/libraries/serviceescalation.rb +193 -0
- data/cookbooks/nagios/libraries/servicegroup.rb +142 -0
- data/cookbooks/nagios/libraries/timeperiod.rb +159 -0
- data/cookbooks/nagios/libraries/users_helper.rb +54 -0
- data/cookbooks/nagios/metadata.json +44 -0
- data/cookbooks/nagios/metadata.rb +22 -0
- data/cookbooks/nagios/recipes/_load_databag_config.rb +153 -0
- data/cookbooks/nagios/recipes/_load_default_config.rb +241 -0
- data/cookbooks/nagios/recipes/apache.rb +114 -0
- data/cookbooks/nagios/recipes/default.rb +41 -0
- data/cookbooks/nagios/recipes/nginx.rb +114 -0
- data/cookbooks/nagios/recipes/pagerduty.rb +95 -0
- data/cookbooks/nagios/recipes/server.rb +182 -0
- data/cookbooks/nagios/recipes/server_package.rb +85 -0
- data/cookbooks/nagios/recipes/server_source.rb +137 -0
- data/cookbooks/nagios/resources/command.rb +34 -0
- data/cookbooks/nagios/resources/conf.rb +52 -0
- data/cookbooks/nagios/resources/contact.rb +34 -0
- data/cookbooks/nagios/resources/contactgroup.rb +35 -0
- data/cookbooks/nagios/resources/host.rb +35 -0
- data/cookbooks/nagios/resources/hostdependency.rb +35 -0
- data/cookbooks/nagios/resources/hostescalation.rb +36 -0
- data/cookbooks/nagios/resources/hostgroup.rb +35 -0
- data/cookbooks/nagios/resources/resource.rb +34 -0
- data/cookbooks/nagios/resources/service.rb +35 -0
- data/cookbooks/nagios/resources/servicedependency.rb +35 -0
- data/cookbooks/nagios/resources/serviceescalation.rb +35 -0
- data/cookbooks/nagios/resources/servicegroup.rb +35 -0
- data/cookbooks/nagios/resources/timeperiod.rb +35 -0
- data/cookbooks/nagios/templates/apache2.conf.erb +102 -0
- data/cookbooks/nagios/templates/cgi.cfg.erb +266 -0
- data/cookbooks/nagios/templates/commands.cfg.erb +13 -0
- data/cookbooks/nagios/templates/contacts.cfg.erb +37 -0
- data/cookbooks/nagios/templates/hostgroups.cfg.erb +25 -0
- data/cookbooks/nagios/templates/hosts.cfg.erb +15 -0
- data/cookbooks/nagios/templates/htpasswd.users.erb +6 -0
- data/cookbooks/nagios/templates/nagios.cfg.erb +22 -0
- data/cookbooks/nagios/templates/nginx.conf.erb +80 -0
- data/cookbooks/nagios/templates/pagerduty.cgi.erb +185 -0
- data/cookbooks/nagios/templates/resource.cfg.erb +27 -0
- data/cookbooks/nagios/templates/servicedependencies.cfg.erb +15 -0
- data/cookbooks/nagios/templates/servicegroups.cfg.erb +14 -0
- data/cookbooks/nagios/templates/services.cfg.erb +14 -0
- data/cookbooks/nagios/templates/spawn-fcgi.erb +10 -0
- data/cookbooks/nagios/templates/templates.cfg.erb +31 -0
- data/cookbooks/nagios/templates/timeperiods.cfg.erb +13 -0
- data/extras/platform_berksfile_base +3 -3
- data/extras/python_rpm/build.sh +4 -4
- data/extras/python_rpm/muthon.spec +2 -4
- data/extras/vault_tools/export_vaults.sh +11 -1
- data/install/installer +1 -1
- data/modules/mu/kittens.rb +27523 -0
- data/modules/mu/master/ldap.rb +48 -31
- data/modules/mu/master.rb +69 -0
- data/modules/mu/mu.yaml.rb +351 -0
- data/modules/mu/providers/aws/firewall_rule.rb +3 -1
- data/modules/mu/providers/aws.rb +11 -5
- data/modules/mu.rb +5 -4
- metadata +99 -48
- data/cookbooks/firewall/CHANGELOG.md +0 -488
- data/cookbooks/firewall/LICENSE +0 -202
- data/cookbooks/firewall/README.md +0 -366
- data/cookbooks/firewall/TODO.md +0 -6
- data/cookbooks/firewall/attributes/default.rb +0 -5
- data/cookbooks/firewall/attributes/firewalld.rb +0 -8
- data/cookbooks/firewall/attributes/iptables.rb +0 -17
- data/cookbooks/firewall/attributes/ufw.rb +0 -12
- data/cookbooks/firewall/attributes/windows.rb +0 -8
- data/cookbooks/firewall/libraries/helpers.rb +0 -105
- data/cookbooks/firewall/libraries/helpers_firewalld.rb +0 -116
- data/cookbooks/firewall/libraries/helpers_firewalld_dbus.rb +0 -72
- data/cookbooks/firewall/libraries/helpers_iptables.rb +0 -112
- data/cookbooks/firewall/libraries/helpers_nftables.rb +0 -170
- data/cookbooks/firewall/libraries/helpers_ufw.rb +0 -142
- data/cookbooks/firewall/libraries/helpers_windows.rb +0 -129
- data/cookbooks/firewall/libraries/provider_firewall_firewalld.rb +0 -179
- data/cookbooks/firewall/libraries/provider_firewall_iptables.rb +0 -171
- data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu.rb +0 -200
- data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu1404.rb +0 -200
- data/cookbooks/firewall/libraries/provider_firewall_rule.rb +0 -34
- data/cookbooks/firewall/libraries/provider_firewall_ufw.rb +0 -138
- data/cookbooks/firewall/libraries/provider_firewall_windows.rb +0 -126
- data/cookbooks/firewall/libraries/resource_firewall.rb +0 -26
- data/cookbooks/firewall/libraries/resource_firewall_rule.rb +0 -52
- data/cookbooks/firewall/metadata.json +0 -40
- data/cookbooks/firewall/metadata.rb +0 -15
- data/cookbooks/firewall/recipes/default.rb +0 -76
- data/cookbooks/firewall/recipes/firewalld.rb +0 -87
- data/cookbooks/firewall/resources/firewalld.rb +0 -28
- data/cookbooks/firewall/resources/firewalld_config.rb +0 -39
- data/cookbooks/firewall/resources/firewalld_helpers.rb +0 -106
- data/cookbooks/firewall/resources/firewalld_icmptype.rb +0 -88
- data/cookbooks/firewall/resources/firewalld_ipset.rb +0 -104
- data/cookbooks/firewall/resources/firewalld_policy.rb +0 -115
- data/cookbooks/firewall/resources/firewalld_service.rb +0 -98
- data/cookbooks/firewall/resources/firewalld_zone.rb +0 -118
- data/cookbooks/firewall/resources/nftables.rb +0 -71
- data/cookbooks/firewall/resources/nftables_rule.rb +0 -113
- data/cookbooks/firewall/templates/default/ufw/default.erb +0 -13
- /data/cookbooks/{firewall → nagios}/chefignore +0 -0
- /data/cookbooks/{firewall → nagios}/renovate.json +0 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander Botman <sbotman@schubergphilis.com>
|
3
|
+
# Cookbook:: nagios
|
4
|
+
# Library:: hostescalation
|
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 hostescalation options,
|
25
|
+
# that are used within nagios configurations.
|
26
|
+
#
|
27
|
+
class Hostescalation < Nagios::Base
|
28
|
+
attr_reader :host_description,
|
29
|
+
:host_name,
|
30
|
+
:hostgroup_name,
|
31
|
+
:contacts,
|
32
|
+
:contact_groups
|
33
|
+
|
34
|
+
attr_accessor :first_notification,
|
35
|
+
:last_notification,
|
36
|
+
:notification_interval,
|
37
|
+
:escalation_options,
|
38
|
+
:escalation_period
|
39
|
+
|
40
|
+
def initialize(name)
|
41
|
+
@host_description = name
|
42
|
+
@contacts = {}
|
43
|
+
@contact_groups = {}
|
44
|
+
@host_name = {}
|
45
|
+
@hostgroup_name = {}
|
46
|
+
super()
|
47
|
+
end
|
48
|
+
|
49
|
+
def definition
|
50
|
+
get_definition(configured_options, 'hostescalation')
|
51
|
+
end
|
52
|
+
|
53
|
+
def contacts_list
|
54
|
+
@contacts.values.map(&:to_s).sort.join(',')
|
55
|
+
end
|
56
|
+
|
57
|
+
def contact_groups_list
|
58
|
+
@contact_groups.values.map(&:to_s).sort.join(',')
|
59
|
+
end
|
60
|
+
|
61
|
+
def host_name_list
|
62
|
+
@host_name.values.map(&:to_s).sort.join(',')
|
63
|
+
end
|
64
|
+
|
65
|
+
def hostgroup_name_list
|
66
|
+
@hostgroup_name.values.map(&:to_s).sort.join(',')
|
67
|
+
end
|
68
|
+
|
69
|
+
def import(hash)
|
70
|
+
update_options(hash)
|
71
|
+
update_members(hash, 'contacts', Nagios::Contact)
|
72
|
+
update_members(hash, 'contact_groups', Nagios::Contactgroup)
|
73
|
+
update_members(hash, 'host_name', Nagios::Host)
|
74
|
+
update_members(hash, 'hostgroup_name', Nagios::Hostgroup)
|
75
|
+
end
|
76
|
+
|
77
|
+
def push(obj)
|
78
|
+
case obj
|
79
|
+
when Nagios::Host
|
80
|
+
push_object(obj, @host_name)
|
81
|
+
when Nagios::Hostgroup
|
82
|
+
push_object(obj, @hostgroup_name)
|
83
|
+
when Nagios::Contact
|
84
|
+
push_object(obj, @contacts)
|
85
|
+
when Nagios::Contactgroup
|
86
|
+
push_object(obj, @contact_groups)
|
87
|
+
when Nagios::Timeperiod
|
88
|
+
@escalation_period = obj
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def pop(obj)
|
93
|
+
return if obj == self
|
94
|
+
case obj
|
95
|
+
when Nagios::Host
|
96
|
+
if @host_name.key?(obj.to_s)
|
97
|
+
pop_object(obj, @host_name)
|
98
|
+
pop(self, obj)
|
99
|
+
end
|
100
|
+
when Nagios::Hostgroup
|
101
|
+
if @hostgroup_name.key?(obj.to_s)
|
102
|
+
pop_object(obj, @hostgroup_name)
|
103
|
+
pop(self, obj)
|
104
|
+
end
|
105
|
+
when Nagios::Contact
|
106
|
+
if @contacts.key?(obj.to_s)
|
107
|
+
pop_object(obj, @contacts)
|
108
|
+
pop(self, obj)
|
109
|
+
end
|
110
|
+
when Nagios::Contactgroup
|
111
|
+
if @contact_groups.key?(obj.to_s)
|
112
|
+
pop_object(obj, @contact_groups)
|
113
|
+
pop(self, obj)
|
114
|
+
end
|
115
|
+
when Nagios::Timeperiod
|
116
|
+
@escalation_period = nil if @escalation_period == obj
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_s
|
121
|
+
host_description
|
122
|
+
end
|
123
|
+
|
124
|
+
# check the integer options
|
125
|
+
# default = nil
|
126
|
+
def first_notification=(int)
|
127
|
+
@first_notification = check_integer(int)
|
128
|
+
end
|
129
|
+
|
130
|
+
def last_notification=(int)
|
131
|
+
@last_notification = check_integer(int)
|
132
|
+
end
|
133
|
+
|
134
|
+
def notification_interval=(int)
|
135
|
+
@notification_interval = check_integer(int)
|
136
|
+
end
|
137
|
+
|
138
|
+
# check other options
|
139
|
+
def escalation_options=(arg)
|
140
|
+
@escalation_options = check_state_options(arg, %w(d u r), 'escalation_options')
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def config_options
|
146
|
+
{
|
147
|
+
'name' => 'name',
|
148
|
+
'use' => 'use',
|
149
|
+
'host_description' => nil,
|
150
|
+
'contacts_list' => 'contacts',
|
151
|
+
'contact_groups_list' => 'contact_groups',
|
152
|
+
'escalation_period' => 'escalation_period',
|
153
|
+
'host_name_list' => 'host_name',
|
154
|
+
'hostgroup_name_list' => 'hostgroup_name',
|
155
|
+
'escalation_options' => 'escalation_options',
|
156
|
+
'first_notification' => 'first_notification',
|
157
|
+
'last_notification' => 'last_notification',
|
158
|
+
'notification_interval' => 'notification_interval',
|
159
|
+
'register' => 'register',
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
def merge_members(obj)
|
164
|
+
obj.contacts.each { |m| push(m) }
|
165
|
+
obj.host_name.each { |m| push(m) }
|
166
|
+
obj.contact_groups.each { |m| push(m) }
|
167
|
+
obj.hostgroup_name.each { |m| push(m) }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander Botman <sbotman@schubergphilis.com>
|
3
|
+
# Cookbook:: nagios
|
4
|
+
# Library:: hostgroup
|
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 hostgroup options,
|
25
|
+
# that are used within nagios configurations.
|
26
|
+
#
|
27
|
+
class Hostgroup < Nagios::Base
|
28
|
+
attr_reader :hostgroup_name,
|
29
|
+
:members,
|
30
|
+
:hostgroup_members
|
31
|
+
|
32
|
+
attr_accessor :alias,
|
33
|
+
:notes,
|
34
|
+
:notes_url,
|
35
|
+
:action_url
|
36
|
+
|
37
|
+
def initialize(hostgroup_name)
|
38
|
+
@hostgroup_name = hostgroup_name
|
39
|
+
@members = {}
|
40
|
+
@hostgroup_members = {}
|
41
|
+
super()
|
42
|
+
end
|
43
|
+
|
44
|
+
def definition
|
45
|
+
get_definition(configured_options, 'hostgroup')
|
46
|
+
end
|
47
|
+
|
48
|
+
def hostgroup_members_list
|
49
|
+
@hostgroup_members.values.map(&:to_s).sort.join(',')
|
50
|
+
end
|
51
|
+
|
52
|
+
def import(hash)
|
53
|
+
update_options(hash)
|
54
|
+
update_members(hash, 'members', Nagios::Host, true)
|
55
|
+
update_members(hash, 'hostgroups_members', Nagios::Hostgroup, true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def members_list
|
59
|
+
@members.values.map(&:to_s).sort.join(',')
|
60
|
+
end
|
61
|
+
|
62
|
+
def push(obj)
|
63
|
+
case obj
|
64
|
+
when Nagios::Host
|
65
|
+
push_object(obj, @members)
|
66
|
+
when Nagios::Hostgroup
|
67
|
+
push_object(obj, @hostgroup_members)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def pop(obj)
|
72
|
+
return if obj == self
|
73
|
+
case obj
|
74
|
+
when Nagios::Host
|
75
|
+
if @members.key?(obj.to_s)
|
76
|
+
pop_object(obj, @members)
|
77
|
+
obj.pop(obj)
|
78
|
+
end
|
79
|
+
when Nagios::Hostgroup
|
80
|
+
if @hostgroups_members.key?(obj.to_s)
|
81
|
+
pop_object(obj, @hostgroup_members)
|
82
|
+
obj.pop(obj)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.create(name)
|
88
|
+
Nagios.instance.find(Nagios::Hostgroup.new(name))
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_s
|
92
|
+
hostgroup_name
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def config_options
|
98
|
+
{
|
99
|
+
'name' => 'name',
|
100
|
+
'use' => 'use',
|
101
|
+
'hostgroup_name' => 'hostgroup_name',
|
102
|
+
'members_list' => 'members',
|
103
|
+
'hostgroup_members_list' => 'hostgroup_members',
|
104
|
+
'alias' => 'alias',
|
105
|
+
'notes' => 'notes',
|
106
|
+
'notes_url' => 'notes_url',
|
107
|
+
'action_url' => 'action_url',
|
108
|
+
'register' => 'register',
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def merge_members(obj)
|
113
|
+
obj.members.each { |m| push(m) }
|
114
|
+
obj.hostgroup_members.each { |m| push(m) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander Botman <sbotman@schubergphilis.com>
|
3
|
+
# Cookbook:: nagios
|
4
|
+
# Library:: nagios
|
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
|
+
#
|
22
|
+
# This class holds all methods with regard to the nagios model.
|
23
|
+
#
|
24
|
+
class Nagios
|
25
|
+
attr_reader :commands,
|
26
|
+
:contactgroups,
|
27
|
+
:contacts,
|
28
|
+
:hostgroups,
|
29
|
+
:hosts,
|
30
|
+
:servicegroups,
|
31
|
+
:services,
|
32
|
+
:timeperiods,
|
33
|
+
:hostdependencies,
|
34
|
+
:hostescalations,
|
35
|
+
:servicedependencies,
|
36
|
+
:serviceescalations,
|
37
|
+
:resources
|
38
|
+
|
39
|
+
attr_accessor :host_name_attribute,
|
40
|
+
:normalize_hostname,
|
41
|
+
:default_command,
|
42
|
+
:default_contactgroup,
|
43
|
+
:default_contact,
|
44
|
+
:default_hostgroup,
|
45
|
+
:default_host,
|
46
|
+
:default_servicegroup,
|
47
|
+
:default_service,
|
48
|
+
:default_timeperiod
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@commands = {}
|
52
|
+
@contactgroups = {}
|
53
|
+
@contacts = {}
|
54
|
+
@hostgroups = {}
|
55
|
+
@hosts = {}
|
56
|
+
@servicegroups = {}
|
57
|
+
@services = {}
|
58
|
+
@timeperiods = {}
|
59
|
+
@hostdependencies = {}
|
60
|
+
@hostescalations = []
|
61
|
+
@servicedependencies = {}
|
62
|
+
@serviceescalations = []
|
63
|
+
@resources = {}
|
64
|
+
@host_name_attribute = 'hostname'
|
65
|
+
@normalize_hostname = false
|
66
|
+
end
|
67
|
+
|
68
|
+
def commands
|
69
|
+
Hash[@commands.sort]
|
70
|
+
end
|
71
|
+
|
72
|
+
def contactgroups
|
73
|
+
Hash[@contactgroups.sort]
|
74
|
+
end
|
75
|
+
|
76
|
+
def contacts
|
77
|
+
Hash[@contacts.sort]
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete(hash, key)
|
81
|
+
case hash
|
82
|
+
when 'command'
|
83
|
+
@commands.delete(key)
|
84
|
+
when 'contactgroup'
|
85
|
+
@contactgroups.delete(key)
|
86
|
+
when 'contact'
|
87
|
+
@contacts.delete(key)
|
88
|
+
when 'hostgroup'
|
89
|
+
@hostgroups.delete(key)
|
90
|
+
when 'host'
|
91
|
+
@hosts.delete(key)
|
92
|
+
when 'servicegroup'
|
93
|
+
@servicegroups.delete(key)
|
94
|
+
when 'service'
|
95
|
+
@services.delete(key)
|
96
|
+
when 'timeperiod'
|
97
|
+
@timeperiods.delete(key)
|
98
|
+
when 'hostdependency'
|
99
|
+
@hostdependencies.delete(key)
|
100
|
+
when 'hostescalation'
|
101
|
+
@hostescalations.delete(key)
|
102
|
+
when 'servicedependency'
|
103
|
+
@servicedependencies.delete(key)
|
104
|
+
when 'serviceescalation'
|
105
|
+
@serviceescalations.delete(key)
|
106
|
+
when 'resource'
|
107
|
+
@resources.delete(key)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def find(obj)
|
112
|
+
case obj
|
113
|
+
when Nagios::Command
|
114
|
+
find_object(obj, @commands)
|
115
|
+
when Nagios::Contact
|
116
|
+
find_object(obj, @contacts)
|
117
|
+
when Nagios::Contactgroup
|
118
|
+
find_object(obj, @contactgroups)
|
119
|
+
when Nagios::Host
|
120
|
+
find_object(obj, @hosts)
|
121
|
+
when Nagios::Hostgroup
|
122
|
+
find_object(obj, @hostgroups)
|
123
|
+
when Nagios::Service
|
124
|
+
find_object(obj, @services)
|
125
|
+
when Nagios::Servicegroup
|
126
|
+
find_object(obj, @servicegroups)
|
127
|
+
when Nagios::Timeperiod
|
128
|
+
find_object(obj, @timeperiods)
|
129
|
+
when Nagios::Hostdependency
|
130
|
+
find_object(obj, @hostdependencies)
|
131
|
+
when Nagios::Servicedependency
|
132
|
+
find_object(obj, @servicedependencies)
|
133
|
+
when Nagios::Resource
|
134
|
+
find_object(obj, @resources)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def hosts
|
139
|
+
Hash[@hosts.sort]
|
140
|
+
end
|
141
|
+
|
142
|
+
def hostdependencies
|
143
|
+
Hash[@hostdependencies.sort]
|
144
|
+
end
|
145
|
+
|
146
|
+
def hostgroups
|
147
|
+
Hash[@hostgroups.sort]
|
148
|
+
end
|
149
|
+
|
150
|
+
def normalize_hostname=(expr)
|
151
|
+
@normalize_hostname = (expr == true || !(expr =~ /y|yes|true|1/).nil?)
|
152
|
+
end
|
153
|
+
|
154
|
+
def push(obj)
|
155
|
+
case obj
|
156
|
+
when Chef::Node
|
157
|
+
push_node(obj)
|
158
|
+
when Nagios::Command
|
159
|
+
push_object(obj)
|
160
|
+
when Nagios::Contact
|
161
|
+
push_object(obj)
|
162
|
+
when Nagios::Contactgroup
|
163
|
+
push_object(obj)
|
164
|
+
when Nagios::Host
|
165
|
+
push_object(obj)
|
166
|
+
when Nagios::Hostgroup
|
167
|
+
push_object(obj)
|
168
|
+
when Nagios::Service
|
169
|
+
push_object(obj)
|
170
|
+
when Nagios::Servicegroup
|
171
|
+
push_object(obj)
|
172
|
+
when Nagios::Timeperiod
|
173
|
+
push_object(obj)
|
174
|
+
when Nagios::Hostdependency
|
175
|
+
push_object(obj)
|
176
|
+
when Nagios::Hostescalation
|
177
|
+
@hostescalations.push(obj)
|
178
|
+
when Nagios::Servicedependency
|
179
|
+
push_object(obj)
|
180
|
+
when Nagios::Serviceescalation
|
181
|
+
@serviceescalations.push(obj)
|
182
|
+
when Nagios::Resource
|
183
|
+
push_object(obj)
|
184
|
+
else
|
185
|
+
Chef::Log.fail("Nagios error: Pushing unknown object: #{obj.class} into Nagios.instance")
|
186
|
+
raise
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def timeperiods
|
191
|
+
Hash[@timeperiods.sort]
|
192
|
+
end
|
193
|
+
|
194
|
+
def resources
|
195
|
+
Hash[@resources.sort]
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.instance
|
199
|
+
@instance ||= Nagios.new
|
200
|
+
end
|
201
|
+
|
202
|
+
def services
|
203
|
+
Hash[@services.sort]
|
204
|
+
end
|
205
|
+
|
206
|
+
def servicedependencies
|
207
|
+
Hash[@servicedependencies.sort]
|
208
|
+
end
|
209
|
+
|
210
|
+
def servicegroups
|
211
|
+
Hash[@servicegroups.sort]
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def blank?(expr)
|
217
|
+
return true if expr.nil?
|
218
|
+
case expr
|
219
|
+
when 'String', String
|
220
|
+
return true if expr == ''
|
221
|
+
when 'Array', 'Hash', Array, Hash
|
222
|
+
return true if expr.empty?
|
223
|
+
else
|
224
|
+
return false
|
225
|
+
end
|
226
|
+
false
|
227
|
+
end
|
228
|
+
|
229
|
+
def find_object(obj, hash)
|
230
|
+
current = hash[obj.to_s]
|
231
|
+
if current.nil?
|
232
|
+
Chef::Log.debug("Nagios debug: Creating entry for #{obj.class} with name: #{obj}")
|
233
|
+
hash[obj.to_s] = obj
|
234
|
+
obj
|
235
|
+
else
|
236
|
+
Chef::Log.debug("Nagios debug: Found entry for #{obj.class} with name: #{obj}")
|
237
|
+
current
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def get_groups(obj)
|
242
|
+
groups = obj['roles'].nil? ? [] : obj['roles'].dup
|
243
|
+
groups += [obj['os']] unless blank?(obj['os'])
|
244
|
+
groups + [obj.chef_environment]
|
245
|
+
end
|
246
|
+
|
247
|
+
def get_hostname(obj)
|
248
|
+
return obj.name if @host_name_attribute == 'name'
|
249
|
+
return obj['nagios']['host_name'] unless blank?(obj['nagios']) || blank?(obj['nagios']['host_name'])
|
250
|
+
return obj[@host_name_attribute] unless blank?(obj[@host_name_attribute])
|
251
|
+
return obj['hostname'] unless blank?(obj['hostname'])
|
252
|
+
return obj.name unless blank?(obj.name)
|
253
|
+
nil
|
254
|
+
end
|
255
|
+
|
256
|
+
def push_node(obj)
|
257
|
+
groups = get_groups(obj)
|
258
|
+
hostname = get_hostname(obj)
|
259
|
+
return if hostname.nil?
|
260
|
+
|
261
|
+
host = find(Nagios::Host.new(hostname))
|
262
|
+
# TODO: merge the ip_to_monitor funtion into this logic here
|
263
|
+
host.address = obj['ipaddress']
|
264
|
+
host.import(obj['nagios']) unless obj['nagios'].nil?
|
265
|
+
|
266
|
+
groups.each do |r|
|
267
|
+
hg = find(Nagios::Hostgroup.new(r))
|
268
|
+
hg.push(host)
|
269
|
+
host.push(hg)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def push_object(obj)
|
274
|
+
object = find(obj.class.new(obj.to_s))
|
275
|
+
object.merge!(obj)
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander Botman <sbotman@schubergphilis.com>
|
3
|
+
# Cookbook:: nagios
|
4
|
+
# Library:: resource
|
5
|
+
#
|
6
|
+
# Copyright:: 2015, 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 resource options,
|
25
|
+
# that are used within nagios configurations.
|
26
|
+
#
|
27
|
+
class Resource < Nagios::Base
|
28
|
+
attr_reader :key
|
29
|
+
attr_accessor :value
|
30
|
+
|
31
|
+
def initialize(key, value = nil)
|
32
|
+
@key = key
|
33
|
+
@value = value
|
34
|
+
super()
|
35
|
+
end
|
36
|
+
|
37
|
+
def definition
|
38
|
+
if blank?(value)
|
39
|
+
"# Skipping #{key} because the value is missing."
|
40
|
+
elsif key =~ /^USER([1-9]|[1-9][0-9]|[1-2][0-4][0-9]|25[0-6])$/
|
41
|
+
"$#{@key}$=#{@value}"
|
42
|
+
else
|
43
|
+
"# Skipping #{key} because the it's not valid. Use USER[1-256] as your key."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.create(name)
|
48
|
+
Nagios.instance.find(Nagios::Resource.new(name))
|
49
|
+
end
|
50
|
+
|
51
|
+
def import(hash)
|
52
|
+
update_options(hash)
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
key
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|