Can someone help me with a script
I wan’t to know how to create a script when a user login via winbox, ftp, ssh, telnet or api. To email the login time, date, user, from ip and if it is via winbox or so to a
certain email address. And even if a user tried to login and failed by putting an incorrect username or password.
What you can do is to schedule a script to search the system logs (at “/log”) at regular intervals. Login attempts are written there.
At every interval, check for entries newer than the last time the script was executed, collect them into a string that you’ll then send with “/tool e-mail send”. To keep track of when the script was executed, you could use a global variable that you’ll modify at the end of the script.
I have tried the script but no luck. It did work once but the body of the email was empty. then I started over and paste it in the script again and now I don’t even recieved any emails.
I can sent out test emails and daily backups out of my router so my email settings are correct.
Script to check for specific new logs and send email alerts
Tested on RouterOS v5.7+
container to keep track of the last time stamp detected
:global lastTime;
find log entries where the message contains “logged in” or “login failure”
One more question. I run a PPPOE server on my Mikrotik, but every time a user autenticates via PPPOE i ge a email for that as well how can i void this?
To exclude some log entries, replace this line of the original script:
:local currentBuf [ :toarray [ /log find message~“logged in” || message~“login failure” ] ] ;With this:
:local removeThese {“PPPoE”;“any strings you want”}
:foreach i in=$tempBuf do={
:local toggle 1
:foreach j in=$removeThese do={
:if ([:typeof [:find [/log get $i message] “$j”]] = “num”) do={
:set toggle 0
}
}
:if ($toggle = 1) do={
:set currentBuf ( $currentBuf , $i)
}
}This will search through all the “logged in” and “login failure” logs that have been found and exclude any that contain the strings found in the removeThese array.