Skip to content

Instantly share code, notes, and snippets.

@jbz
Created August 8, 2011 18:06
Show Gist options
  • Save jbz/1132325 to your computer and use it in GitHub Desktop.
Save jbz/1132325 to your computer and use it in GitHub Desktop.
rsyslog remote logging
# Recipe:: client
#
# Copyright 2010, Medidata Solutions 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.
#
# NOTE NOTE NOTE
# We use a Chef attr namespace "mdsol" to hold all of our infrastructure's global
# attribs.
include_recipe "rsyslog::default"
# Determine if there is a logserver
# First: set by the role attribute mdsol:logserver ( this allows multiple syslog servers )
# Second: search for the first accurence of a rsyslog_server:true ( knife search node "rsyslog_server:true" -a fqdn )
# Third: just set it to localhost and don't bother with the configuration
# This is *not* best handled by a default[:attr] b/c we're checking for a non-rsyslog namespace
# attribute and setting a local var based on the answer.
rsyslog_server = if host = node[:mdsol][:logserver]
host
elsif (host = search(:node, "rsyslog_server:true").first) && host['fqdn']
host['fqdn']
else
"localhost"
end
rsyslog_port = if port = node[:mdsol][:log_port]
port
else
"514"
end
unless node[:rsyslog][:server]
unless rsyslog_server == "localhost"
template "/etc/rsyslog.d/remote.conf" do
source "remote.conf.erb"
backup false
variables(
:server => rsyslog_server,
:protocol => node[:rsyslog][:protocol],
:port => rsyslog_port
)
owner "root"
group "root"
mode 0644
notifies :restart, resources(:service => "rsyslog"), :immediate
end
end
file "/etc/rsyslog.d/server.conf" do
action :delete
notifies :reload, resources(:service => "rsyslog"), :immediate
only_if do File.exists?("/etc/rsyslog.d/server.conf") end
end
end
if rsyslog_server == "localhost"
file "/etc/rsyslog.d/remote.conf" do
action :delete
notifies :reload, resources(:service => "rsyslog"), :immediate
only_if do File.exists?("/etc/rsyslog.d/remote.conf") end
end
end
#
# Generated by Chef
#
# Network logging configuration
<% case @protocol -%>
<% when "tcp" -%>
*.*;lpr.none;news.none @@<%= @server %>:<%= @port %>
<% when "udp" -%>
*.*;lpr.none;news.none @<%= @server %>:<%= @port %>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment