Project

General

Profile

Using Syslog with Foreman » History » Version 3

Johan Sunnerstig, 08/12/2014 04:25 AM

1 1 Johan Sunnerstig
h1. Using Syslog with Foreman
2
3
Foreman does not natively support syslog, but you can use the 'imfile' module for Rsyslog to forward the production log from the Foreman server to your centralized log server.
4
If you're running Debian or RHEL >= 6 you already have Rsyslog and imfile so you're good to go.
5
6
Begin by configuring Rsyslog, either add the snippet below straight to rsyslog.conf or make sure rsyslog.conf has a statement like this: '$IncludeConfig /etc/rsyslog.d/*.conf' and add the snippet to f.ex '/etc/rsyslog.d/foreman.conf'.
7
<pre>
8
$ModLoad imfile
9
$InputFileName /var/log/foreman/production.log
10
$InputFileTag foreman
11
$InputFileStateFile rsyslog-foreman-state
12
$InputFileSeverity info
13
$InputFileFacility local1
14
$InputRunFileMonitor
15 3 Johan Sunnerstig
local1.info @your.syslog.server
16 1 Johan Sunnerstig
</pre>
17
Change the specifics according to your needs. One @-symbol before the server name signifies a UDP transport and two @-symbols means TCP transport.
18
19
You're now nearly ready to go, when you restart rsyslog it will begin tracking the production.log and forwarding it to your syslog server, however you will need to configure logrotate as well.
20
Edit the file '/etc/logrotate.d/foreman' and add a post-rotate statement like so:
21
<pre>
22
# Foreman logs:
23
/var/log/foreman/*.log {
24
  daily
25
  missingok
26
  rotate 14
27
  compress
28
  delaycompress
29
  notifempty
30
  copytruncate
31 2 Johan Sunnerstig
  # The post-rotate statment begins on the line below...
32
  post-rotate 
33 1 Johan Sunnerstig
    service rsyslog stop
34
    rm /var/spool/rsyslog/rsyslog-foreman-state
35
    service rsyslog start
36 2 Johan Sunnerstig
  endscript
37
  # ...and end here.
38 1 Johan Sunnerstig
}
39
</pre>
40
This is due to the 'copytruncate' statement, this causes logrotate to do pretty much what it says, copy the log file and then truncate it in place, which means rsyslog will not notice the rotation since the inode number doesn't change, thus you will lose the forwarding as soon as a rotation takes place.
41
42
You should be all set by now.