I would like to write a script that runs periodically, and toggles (disable + enable) any wireguard peer that has not been seen in a while. This is needed because in my experience, any wireguard peer becomes unusuable when the listen address of the wireguard server socket is changed (e.g. when the router gets a different addres on its WAN interface). This is an annoying thing, that has been around for a while. There can be other reasons why a peer would become dead. My goal is to monitor all peers in the background, and restart them when they have not been seen for a while. This could save me a lot of time.
I can get the last-handshake value with a script:
:put [/interface/wireguard/peers/get 0 last-handshake ]
00:00:45
But I’m not sure how to compare this with a given number of seconds. Actually, I’m confused about the type of this data. The documentation does not make a difference between date, time, timestamp and interval types: https://wiki.mikrotik.com/wiki/Manual:Scripting#Data_types
It only has this vague description: “time - date and time value”.
But clearly, the expression 10000m is not a date:
:put 10000m
6d22:40:00
These three values below clearly have a different type:
:put [/system/clock get time]
14:57:35
:put [/system/clock get date]
2023-11-20
:put [/system/script/get 0 last-started ]
2023-11-19 20:00:00
So we have at least four different kind of values but we only have a single data type called “time”, and I’m really confused about this.
Some operators seems logical, but they do not work as expected. Here is an example:
> :put [ [/system/script/get 0 last-started ] ]
2023-11-19 20:00:00
> :put [ [/system/script/get 0 last-started ] + 10m ]
2023-11-19 20:00:00
Looks like adding “100m” to “2023-11-19 20:00:00” is not an error (because it does not throw an error), but it does nothing. These values are not interpreted as string (that would result in “2023-11-19 20:00:0010m”, but they are also not interpreted as timestamp and interval values. But they are interpreted I guess, otherwise the expression would throw an error. What is happening here?
Here are some questions.
- What is the type of the value that is printed as 6d22:40 ?
- What is the type of the value that is printed as 14:57:35 ?
- What is the type of the value that is printed as 2023-11-20 ?
- What is the type of the value that is printed as 2023-11-19 20:00:00 ?
- Out of these four things, which ones are documented, and which ones aren’t?
- How can I access various properties of these values? (For example, year number in a date, or total number of sedconds in an interval)
- Are there any operators that work on this/these types?