Community discussions

MikroTik App
 
igpetkov
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Thu Oct 09, 2014 10:27 pm

logging of a lost connection

Sat May 09, 2015 10:04 pm

Hello everyone!
I have a problem with my ISP. Sometimes my router lost connection to my ISP and establish connection later. I want to create log file about these periods. Is this possible, maybe netwatch, but do not know how to create file automaticly, save the file on hard drive (router memory) to download later and how much resourses does it take? My router is RB 2011 UiAS-RM

I hope someone can help me,thank you
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 1906
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: logging of a lost connection

Sat May 09, 2015 10:54 pm

I am checking VPN tunnels with
:local TargetServer192   "192.168.1.17"
:local komunikat ""

:local i 0
:local Missed192 0
:local VPNChanged
:global VPNUp

#:log info ("CHECK_VPN: >> <<")
:if ([:typeof $VPNUp] = "nothing") do={:set VPNUp false}

{
  :for i from=1 to=4 do={
#   :log info ("CHECK_VPN: ping $TargetServer192")
    if ([/ping $TargetServer192 count=1 interval=1s]=0) do={:set Missed192 ($Missed192 + 1)}
  };
# Max 2 missed from 4 means that  VPN works, 4 missed means that VPN is down
#  :log info ("CHECK_VPN: Missed192 $Missed192")
  :set VPNChanged (($VPNUp and ($Missed192=4)) or (!$VPNUp and ($Missed192<3)))
#  :log info ("CHECK_VPN: $VPNChanged $VPNUp and $Missed192")
  :set VPNUp ($Missed192<3)
#  :log info ("CHECK_VPN: $VPNChanged $VPNUp and $Missed192")
  :if ($VPNChanged) do={
    :set komunikat "VPN: $[/system identity get name], $[/system clock get time], $[/system clock get date], $[/ip address get [find interface=ETH1-WAN] address] - "
    :if ( $VPNUp ) do={
      :set komunikat ($komunikat . "UP")
    } else={
      :set komunikat ($komunikat . "DOWN")
    }
    :log info $komunikat
    /tool e-mail send to=youremailhere subject=$komunikat;
  } else={
#    :log info ("CHECK_VPN: VPNChanged $VPNChanged")
  }
}
Info about up/down is logged to log and send to my e-mail.
Remeber to configure Tools/E-mail to use "/tool e-mail send" form.

This code should be saved as script in System/Script and the the name of this script should be used as action in sheduled event in System/Sheduler.
If you want to append "komunikat" to afile the look here: http://forum.mikrotik.com/viewtopic.php?t=66605#p343718
Real admins use real keyboards.
To quote or not to quote, there is the topic: viewtopic.php?f=2&t=168474
 
Dreidor
just joined
Posts: 1
Joined: Thu Jun 23, 2016 6:12 pm

Re: logging of a lost connection

Thu Jun 23, 2016 6:21 pm

I am checking VPN tunnels with
:local TargetServer192   "192.168.1.17"
:local komunikat ""

:local i 0
:local Missed192 0
:local VPNChanged
:global VPNUp

#:log info ("CHECK_VPN: >> <<")
:if ([:typeof $VPNUp] = "nothing") do={:set VPNUp false}

{
  :for i from=1 to=4 do={
#   :log info ("CHECK_VPN: ping $TargetServer192")
    if ([/ping $TargetServer192 count=1 interval=1s]=0) do={:set Missed192 ($Missed192 + 1)}
  };
# Max 2 missed from 4 means that  VPN works, 4 missed means that VPN is down
#  :log info ("CHECK_VPN: Missed192 $Missed192")
  :set VPNChanged (($VPNUp and ($Missed192=4)) or (!$VPNUp and ($Missed192<3)))
#  :log info ("CHECK_VPN: $VPNChanged $VPNUp and $Missed192")
  :set VPNUp ($Missed192<3)
#  :log info ("CHECK_VPN: $VPNChanged $VPNUp and $Missed192")
  :if ($VPNChanged) do={
    :set komunikat "VPN: $[/system identity get name], $[/system clock get time], $[/system clock get date], $[/ip address get [find interface=ETH1-WAN] address] - "
    :if ( $VPNUp ) do={
      :set komunikat ($komunikat . "UP")
    } else={
      :set komunikat ($komunikat . "DOWN")
    }
    :log info $komunikat
    /tool e-mail send to=youremailhere subject=$komunikat;
  } else={
#    :log info ("CHECK_VPN: VPNChanged $VPNChanged")
  }
}
Info about up/down is logged to log and send to my e-mail.
Remeber to configure Tools/E-mail to use "/tool e-mail send" form.

This code should be saved as script in System/Script and the the name of this script should be used as action in sheduled event in System/Sheduler.
If you want to append "komunikat" to afile the look here: http://forum.mikrotik.com/viewtopic.php?t=66605#p343718
Hello BartoszP,
i'm new to RouterOS; i'm trying your script and it's very well done.
Is there anyway to make it loop through all the IPSEC vpn we have, customizing every mail?
Like a for loop i mean.
Thanks in advance!

Who is online

Users browsing this forum: mikon, mkx, niyaza93, Traveler382 and 46 guests