OSDN Git Service

fix service control.
[metasearch/grid-chef-repo.git] / roles / grid-nm.rb
1 #
2 # Copyright 2013-2014, whitestar
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 $LOAD_PATH.push("#{File.dirname(__FILE__)}/_lib")
18 #${chef-repo}/roles/_lib/grid.rb
19 require 'grid'
20
21 name 'grid-nm'
22 description 'Grid Base nagios node'
23
24 run_list(
25   'role[node_commons]',
26   'role[nameservice-client-grid]',
27   'role[ganglia-gmond]',
28   'role[nagios]'
29 )
30
31 #env_run_lists "prod" => ["recipe[apache2]"], "staging" => ["recipe[apache2::staging]"], "_default" => []
32
33 this_cluster = Grid::CLUSTERS[:base]
34 this_subcluster = Grid::CLUSTERS[:base][:nagioses]
35 mcast_addr = this_subcluster[:mcast_addr]
36 port = '8649'
37 =begin
38 # uni-cast
39 udp_send_channels4ucast = []
40 this_subcluster[:nodes].first(2).each {|host|
41   udp_send_channels4ucast.push(
42     {
43       'mcast_join' => '',
44       'host' => "#{host}.#{Grid::DOMAIN}",
45       'port' => port,
46       'ttl' => ''
47     }
48   )
49 }
50 =end
51
52 host_templates = []
53 hosts = []
54 hostgroups = []
55 hostgroup_names = []
56
57 Grid::CLUSTERS[:base].each {|key, cluster|
58   host_templates.push(
59     {
60       'name' => cluster[:use_host_object],
61       'use' => 'generic-grid-host',
62       'register' => '0'
63     }
64   )
65
66   cluster[:nodes].each {|node|
67     hosts.push(
68       {
69         'host_name' => node,
70         'use' => cluster[:use_host_object],
71         'address' => "#{node}.#{Grid::DOMAIN}",
72       }
73     )
74   }  
75
76   hostgroups.push( 
77     {
78       'hostgroup_name' => cluster[:name],
79       'alias' => cluster[:alias],
80       'members' => cluster[:nodes].join(','),
81     }
82   )
83   hostgroup_names.push(cluster[:name])
84 }
85
86 nagios_objects = {
87   'contacts' => [
88     {
89       'name' => 'generic-grid-contact',
90       'service_notification_period' => '24x7',
91       'host_notification_period' => '24x7',
92       'service_notification_options' => 'w,u,c,r',
93       'host_notification_options' => 'd,u,r',
94       'service_notification_commands' => 'notify-service-by-email',
95       'host_notification_commands' => 'notify-host-by-email',
96       'register' => '0'
97     },
98     {
99       'contact_name' => 'alice',
100       'use' => 'generic-grid-contact',
101       'alias' => 'Alice',
102       'email' => 'alice@localhost'
103     },
104     {
105       'contact_name' => 'bob',
106       'use' => 'generic-grid-contact',
107       'alias' => 'Bob',
108       'email' => 'bob@localhost'
109     }
110   ],
111   'contactgroups' => [
112     {
113       'contactgroup_name' => 'grid-admins',
114       'alias' => 'Grid Administrators',
115       'members' => 'root'
116       #'members' => 'alice,bob'
117     }
118   ],
119   'hosts' => [
120     {
121       'name' => 'generic-grid-host',
122       'use' => 'generic-host',
123       'alias' => 'Grid Node',
124       'check_command' => 'check-host-alive',
125       'max_check_attempts' => '20',
126       'notification_interval' => '60',
127       'notification_period' => '24x7',
128       'notification_options' => 'd,u,r',
129       'register' => '0',
130     }
131   ] + host_templates + hosts,
132   'hostgroups' => \
133     hostgroups + [
134       # all nodes
135       {
136         'hostgroup_name' => 'grid-servers',
137         'alias' => 'GridServers',
138         'hostgroup_members' => hostgroup_names.join(',')
139       }
140     ],
141   'services' => [
142     # ganglia gmetad monitoring
143     {
144       'use' => 'generic-check_ganglia_cache-service',
145       'host_name' => 'localhost',
146       'contact_groups' => 'grid-admins',
147     },
148     {
149       'use' => 'generic-ganglia_heartbeat-service',
150       'hostgroup_name' => "#{this_cluster[:gmetads][:name]}",
151       'contact_groups' => 'grid-admins',
152     },
153     # standard monitoring.
154     {
155       'use' => 'generic-ping-service',
156       'hostgroup_name' => 'grid-servers',
157       'contact_groups' => 'grid-admins',
158     },
159     {
160       'use' => 'generic-ssh-service',
161       'hostgroup_name' => 'grid-servers',
162       'contact_groups' => 'grid-admins',
163     },
164     {
165       'use' => 'generic-ntp-service',
166       'hostgroup_name' => 'grid-servers',
167       'contact_groups' => 'grid-admins',
168     },
169     {
170       'use' => 'generic-load_one-service',
171       'hostgroup_name' => 'grid-servers',
172       'contact_groups' => 'grid-admins',
173     },
174     {
175       'use' => 'generic-load_five-service',
176       'hostgroup_name' => 'grid-servers',
177       'contact_groups' => 'grid-admins',
178     },
179     {
180       'use' => 'generic-load_fifteen-service',
181       'hostgroup_name' => 'grid-servers',
182       'contact_groups' => 'grid-admins',
183     },
184     {
185       'use' => 'generic-part_max_used-service',
186       'hostgroup_name' => 'grid-servers',
187       'contact_groups' => 'grid-admins',
188     },
189     {
190       'use' => 'generic-proc_total-service',
191       'hostgroup_name' => 'grid-servers',
192       'contact_groups' => 'grid-admins',
193     },
194     {
195       'use' => 'generic-http-service',
196       'hostgroup_name' \
197         => "#{this_cluster[:gmetads][:name]},#{this_cluster[:nagioses][:name]}",
198       'contact_groups' => 'grid-admins',
199     },
200 =begin
201     {
202       'use' => 'generic-ldap-service',
203       'hostgroup_name' => 'grid-nameservice-servers',
204       'check_command' => 'check_ldap3!dc=grid,dc=example,dc=com',
205       'contact_groups' => 'grid-admins',
206     },
207 =end
208   ],
209   'servicedependencies' => [
210     {
211       'host_name' => 'localhost',
212       'service_description' => 'Cache for check_ganglia_metric',
213       #'dependent_host_name' => '.*',  # NG!
214       'dependent_hostgroup_name' => 'grid-servers',
215       'dependent_service_description' => '.* via Ganglia$',
216       'execution_failure_criteria' => 'c,p'
217     }
218   ]
219 }
220
221 default_attributes(
222   'nagios' => {
223     'cluster_name' => 'grid-base',
224     'objects' => nagios_objects,
225     'web' => {
226       'Allow' => [
227         "from .#{Grid::DOMAIN}",
228         'from 192.168.0.0/16'],
229       'AuthType' => 'Kerberos',
230       'mod_auth_kerb' => {
231         'KrbAuthRealms' => Grid::REALM,
232         'Krb5Keytab' => '/etc/krb5.keytab'
233       }
234     },
235     'check_external_commands' => '1',
236     'use_regexp_matching' => '1',
237     'authorized_for_system_information' => '*',
238     'authorized_for_configuration_information' => '*',
239     'authorized_for_system_commands' => '*',
240     'authorized_for_all_services' => '*',
241     'authorized_for_all_hosts' => '*',
242     'authorized_for_all_service_commands' => '*',
243     'authorized_for_all_host_commands' => '*',
244     'check_ganglia_metric' => {
245       'enabled' => true,
246       'gmetad_host' => "#{this_cluster[:gmetads][:service_hostname]}.#{Grid::DOMAIN}"
247     },
248   }
249 )
250
251 override_attributes(
252   'ganglia' => {
253     # gmond
254     'cluster' => {
255       'name' => this_subcluster[:alias],
256       'owner' => Grid::DOMAIN
257     },
258     'static' => {
259       ## static multi-cast
260       'udp_send_channels' => [
261         {
262           'mcast_join' => mcast_addr,
263           'host' => '',
264           'port' => port,
265           'ttl' => '1'
266         }
267       ],
268       'udp_recv_channels' => [
269         {
270           'mcast_join' => mcast_addr,
271           'port' => port,
272           'bind' => mcast_addr
273         }
274       ]
275 =begin
276       ## static uni-cast
277       'udp_send_channels' => udp_send_channels4ucast,
278       'udp_recv_channels' => [
279         {
280           'mcast_join' => '',
281           'port' => port,
282           'bind' => ''
283         }
284       ]
285 =end
286     }
287   }
288 )