-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.rb
151 lines (127 loc) · 3.5 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#
# Author:: Joshua Sierles <joshua@37signals.com>
# Author:: Joshua Timberman <joshua@opscode.com>
# Author:: Nathan Haneysmith <nathan@opscode.com>
# Cookbook Name:: nagios
# Recipe:: server
#
# Copyright 2009, 37signals
# Copyright 2009-2010, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include_recipe "apache2"
include_recipe "apache2::mod_ssl"
include_recipe "apache2::mod_rewrite"
include_recipe "nagios::client"
sysadmins = search(:users, 'groups:sysadmin')
nodes = search(:node, "hostname:[* TO *] AND app_environment:#{node[:app_environment]}")
if nodes.empty?
Chef::Log.info("No nodes returned from search, using this node so hosts.cfg has data")
nodes = Array.new
nodes << node
end
members = Array.new
sysadmins.each do |s|
members << s['id']
end
role_list = Array.new
service_hosts= Hash.new
search(:role, "*:*") do |r|
role_list << r.name
search(:node, "role:#{r.name} AND app_environment:#{node[:app_environment]}") do |n|
service_hosts[r.name] = n['hostname']
end
end
if node[:public_domain]
public_domain = node[:public_domain]
else
public_domain = node[:domain]
end
%w{ nagios3 nagios-nrpe-plugin nagios-images }.each do |pkg|
package pkg
end
service "nagios3" do
supports :status => true, :restart => true, :reload => true
action [ :enable ]
end
nagios_conf "nagios" do
config_subdir false
end
directory "#{node[:nagios][:dir]}/dist" do
owner "nagios"
group "nagios"
mode "0755"
end
directory node[:nagios][:state_dir] do
owner "nagios"
group "nagios"
mode "0751"
end
directory "#{node[:nagios][:state_dir]}/rw" do
owner "nagios"
group node[:apache][:user]
mode "2710"
end
execute "archive default nagios object definitions" do
command "mv #{node[:nagios][:dir]}/conf.d/*_nagios*.cfg #{node[:nagios][:dir]}/dist"
not_if { Dir.glob(node[:nagios][:dir] + "/conf.d/*_nagios*.cfg").empty? }
end
file "#{node[:apache][:dir]}/conf.d/nagios3.conf" do
action :delete
end
case node[:nagios][:server_auth_method]
when "openid"
include_recipe "apache2::mod_auth_openid"
else
template "#{node[:nagios][:dir]}/htpasswd.users" do
source "htpasswd.users.erb"
owner "nagios"
group node[:apache][:user]
mode 0640
variables(
:sysadmins => sysadmins
)
end
end
apache_site "000-default" do
enable false
end
template "#{node[:apache][:dir]}/sites-available/nagios3.conf" do
source "apache2.conf.erb"
mode 0644
variables :public_domain => public_domain
if File.symlink?("#{node[:apache][:dir]}/sites-enabled/nagios3.conf")
notifies :reload, resources(:service => "apache2")
end
end
apache_site "nagios3.conf"
%w{ nagios cgi }.each do |conf|
nagios_conf conf do
config_subdir false
end
end
%w{ commands templates timeperiods}.each do |conf|
nagios_conf conf
end
nagios_conf "services" do
variables :service_hosts => service_hosts
end
nagios_conf "contacts" do
variables :admins => sysadmins, :members => members
end
nagios_conf "hostgroups" do
variables :roles => role_list
end
nagios_conf "hosts" do
variables :nodes => nodes
end