Syslog

From YobiWiki
Jump to: navigation, search

Contents

Syslog-ng

Install

apt-get install syslog-ng

Example of /etc/syslog-ng/syslog-ng.conf:

Comment kernel source out as we are in a vserver:

   source s_all {
       #file("/proc/kmsg" log_prefix("kernel: "));

I want to keep the original hostnames:

   options {
       keep_hostname(1);

Enable logging per remote host

source net { udp(ip(<local_ip_or_hostname>)); };

Add specific destination files to collect auth.log and syslog.log of every remote (and local) node:
Note that for some we add a template to replace the IP by the hostname in the msgs

destination df_zeus_auth      {   file("/var/log/remote/MAIN/auth.log"        owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };
destination df_zeus_syslog    {   file("/var/log/remote/MAIN/syslog.log"      owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };
destination df_zeus_kern      {   file("/var/log/remote/MAIN/kern.log"        owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };
destination df_mx_auth        {   file("/var/log/remote/mx/auth.log"          owner("root") group("adm") perm(0640)); };
destination df_mx_syslog      {   file("/var/log/remote/mx/syslog.log"        owner("root") group("adm") perm(0640)); };
destination df_public_auth    {   file("/var/log/remote/public/auth.log"      owner("root") group("adm") perm(0640) template("$DATE public $MESSAGE\n")); };
destination df_public_syslog  {   file("/var/log/remote/public/syslog.log"    owner("root") group("adm") perm(0640) template("$DATE public $MESSAGE\n")); };
destination df_private_auth   {   file("/var/log/remote/private/auth.log"     owner("root") group("adm") perm(0640) template("$DATE private $MESSAGE\n")); };
destination df_private_syslog {   file("/var/log/remote/private/syslog.log"   owner("root") group("adm") perm(0640) template("$DATE private $MESSAGE\n")); };
destination df_ns0_auth       {   file("/var/log/remote/ns0/auth.log"         owner("root") group("adm") perm(0640) template("$DATE ns0 $MESSAGE\n")); };
destination df_ns0_syslog     {   file("/var/log/remote/ns0/syslog.log"       owner("root") group("adm") perm(0640) template("$DATE ns0 $MESSAGE\n")); };
destination df_sql_auth       {   file("/var/log/remote/sql/auth.log"         owner("root") group("adm") perm(0640) template("$DATE sql $MESSAGE\n")); };
destination df_sql_syslog     {   file("/var/log/remote/sql/syslog.log"       owner("root") group("adm") perm(0640) template("$DATE sql $MESSAGE\n")); };
destination df_devel_auth     {   file("/var/log/remote/devel/auth.log"       owner("root") group("adm") perm(0640) template("$DATE devel $MESSAGE\n")); };
destination df_devel_syslog   {   file("/var/log/remote/devel/syslog.log"     owner("root") group("adm") perm(0640) template("$DATE devel $MESSAGE\n")); };
destination df_others_auth    {   file("/var/log/remote/$HOST/auth.log"       owner("root") group("adm") perm(0640)); };
destination df_others_syslog  {   file("/var/log/remote/$HOST/syslog.log"     owner("root") group("adm") perm(0640)); };
destination df_nf_ethr_in     {   file("/var/log/remote/MAIN/NF/ethr_in.log"  owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };
destination df_nf_ethr_out    {   file("/var/log/remote/MAIN/NF/ethr_out.log" owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };
destination df_nf_others      {   file("/var/log/remote/MAIN/NF/others.log"   owner("root") group("adm") perm(0640) template("$DATE MAIN $MESSAGE\n")); };

Add filters for remote nodes:
This is quite strange but msgs from the host are seen as coming from the IP of the collecting node
As the source will be net instead of s_all, we can still distinguish both from each other
Filters are sub-string regexps so we have to pay attention that IP x.x.x.1 can catch IP x.x.x.100 if not ended with a $

filter f_zeus    { host(192.168.x.x$); };
filter f_public  { host(192.168.x.x$); };
filter f_private { host(192.168.x.x$); };
filter f_ns0     { host(192.168.x.x$); };
filter f_devel   { host(192.168.x.x$); };
filter f_sql     { host(192.168.x.x$); };

For the host which gets the kernel logs, we add filters for the netfilter logs:

filter f_nf       { match("NF Dropped "); };
filter f_ethr_in  { match("ETH_R IN "); };
filter f_ethr_out { match("ETH_R OUT "); };

Then combine all those in log statements
They all contain the flag final so each entry will be captured only once, this avoids us to write negated filters and this should accelerate a bit the processing

log {
        source(net);
        filter(f_zeus);
        filter(f_auth);
        destination(df_zeus_auth);
        flags(final);
};
log {
        source(net);
        filter(f_zeus);
        filter(f_kern);
        filter(f_nf);
        filter(f_ethr_in);
        destination(df_nf_ethr_in);
        flags(final);
};
log {
        source(net);
        filter(f_zeus);
        filter(f_kern);
        filter(f_nf);
        filter(f_ethr_out);
        destination(df_nf_ethr_out);
        flags(final);
};
log {
        source(net);
        filter(f_zeus);
        filter(f_kern);
        filter(f_nf);
        destination(df_nf_others);
        flags(final);
};
log {
        source(net);
        filter(f_zeus);
        filter(f_kern);
        destination(df_zeus_kern);
        flags(final);
};
log {
        source(net);
        filter(f_zeus);
        filter(f_syslog);
        destination(df_zeus_syslog);
        flags(final);
};
# Don't forget ourselves:
log {
        source(s_all);
        filter(f_auth);
        destination(df_mx_auth);
};
log {
        source(s_all);
        filter(f_syslog);
        destination(df_mx_syslog);
};
# Other vservers:
log {
        source(net);
        filter(f_public);
        filter(f_auth);
        destination(df_public_auth);
        flags(final);
};
log {
        source(net);
        filter(f_public);
        filter(f_syslog);
        destination(df_public_syslog);
        flags(final);
};
log {
        source(net);
        filter(f_private);
        filter(f_auth);
        destination(df_private_auth);
        flags(final);
};
log {
        source(net);
        filter(f_private);
        filter(f_syslog);
        destination(df_private_syslog);
        flags(final);
};
log {
        source(net);
        filter(f_ns0);
        filter(f_auth);
        destination(df_ns0_auth);
        flags(final);
};
log {
        source(net);
        filter(f_ns0);
        filter(f_syslog);
        destination(df_ns0_syslog);
        flags(final);
};
log {
        source(net);
        filter(f_sql);
        filter(f_auth);
        destination(df_sql_auth);
        flags(final);
};
log {
        source(net);
        filter(f_sql);
        filter(f_syslog);
        destination(df_sql_syslog);
        flags(final);
};
log {
        source(net);
        filter(f_devel);
        filter(f_auth);
        destination(df_devel_auth);
        flags(final);
};
log {
        source(net);
        filter(f_devel);
        filter(f_syslog);
        destination(df_devel_syslog);
        flags(final);
};
# Catch other remote hosts:
log {
        source(net);
        filter(f_auth);
        destination(df_others_auth);
        flags(final);
};
log {
        source(net);
        filter(f_syslog);
        destination(df_others_syslog);
        flags(final);
};

Allow inbound connections from monitoring subnet

iptables -A INPUT -s xxxx -d xxxx -p udp --dport 514 -m state --state NEW -j ACCEPT

On satellite hosts: add to /etc/syslog.conf

*.*               @192.168.x.xxx

Resources & Credits


Logrotate

We add a file to rotate our new log files:

/etc/logrotate.d/local-syslog-ng:
/var/log/remote/*/*.log {
  rotate 28
  missingok
  notifempty
  daily
  compress
}

The call to syslog-ng reload will be done by the native /etc/logrotate.d/syslog-ng so we don't need to do it ourselves

Others

Check Logcheck and Php-Syslog-ng.

TODO

  • source IP of zeus seems to be 100, why?
  • fwlogwatch?
Personal tools
Namespaces

Variants
Actions
Navigation
Tools