client.rb 2.67 KB
Newer Older
jtimberman's avatar
jtimberman committed
1
2
3
4
#
# Cookbook Name:: rsyslog
# Recipe:: client
#
Tim Smith's avatar
Tim Smith committed
5
# Copyright 2009-2015, Chef Software, Inc.
jtimberman's avatar
jtimberman committed
6
7
8
9
#
# 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
10
#
jtimberman's avatar
jtimberman committed
11
#     http://www.apache.org/licenses/LICENSE-2.0
12
#
jtimberman's avatar
jtimberman committed
13
14
15
16
17
18
19
# 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.
#

20
21
22
# Do not run this recipe if the server attribute is set
return if node['rsyslog']['server']
include_recipe 'rsyslog::default'
23

Sasha Gerrand's avatar
Sasha Gerrand committed
24
25
26
27
28
29
results = search(:node, node['rsyslog']['server_search']).map do |server|
  ipaddress = server['ipaddress']
  # If both server and client are on the same cloud and local network, they may be
  # instructed to communicate via the internal interface by enabling `use_local_ipv4`
  if node['rsyslog']['use_local_ipv4'] && server.attribute?('cloud') && server['cloud']['local_ipv4']
    ipaddress = server['cloud']['local_ipv4']
30
  end
Sasha Gerrand's avatar
Sasha Gerrand committed
31
  ipaddress
32
end
Sasha Gerrand's avatar
Sasha Gerrand committed
33
server_ips = Array(node['rsyslog']['server_ip']) + Array(results)
34
35
36
37
38
39
40
41
42
43
44
45
46
47

rsyslog_servers = []

server_ips.each do |ip|
  rsyslog_servers << { 'server' => ip, 'port' => node['rsyslog']['port'], 'logs' => node['rsyslog']['logs_to_forward'], 'protocol' => node['rsyslog']['protocol'], 'remote_template' => node['rsyslog']['default_remote_template'] }
end

unless node['rsyslog']['custom_remote'].first.empty?
  node['rsyslog']['custom_remote'].each do |server|
    if server['server'].nil?
      Chef::Application.fatal!('Found a custom_remote server with no IP. Check your custom_remote attribute definition!')
    end
  end
  rsyslog_servers += node['rsyslog']['custom_remote']
48
end
49

50
if rsyslog_servers.empty?
Ronald Doorn's avatar
Ronald Doorn committed
51
52
  Chef::Log.warn('The rsyslog::client recipe was unable to determine the remote syslog server. Checked both the server_ip attribute and search! Not forwarding logs.')
else
53
  remote_type = node['rsyslog']['use_relp'] ? 'relp' : 'remote'
54

Jennifer Davis's avatar
Jennifer Davis committed
55
56
57
58
59
60
61
62
63
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/49-remote.conf" do
  source    "49-#{remote_type}.conf.erb"
  owner     'root'
  group     'root'
  mode      '0644'
  variables(:servers => rsyslog_servers)
  notifies  :run, 'execute[validate_config]'
  notifies  :restart, "service[#{node['rsyslog']['service_name']}]"
  only_if   { node['rsyslog']['remote_logs'] }
64
end
65

Dan Buch's avatar
Dan Buch committed
66
file "#{node['rsyslog']['config_prefix']}/rsyslog.d/server.conf" do
67
  action   :delete
Jennifer Davis's avatar
Jennifer Davis committed
68
  notifies :run, 'execute[validate_config]'
69
  notifies :restart, "service[#{node['rsyslog']['service_name']}]"
70
end