logging of a lost connection

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/t/print-in-file-on-specific-interfval-help/60558/1