Community discussions

MikroTik App
 
User avatar
baragoon
Member
Member
Topic Author
Posts: 325
Joined: Thu Jan 05, 2017 10:38 am
Location: Kyiv, UA
Contact:

log entry and action when occurs

Tue May 07, 2024 6:28 pm

Dear scripting gurus, I would like to ask you for help.
Please help me with a simple script, which will monitor /log for one exact message - "FCC: Attemtped to send a frame with no bonded connections established" and if this message appears in the log - restart container.
There is no problem with container restart (somethiing like /container stop [find where interface=veth-xxx], :delay, then /container start [find where interface=veth-xxx]), but I can't understand how to monitor log for this specific entry and then run a desired action.
Thank you in advance.
 
jaclaz
Forum Veteran
Forum Veteran
Posts: 810
Joined: Tue Oct 03, 2023 4:21 pm

Re: log entry and action when occurs

Tue May 07, 2024 7:46 pm

Something like:
viewtopic.php?t=175246
might be of inspiration, but I believe the issue is that you must clear the log (setting its lines to 1 and then back to the "normal" number of lines, *like* in this (old) script):
https://web.archive.org/web/20210416175 ... ger_Script
every time, and this might be inconvenient/not wanted.
 
User avatar
baragoon
Member
Member
Topic Author
Posts: 325
Joined: Thu Jan 05, 2017 10:38 am
Location: Kyiv, UA
Contact:

Re: log entry and action when occurs

Tue May 07, 2024 8:26 pm

Thanks @jaclaz, reading and trying more and more 😀
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12050
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log entry and action when occurs  [SOLVED]

Wed May 08, 2024 7:11 pm

search better on forum, some of my script do not catch twice the same log, only new added log.....


viewtopic.php?p=1051243#p1051243

example code

:global lastLog
:if ([:typeof $lastLog] != "num") do={:set lastLog 0}

{
:local id2num do={:return [:tonum "0x$[:pick $1 1 [:len $1]]"]}

/log
:foreach item in=[find where (([$id2num $".id"] > $lastLog) and (message="FCC: Attemtped to send a frame with no bonded connections established"))] do={
    :set lastLog [$id2num $item]
    # do something here..................
}

}
 
User avatar
baragoon
Member
Member
Topic Author
Posts: 325
Joined: Thu Jan 05, 2017 10:38 am
Location: Kyiv, UA
Contact:

Re: log entry and action when occurs

Wed May 08, 2024 9:57 pm

Thank you, @rextended, works like a charm!

Who is online

Users browsing this forum: No registered users and 17 guests