Home

Awesome

rsyslog Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

Installs and configures rsyslog to replace syslogd for client and/or server use. By default, the service will be configured to log to files on local disk. See the Recipes and Examples sections for other uses.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

Chef

Other

To use the recipe[rsyslog::client] recipe, you'll need to set up the rsyslog.server_search or rsyslog.server_ip attributes. See the Recipes and Examples sections below.

Attributes

See attributes/default.rb for default values.

Recipes

default

Installs the rsyslog package, manages the rsyslog service and sets up basic configuration for a standalone machine.

client

Includes recipe[rsyslog].

Uses node['rsyslog']['server_ip'] or Chef search (in that precedence order) to determine the remote syslog server's IP address. If search is used, the search query will look for the first ipaddress returned from the criteria specified in node['rsyslog']['server_search'].

You can use node['rsyslog']['custom_config'] to define custom entries for sending logs to remote servers. Available attributes:

    'server': Ip/hostname of remote syslog server (Required)
    'port': Port to send logs to
    'logs': Syslog log facilities to send (auth, authpriv, daemon, etc)
    'protocol': Can be tcp or udp
    'remote_template': Rsyslog template used for the messages

Example:

node['rsyslog']['custom_remote'] = [
  { 'server' => '10.10.4.4', 'port' => '567', 'logs' => 'auth.*,mail.*', 'protocol' => 'udp', 'remote_template' => 'RSYSLOG_SyslogProtocol23Format'},
  { 'server' => '10.0.0.3', 'port' => '555', 'logs' => 'authpriv,daemon.*' }
]

The server key is required; if other keys are left out, the default global values will be used (eg node['rsyslog']['port'] will be used if 'port' is omitted)

If the node itself is a rsyslog server ie it has rsyslog.server set to true then the configuration is skipped.

If the node had an /etc/rsyslog.d/35-server-per-host.conf file previously configured, this file gets removed to prevent duplicate logging.

Any previous logs are not cleaned up from the log_dir.

server

Configures the node to be a rsyslog server. The chosen rsyslog server node should be defined in the server_ip attribute or resolvable by the specified search criteria specified in node['rsyslog']['server_search] (so that nodes making use of the client recipe can find the server to log to).

The server recipe will create the logs in attribute node['rsyslog']['log_dir'], and the configuration in /etc/rsyslog.d/server.conf. This recipe also removes any previous configuration to a remote server by removing the file /etc/rsyslog.d/49-remote.conf.

The cron job used in the previous version of this cookbook is removed, but it does not remove any existing cron job from your system (so it doesn't break anything unexpectedly). We recommend setting up logrotate for the logfiles instead.

The log_dir will be concatenated with per_host_dir to store the logs for each client. Modify the attribute to have a value that is allowed by rsyslogs template matching values, see the rsyslog documentation for this.

Directory structure:

<%= @log_dir %>/<%= @per_host_dir %>/"logfile"

For example for the system with hostname www:

/srv/rsyslog/2011/11/19/www/messages

For example, to change this to just the hostname, set the attribute node['rsyslog']['per_host_dir'] via a role:

"rsyslog" => { "per_host_dir" => "%HOSTNAME%" }

At this time, the server can only listen on UDP or TCP.

Resources

file_input

Configures a text file input monitor to push a log file into rsyslog. Rsyslog must be installed to use this custom resource either using your own wrapper cookbook or the rsyslog::default recipe.

Properties:

Usage

Use recipe[rsyslog] to install and start rsyslog as a basic configured service for standalone systems.

Use recipe[rsyslog::client] to have nodes log to a remote server (which is found via the server_ip attribute or by the recipe's search call -- see client)

Use recipe[rsyslog::server] to set up a rsyslog server. It will listen on node['rsyslog']['port'] protocol node['rsyslog']['protocol'].

If you set up a different kind of centralized loghost (syslog-ng, graylog2, logstash, etc), you can still send log messages to it as long as the port and protocol match up with the server software. See Examples

Use rsyslog_file_input within your recipes to forward log files to your remote syslog server.

Examples

A base role (e.g., roles/base.rb), applied to all nodes so they are syslog clients:

name "base"
description "Base role applied to all nodes"
run_list("recipe[rsyslog::client]")

Then, a role for the loghost (should only be one):

name "loghost"
description "Central syslog server"
run_list("recipe[rsyslog::server]")

By default this will set up the clients search for a node with the loghost role to talk to the server on TCP port 514. Change the protocol and port rsyslog attributes to modify this.

If you want to specify another syslog compatible server with a role other than loghost, simply fill free to use the server_ip attribute or the server_search attribute.

Example role that sets the per host directory:

name "loghost"
description "Central syslog server"
run_list("recipe[rsyslog::server]")
default_attributes(
  "rsyslog" => { "per_host_dir" => "%HOSTNAME%" }
)

Default rsyslog options are rendered for RHEL family platforms, in /etc/rsyslog.d/50-default.conf with other platforms using a configuration like Debian family defaults. You can override these log facilities and destinations using the rsyslog['default_facility_logs'] hash.

name "facility_log_example"
run_list("recipe[rsyslog::default]")
default_attributes(
  "rsyslog" => {
    "default_facility_logs" => {
      '*.info;mail.none;authpriv.none;cron.none' => "/var/log/messages",
      'authpriv' => '/var/log/secure',
      'mail.*' => '-/var/log/maillog',
      '*.emerg' => '*'
    }
  }
)

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website