Skip to content

Instantly share code, notes, and snippets.

@lichti
Last active October 7, 2023 14:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lichti/3c52f535ffaa49d865564fce26d268b3 to your computer and use it in GitHub Desktop.
Save lichti/3c52f535ffaa49d865564fce26d268b3 to your computer and use it in GitHub Desktop.
LogAlert.mikrotik.script
:global lastTimeLogingFailure;
:local varEmail "my@email.com";
:local varEmailSubj "failure login";
:local Hostname [/system identity get name];
:local filter "login failure";
:local varDate [/system clock get date];
:local varMonth [:pick $varDate 0 3];
:local varDay [:pick $varDate 4 6];
:local varYear [:pick $varDate 7 11];
:local varDateTime ([$varYear]."-".[$varMonth]."-".[$varDay]."-".[/system clock get time]);
:local currentBuf [ :toarray [ /log find message~[$filter] ] ] ;
:local currentLineCount [ :len $currentBuf ] ;
:local currentTime [ :totime [/log get [ :pick $currentBuf ($currentLineCount -1) ] time ] ];
:local message "";
:local subject ([/system identity get name] . " - " . [$varEmailSubj] . " - " . [$varDateTime]);
:local body [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
:if ( $lastTimeLogingFailure = "" ) do={
:set lastTimeLogingFailure $currentTime ;
/tool e-mail send to=[$varEmail] subject=[$subject] body=[$body];
} else={
:if ( $lastTimeLogingFailure != $currentTime ) do={
:set lastTimeLogingFailure $currentTime;
/tool e-mail send to=[$varEmail] subject=[$subject] body=[$body];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment