Community discussions

MikroTik App
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

How to make MikroTik beep if there's error on logs

Fri Dec 19, 2014 7:12 am

Like this:

Image

How to make MikroTik beep?

Is it possible to trigger event like error then make it beep somehow?

Any idea would be appreciated.

Thank you.
[ IMikroTik ] >
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24608
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: How to make MikroTik beep if there's error on logs

Fri Dec 19, 2014 10:56 am

You can use same approach as here: http://forum.mikrotik.com/viewtopic.php?f=2&t=60616
No answer to your question? How to write posts
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

Re: How to make MikroTik beep if there's error on logs

Fri Dec 19, 2014 4:50 pm

wow, it's too complex.

how to make it even simpler, like just to beep when someone failed logging in, so it will notify our on-spot technician.
[ IMikroTik ] >
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: How to make MikroTik beep if there's error on logs

Fri Dec 19, 2014 6:23 pm

how to make it even simpler, like just to beep when someone failed logging in, so it will notify our on-spot technician.
You can use same approach as here: http://forum.mikrotik.com/viewtopic.php?f=2&t=60616
That script was created to do what you're looking for. Latest version is here: http://forum.mikrotik.com/viewtopic.php ... 16#p460810. There are only a few minor changes you would have to make.

First, copy/paste the script into a new Schedule. Edit the SETUP block at the top. Change the scheduleName to match the name of your schedule. You can delete the email address line. Change the next line to find only logs that contain the words "login failure", and assuming you don't want to filter out any logs, just declare the removeThese array without any value. Like this:
# BEGIN SETUP
:local scheduleName "mySchedule"
:local startBuf [:toarray [/log find message~"login failure"]]
:local removeThese
# END SETUP
Then, at the bottom of the script, change the "/tool e-mail send ..." line to:
:beep
Set the schedule interval to run as frequently as you want to check for new logs.
I don't need any karma... I have Ιησους Χριστος!
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

Re: How to make MikroTik beep if there's error on logs

Sat Dec 20, 2014 3:32 am

Hi skot,

Thank you for your reply,

I'm impressed with your script.

I set up like this but still couldn't get my router beep on login failures:
# BEGIN SETUP
:local scheduleName "login-failures"
:local startBuf [:toarray [/log find message~"login failure"]]
:local removeThese
# END SETUP

    # warn if schedule does not exist
    :if ([:len [/system scheduler find name="$scheduleName"]] = 0) do={
      /log warning "[LOGMON] ERROR: Schedule does not exist. Create schedule and edit script to match name"
    }

    # get last time
    :local lastTime [/system scheduler get [find name="$scheduleName"] comment]
    # for checking time of each log entry
    :local currentTime
    # log message
    :local message
     
    # final output
    :local output

    :local keepOutput false
    # if lastTime is empty, set keepOutput to true
    :if ([:len $lastTime] = 0) do={
      :set keepOutput true
    }


    :local counter 0
    # loop through all log entries that have been found
    :foreach i in=$startBuf do={
     
    # loop through all removeThese array items
      :local keepLog true
      :foreach j in=$removeThese do={
    #   if this log entry contains any of them, it will be ignored
        :if ([/log get $i message] ~ "$j") do={
          :set keepLog false
        }
      }
      :if ($keepLog = true) do={
       
       :set message [/log get $i message]

    #   LOG DATE
    #   depending on log date/time, the format may be different. 3 known formats
    #   format of jan/01/2002 00:00:00 which shows up at unknown date/time. Using as default
        :set currentTime [ /log get $i time ]
    #   format of 00:00:00 which shows up on current day's logs
       :if ([:len $currentTime] = 8 ) do={
         :set currentTime ([:pick [/system clock get date] 0 11]." ".$currentTime)
        } else={
    #     format of jan/01 00:00:00 which shows up on previous day's logs
         :if ([:len $currentTime] = 15 ) do={
            :set currentTime ([:pick $currentTime 0 6]."/".[:pick [/system clock get date] 7 11]." ".[:pick $currentTime 7 15])
          }
       }
        
    #   if keepOutput is true, add this log entry to output
       :if ($keepOutput = true) do={
         :set output ($output.$currentTime." ".$message."\r\n")
       }
    #   if currentTime = lastTime, set keepOutput so any further logs found will be added to output
    #   reset output in the case we have multiple identical date/time entries in a row as the last matching logs
    #   otherwise, it would stop at the first found matching log, thus all following logs would be output
        :if ($currentTime = $lastTime) do={
         :set keepOutput true
         :set output ""
       }
      }

    #   if this is last log entry
      :if ($counter = ([:len $startBuf]-1)) do={
    #   If keepOutput is still false after loop, this means lastTime has a value, but a matching currentTime was never found.
    #   This can happen if 1) The router was rebooted and matching logs stored in memory were wiped, or 2) An item is added
    #   to the removeThese array that then ignores the last log that determined the lastTime variable.
    #   This resets the comment to nothing. The next run will be like the first time, and you will get all matching logs
       :if ($keepOutput = false) do={
    #     if previous log was found, this will be our new lastTime entry      
         :if ([:len $message] > 0) do={
            :set output ($output.$currentTime." ".$message."\r\n")
          }
        }
      }
      :set counter ($counter + 1)
    }

    # If we have output, save new date/time, and send email
    if ([:len $output] > 0) do={
      /system scheduler set [find name="$scheduleName"] comment=$currentTime
      :beep
      /log info "[LOGMON] New logs found, beeping"
    }
Any clue what's wrong am I doing?

Image
[ IMikroTik ] >
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: How to make MikroTik beep if there's error on logs

Mon Dec 22, 2014 6:18 pm

You need to tell the schedule how often to run in the Interval field. Like 00:01:00 would be running once every minute. Also, I think you need to have the write policy enabled on the schedule.
I don't need any karma... I have Ιησους Χριστος!

Who is online

Users browsing this forum: No registered users and 14 guests