sous-chefs / rsyslog

Development repository for the rsyslog cookbook
https://supermarket.chef.io/cookbooks/rsyslog
Apache License 2.0
65 stars 199 forks source link

Feature Request - Order Matters #97

Open thenoid opened 8 years ago

thenoid commented 8 years ago

Like in most things, order matters within the rsyslog.conf - it would be swell if instead of a hash for the rsyslog.default_facility_logs and rsyslog.additional_directives it was an array of hashes, so that way line order could be easily specified.

{
  "rsyslog": {
    "default_facility_logs": [
      {
        "*.info": "/var/log/firstlog"
      },
      {
        "*.info": "~"
      },
      {
        "*.err": "/var/log/orderdoesntmatter1",
        "*.debug": "/var/log/orderdoesntmatter2"
      }
    ]
  }
}

Within each array, a simple sort would/should be applied to ensure random array storage doesn't cause the file to be needlessly regenerated. So the template would end up looking like

<% node['rsyslog']['default_facility_logs'].each do |lines| %>
<% lines.sort.each do |key, value| %>
<%= key %>    <%= value %>
<% end %>
<% end %>

This would grant people to slice, push, pop, etc entries the way they wanted.

The defaults could still be implemented as hash, just the first hash in the array

  default['rsyslog']['default_facility_logs'] = [{
    '*.info;mail.none;authpriv.none;cron.none' => "#{node['rsyslog']['default_log_dir']}/messages",
    'authpriv.*' => "#{node['rsyslog']['default_log_dir']}/secure",
    'mail.*' => "-#{node['rsyslog']['default_log_dir']}/maillog",
    'cron.*' => "#{node['rsyslog']['default_log_dir']}/cron",
    '*.emerg' => ':omusrmsg:*',
    'uucp,news.crit' => "#{node['rsyslog']['default_log_dir']}/spooler",
    'local7.*' => "#{node['rsyslog']['default_log_dir']}/boot.log"
  }]
thenoid commented 8 years ago

Could also easily implement backwards compatibility - detect if the current object is a hash, push it on to an array and save

treenerd commented 8 years ago

Same problem for me. Think it would be a great idea to use array of hashes. In my case I would like to use different entries than in the default attribute files. I didn't find a way to prevent a deep merge of the default attributes. So I had do create a "hotfix". I deleted the default default_facility_logs entries in the attributes file and create new entries in the environment. Nicer would be what @thenoid suggested. +1 from my side

eherot commented 8 years ago

I would also vote for this, especially because of the need to sometimes precede or disable one of the default facilities. E.g. I want to be able to send all local7 logs to a different destination without having them show up in /var/log/syslog but the current system makes that a bit clunky.