MikroTik Script: Authentication Logging w/ Email Reports

MikroTik Script: Authentication Logging w/ Email Reports

In this article I will show you how to configure a separate log file on a MikroTik router that will only contain authentication log entries.  The log file will contain log entries for winbox, webfig, ssh, telnet, ftp as well as VPN user authentications.  Additionally,  we will configure a scheduled script to email this log file to ourselves daily.

Configure Authentication Logging to a dedicated log file

What we have done here is defined a new logging action named auth that logs to a file on disk named auth.log. In my example the log file will retain the last 5000 entries. The second line tells the MikroTik router to write any new logs with the topic account to the auth.log file.

If you are using winbox here is what the configuration screens look like.

winbox-screenshot

winbox-screenshot

Before we get to the email configuration and script I want to point out that you can now easily filter and view authentication logs from within winbox.  Just open the log viewer and choose auth from the dropdown.

winbox-screenshot

You can also print the auth log from the cli using the following command.

Email Configuration

Before we can send email from the MikroTik router we must configure a valid email server in Tools | Email. Here is an example, of course you will have to workout your own authentication credentials.

The Script

I have chosen to create a dedicated script and separate schedule that executes the script. I could also just paste the script right into the schedule itself. I like the separated approach because you can run the script on demand from winbox using the Run Script button.

The Schedule

The schedule that I have configured emails the auth.log file as attachment everyday at 9:40AM. Here are the equivalent winbox screenshots.

winbox-screenshot

winbox-screenshot

winbox-screenshot


Example Authentication Log Entries

I hope you find this technique useful in monitoring and managing your MikroTik devices. Feel free to leave a comment below or checkout my other MikroTik Tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *