LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-17-2014, 10:45 AM   #1
grodech
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 0
rsyslog - separating logs


I have my Ubuntu (12.04) workstation set up to recieve syslog messages from other devices. I was trying to get the rsyslog to generate separate log files for the other devices based on hostname, but leave it's own internal logs as is. What's happening at this point is that all the syslog entries are going into the default systlog log file as well as going into the individual host-based log files.

In the rsyslog.conf file, I added the following template:

Quote:
###########################
#### GLOBAL DIRECTIVES ####
###########################

# Template to generate the log file name dynamically
$template FILENAME,"/var/log/homeagent/%HOSTNAME%.syslog.log"
*.* ?FILENAME
It kind of works, but it's generating a new file even for the localhost, and it's still putting everything in the /var/log/syslog file. What am I missing to get it to not log the other hosts in /var/log/syslog?
 
Old 01-18-2014, 01:41 AM   #2
RootMason
Member
 
Registered: Oct 2012
Location: Tucson, AZ
Distribution: Debian/CentOS
Posts: 124

Rep: Reputation: 5
Does this help at all? It certainly isn't much like your specific scenario, but perhaps the use of the if statements will work.

Storing Messages from a Remote System into a Specific File

This is a log-consolidation scenario. There exists at least two systems, a server and at least one client. The server is meant to gather log data from all the clients. Clients may (or may not) process and store messages locally. If they do, it doesn’t matter here. See recipe Sending Messages to a Remote Syslog Server for how to configure the clients.

Messages from remote hosts in the 192.0.1.x network shall be written to one file and messages from remote hosts in the 192.0.2.x network shallbe written to another file.
Things to think about

TCP recpetion is not a build-in capability. You need to load the imtcp plugin in order to enable it. This needs to be done only once in rsyslog.conf. Do it right at the top.

Note that the server port address specified in $InputTCPServerRun must match the port address that the clients send messages to.
Config Statements

$ModLoad imtcp
$InputTCPServerRun 10514
# do this in FRONT of the local/regular rules
if $fromhost-ip startswith '192.0.1.' then /var/log/network1.log
& ~
if $fromhost-ip startswith '192.0.2.' then /var/log/network2.log
& ~
# local/regular rules, like
*.* /var/log/syslog.log

How it works

It is important that the rules processing the remote messages come before any rules to process local messages. The if’s above check if a message originates on the network in question and, if so, writes them to the appropriate log. The next line ("& ~") is important: it tells rsyslog to stop processing the message after it was written to the log. As such, these messages will not reach the local part. Without that "& ~", messages would also be written to the local files.

Also note that in the filter there is a dot after the last number in the IP address. This is important to get reliable filters. For example, both of the addresses "192.0.1.1″ and "192.0.10.1″ start with "192.0.1″ but only one actually starts with "192.0.1."!
 
Old 01-20-2014, 09:59 AM   #3
grodech
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
I had seen that post in my searches, along with others, and it did help somewhat, though as you said it is not the same as my situation. While I could set it up to search for specific things as this post says, I would have to change the rsyslog.conf file every time an IP address was added or changed. Utilizing the %hostname% helps with that.

I noticed that the example includes "& ~" after each line. What does that do?
 
Old 01-20-2014, 11:56 AM   #4
grodech
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grodech View Post
I had seen that post in my searches, along with others, and it did help somewhat, though as you said it is not the same as my situation. While I could set it up to search for specific things as this post says, I would have to change the rsyslog.conf file every time an IP address was added or changed. Utilizing the %hostname% helps with that.

I noticed that the example includes "& ~" after each line. What does that do?
Ok - after a thorough reading, the & ~ is supposed to stop processing the message. I've changed my rsyslog.conf to be as follows:
Quote:
# Template to generate the log file name dynamically
$template FILENAME,"/var/log/homeagent/%HOSTNAME%.log"
if $fromhost-ip startswith '172.16' then ?FILENAME
& ~
#
This seems to work better. I don't get a separate file for the local workstation, however the other devices still appear in the local syslog file as well as in the individual logs. It almost seems like the messages keep processing even though I have the & ~ in there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
logs to remote rsyslog sunlinux Linux - Server 2 12-10-2013 09:05 AM
[SOLVED] Rsyslog server cant log logs owned by root nico34 Linux - Server 2 03-19-2012 05:46 AM
How can I define how old logs should rsyslog keep? craseal Linux - Server 1 08-25-2010 08:38 PM
Separating WPA logs from /var/log/messages using syslog-ng lp449 Linux - Newbie 1 06-04-2008 06:12 AM
rsyslog sometimes logs fqdn, sometimes just host name whysyn Linux - Software 3 06-03-2008 10:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration