OSDN Git Service

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