Jump to content

Темплейт за rsyslog


Асен Нейков
 Share

Recommended Posts

Здравейте,

   Инсталирах rsyslog, за да логвам информацията от един линк. Имам две устройства, които трябва да следя- Rocket M5 и след него Rocket M2, свързани са един с друг с пач сабел. И двата са в рутер мод с включен нат, a вторият е с dhcp сървър.   В тази схема и двете устройства изпращат от едно и също ip и съответно пишат в един лог файл. Какъв е начина да накарам syslog server-a да пише информацията в два различни файла за всяко устройство по отделно?  Разбрах, че това се прави с темплейтите, но не мога да го измисля. Ето това е съдържанието на rsyslog.conf: 

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#                       For more information see
#                       /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog   # provides kernel logging support
#$ModLoad immark  # provides --MARK-- message capability

# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514

# Enable non-kernel facility klog messages
$KLogPermitNonKernelFacility on

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

######################
        RULES
######################
mail.info       /var/log/mail.info
mail.warn       /var/log/mail.warn
mail.err        /var/log/mail.err
daemon.*        /var/log/daemon.log

# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template FILENAME,"/var/log/%hostname%/%HOSTNAME%.log"

# Log all messages to the dynamically formed file. Now each clients log (192.168.1.2, 192.168.1.3,etc...), will be under a separate directory which is formed by the template FILENAME.
*.* ?FILENAME

 Благодаря Ви предварително за отделеното време.

Edited by Асен Нейков
Link to comment
Share on other sites

if $fromhost-ip == '1.1.1.1' then /var/log/1.log
& ~
if $fromhost-ip == '2.2.2.2' then /var/log/2.log
& ~

и т.н.

или

if $msg contains 'host1' then /var/log/somelog

& ~

Edited by h3ll
Link to comment
Share on other sites

Благодаря за бързия отговор, но и двете устройства стоят зад едно ip и се очертава да закача още 5-6 устройства в скоро време на същото Ip.  Мислех дали няма да стане да пусна втори listener на друг порт и така за всяко отделно устройство, но не мога да измисля конфигурацията на файла.

Link to comment
Share on other sites

След няколко часа на проби и грешки открих правилната конфигурация с RuleSet и отделен порт за всяко устройство:

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#                       For more information see
#                       /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog   # provides kernel logging support
#$ModLoad immark  # provides --MARK-- message capability

# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
#$UDPServerRun 515
# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
$InputTCPServerRun 515

# Enable non-kernel facility klog messages
$KLogPermitNonKernelFacility on

###########################
#### GLOBAL DIRECTIVES ####
###########################



#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

######################
#       RULES        #
######################
mail.info       /var/log/mail.info
mail.warn       /var/log/mail.warn
mail.err        /var/log/mail.err
daemon.*        /var/log/daemon.log

########################
#      RULESETS        #
########################

$RuleSet RocketM5
*.* /var/log/********/RocketM5


$RuleSet RocketM2
*.* /var/log/********/RocketM2


$InputTCPServerBindRuleset RocketM5
$InputTCPServerRun 514


$InputTCPServerBindRuleset RocketM2
$InputTCPServerRun 515

 

Edited by Асен Нейков
Link to comment
Share on other sites

И за какво усложни конфигурацията? Сега си сменял портове на всяко у-во, правил си рулсетове, вместо само да сортираш по "hostname".

Link to comment
Share on other sites

На две места писах каква е причината. Едниния рокет е зад нат-а на другия и двете стоят зад едно IP. Първо бях активирал този темплейт, но тъй като идват от едто ip се пише в един файл.

# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template FILENAME,"/var/log/%hostname%/%HOSTNAME%.log"

# Log all messages to the dynamically formed file. Now each clients log (192.168.1.2, 192.168.1.3,etc...), will be under a separate directory which is formed by the template FILENAME.
*.* ?FILENAME

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.