System Time Variable

I’m creating a script to monitor if the internet is up or down. When the internet is back up from being down, I have an email sent. In the email, I want to include the time the internet went down. Is there a way to set a variable to the time the internet goes down so I can use it in the up email?

Check this:

:local komunikat "INTERNET: $[/system identity get name], $[/system clock get time], $[/system clock get date], $[/ip address get [find interface=ETH1-WAN] address] - PUBLIC PING UP";
/tool e-mail send to=address@somewhere.org subject=$komunikat;

SMTP server configured in Tools/Email

That’s not what I’m looking for.

I am monitoring 8.8.8.8. If the ping times out twice, the device is considered down. At the second timeout, I want to mark the time. I think the only way I can do this is with a variable. Then, when 8.8.8.8 is back up, I am sending an email with the time the internet went down. I need to know how to store the time 8.8.8.8 went down so I can use it.

:global mylocaltime
:global mylocaldate
:set mylocaltime $[/system clock get time];
:set mylocaldate $[/system clock get date];

This could also help

:local ServerGOOGLE   "8.8.8.8"

:local i 0
:local MissedPackets 0
:local LinkChanged
:local PingOK
:global GoogleUp

:if ([:typeof $GoogleUp] = "nothing") do={:set GoogleUp false}

# PING host 5 times delay 4s
:for i from=1 to=5 do={
  if ([/ping $ServerGOOGLE count=1 interval=4s]=0) do={:set MissedPackets ($MissedPackets + 1)}
};
# check if all pings reached the destination - this equation could consider some packet loss
:set PingOK (!($MissedPackets=5))
:set LinkChanged (($GoogleUp and !$PingOK) or (!$GoogleUp and $PingOK))
:set GoogleUp $PingOK
:if ($LinkChanged) do={
  :local komunikat "GOOGLE: $[/system identity get name], $[/system clock get time], $[/system clock get date], $[/ip address get [find interface=ETH1-WAN] address] - "
  :if ( $GoogleUp ) do={
    :set komunikat ($komunikat . "UP")
  } else={
    :set komunikat ($komunikat . "DOWN")
  }
  :log info $komunikat
}