×
Back to Geneos FAQ
How to compare timestamp with the current time in gateway rules?
You can make use of parseDate() and now() functions in gateway rules.
For example, the requirement is to check if a date (in a data cell) is 2 days past the current date. Sample value of cell is in the format: 2022-09-28 07:25:01. Then you can set a rule:
set $(timenow) now() // this will get the current time at the point of execution expressed as seconds since the UNIX epoch.
set $(timedetected) parseDate("%Y-%m-%d %H:%M:%S", value) // this will convert the date into epoch format
if $(timenow) - $(timedetected) >= 172800 then
severity critical
else
severity ok
endif
Where 172800 represents the number of seconds for 2 days.
Sample output:
Right-click on the red cell and select Show Rules.
You just need to modify the string format in the parseDate function if you have a different date format. This can then be compared to the now() function which represents the current timestamp in epoch format.
Note
The reverse function forparseDate()isprintDate(), which converts epoch timestamp to any format readable times using the same time formatting codes.
For more information, check the documentation about parseDate() function and Time formatting parsing codes.
["Geneos"]
["Geneos > Gateway"]
["FAQ"]