On 2018-02-03 15:49, Scott Weeks wrote:
Then, you can watch your network in real time
like so (below is all one line):

tail -f /var/log/router.log /var/log/switch.log
| egrep -vi 'term1|term2|termN'

'egrep -v' takes out all the lines you don't
want to see while the syslog messages scroll
across the screen.

Syslog-ng can do regex filtering on messages also. So instead of doing an 'egrep -v' on a huge file after it has been logged, you can put your filter right into the syslog-ng configuration, and have those filtered messages output to a file (or any other output that syslog-ng supports). The result is a smaller file to search and work with.

We implemented a simple email alerter using this functionality. In syslog-ng, we set up two filters. One filter does the 'egrep -v':

filter f_email_msg {
not message("%PKT_INFRA-LINEPROTO-.*[0-9/]+\\.") # filter out subinterface up/downs
        and not message("%PKT_INFRA-LINEPROTO-.*Multilink")
        and not message("%PKT_INFRA-LINEPROTO-.*Serial")
        and not message("%PKT_INFRA-LINEPROTO-.*Tunnel")
        # etc

Another filter applied to the messages filters messages to just our core devices:

filter f_email_sources {
        or host("")
        or host("")
        or host("")
        or host("")
        or host("")

Then those are tied together in a syslog-ng rule that outputs to a file:

destination d_email_log {
log { source(s_devices); filter(f_email_sources); filter(f_email_msg); destination(d_email_log); };

A lightweight Python script that runs as a daemon checks that file once every 10 seconds, and if the file length is non-zero, it sends the contents of the file in an email to the admins. A shell script run as a cron job would work equally as well.

(Also, for emailed syslogs, there is more incentive for the admin to keep her or his message filter up to date, as opposed to a file the administrator must manually examine. Otherwise the admin has a full inbox :) )

It's very simple and stable, and has worked better than the commercial product we used to use for this purpose.


Reply via email to