Hello,
I have found a script to send me mail if there’s any failure login. May I get your expertise comment how to get a entire log (not just login failure) and send email to me daily?
Here below is the script that to send me log for failure login only:
:local scheduleName “Email_log_file_2”
:local emailAddress “mymail@mymail.com”
:local startBuf [:toarray [/log find message~“logged in” || message~“login failure”]]
:local removeThese (“”)
:local lastTime [/system scheduler get [find name=“$scheduleName”] comment]
:local currentBuf “”; :set currentBuf [:toarray $currentBuf]
:foreach i in=$startBuf do={
:local toggle 1
:foreach j in=[:toarray $removeThese] do={
:if ([:typeof [:find [/log get $i message] “$j”]] = “num”) do={
:set toggle 0
}
}
:if ($toggle = 1) do={
:set currentBuf ($currentBuf , $i)
}
}
:local currentLineCount [ :len $currentBuf ]
if ($currentLineCount > 0) do={
:local currentTime “$[ /log get [ :pick $currentBuf ($currentLineCount -1) ] time ]”
:if ([:len $currentTime] = 15 ) do={
:set currentTime [ :pick $currentTime 7 15 ]
}
:local output “$currentTime $[/log get [ :pick $currentBuf ($currentLineCount-1) ] message ]”
:if (([:len $lastTime] < 1) || (([:len $lastTime] > 0) && ($lastTime != $currentTime))) do={
/system scheduler set [find name=“$scheduleName”] comment=$currentTime
/tool e-mail send to=“$emailAddress” subject=“MikroTik alert $currentTime” body=“$output”
}
}
Thank you.