:if ([:len [/user active find]] > 0) do {
:local tmpMessage value="";
:foreach tmpArrayItem in [/user active find] do {
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n");
};
:log info message=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage);
};
:log info message=("Start Check Logged Users");
:local tmpAllTheUsersLogged value=[/user active find];
:if ([:len $tmpAllTheUsersLogged] > 0) do={
:local tmpMessage value="";
:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n");
};
:set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage);
:if ($cluEmailSent != "true") do={
:log info message=$tmpMessage;
/tool e-mail send from="clu.script@routerboard.local" to="your@mail.it" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage;
:global cluEmailSent value="true";
};
} else={
:global cluEmailSent value="false";
};
:log info message=("Check Logged Users End");
:global cluEmailSent value="false";
Hmmm... wait two mins....@ rextended. Can you make a script if someone TRY to login on the routerboard?
:put [/log find where message~"login failure"]
Have you find one personal assistant?Thanks, can you give me the fully script to email please
:log info message=("Start Check Failed Login");
:local currentLoginFailureArray value=[/log find where message~"login failure"];
:if ($currentLoginFailureArray != $previosLoginFailureArray) do={
:local tmpMessage value="";
:foreach tmpArrayItem in=$currentLoginFailureArray do={
:set $tmpMessage value=($tmpMessage.[/log get value-name=time $tmpArrayItem]." ".[/log get value-name=topic $tmpArrayItem]." ".[/log get value-name=message $tmpArrayItem]."\r\n");
};
:set $tmpMessage value=("Login Failure(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage);
:log info message=$tmpMessage;
/tool e-mail send from="clu.script@routerboard.local" to="your@mail.it" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage;
:global previosLoginFailureArray value=$currentLoginFailureArray;
};
:log info message=("Check Failed Login End");
:global previosLoginFailureArray value=[/log find where message~"login failure"];
this works for succefull login. i want to be emailed for failure login!I use the logging function to email when a user logs into the routerboard.
Setup email, in the tools menu, the under logging create a new action, type email.
Then, add a new logging rule.
Topic: Account, Action 'Your new emailing action'
Now try logging in from winbox and you should receive an email.
I made the script for you....
Schedule that script every appropriate time, like 10 seconds?
Syntax is for RouterOS 6.7+
(Notice: a blank line on log after all log entry are normal, because \r\n at the end of each line)Code: Select all:log info message=("Start Check Failed Login"); :local currentLoginFailureArray value=[/log find where message~"login failure"]; :if ($currentLoginFailureArray != $previosLoginFailureArray) do={ :local tmpMessage value=""; :foreach tmpArrayItem in=$currentLoginFailureArray do={ :set $tmpMessage value=($tmpMessage.[/log get value-name=time $tmpArrayItem]." ".[/log get value-name=topic $tmpArrayItem]." ".[/log get value-name=message $tmpArrayItem]."\r\n"); }; :set $tmpMessage value=("Login Failure(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage); :log info message=$tmpMessage; /tool e-mail send from="clu.script@routerboard.local" to="your@mail.it" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage; :global previosLoginFailureArray value=$currentLoginFailureArray; }; :log info message=("Check Failed Login End");
You also must schedule this at startup of routerboard:Code: Select all:global previosLoginFailureArray value=[/log find where message~"login failure"];
Mmm.. look familiar...
Also working fine, but there is no body and subjectthanx i just did it. i just have to select in topics "critical" and put to prefix "login failure".
very nice without script!
Hi plisken.I Delete :global cluEmailSent value="false"; in the script and everything looks fine to me.
I only get 1 email
Greatings
:log info message=("Start Check Logged Users");
:local tmpAllTheUsersLogged value=[/user active find];
:if ([:len $tmpAllTheUsersLogged] > 0) do={
:local tmpMessage value="";
:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n");
};
:set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage);
:if ($cluEmailSent != "true") do={
:log info message=$tmpMessage;
/tool e-mail send from="youreemail@test.com" to="youremail@test.com" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage;
:global cluEmailSent value="true";
};
} else={
:global cluEmailSent value="false";
};
:log info message=("Check Logged Users End");
:log info message=("Start Check Logged Users")
:local tmpAllTheUsersLogged value=[/user active find]
:if ([:len $tmpAllTheUsersLogged] > 0) do={
:local tmpMessage value=""
:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n")
}
:set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage)
:if ($cluEmailSent != "true") do={
:log info message=$tmpMessage
/tool e-mail send from="youreemail@test.com" to="youremail@test.com" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage
:global cluEmailSent value="true"
}
} else={
:global cluEmailSent value="false"
}
:log info message=("Check Logged Users End")
This is the working script, but don't forget to setup the email settings in "tools" "email".
Code: Select all:log info message=("Start Check Logged Users"); :local tmpAllTheUsersLogged value=[/user active find]; :if ([:len $tmpAllTheUsersLogged] > 0) do={ :local tmpMessage value=""; :foreach tmpArrayItem in=$tmpAllTheUsersLogged do={ :set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n"); }; :set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage); :if ($cluEmailSent != "true") do={ :log info message=$tmpMessage; /tool e-mail send from="youreemail@test.com" to="youremail@test.com" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage; :global cluEmailSent value="true"; }; } else={ :global cluEmailSent value="false"; }; :log info message=("Check Logged Users End");