Zabbix Date Comparison

8.2k Views Asked by At

I'm using an API call to query my registrar for my domains's expiry date. The data is returned as a string, formatted DD/MM/YYYY. Mostly, this is a future date.

I wish to fire a trigger when the expiry date is 20 days or less.

How can I calculate the difference in days between today and the date value of the string returned by script (this is actually a UserParameter)?

1

There are 1 best solutions below

1
On

Zabbix is not able to do it. It'll be possible, if you are able to save string DD/MM/YYYY as UNIX timestamp (it's userparameter, so it will be easy). Then the trigger will be (20days = 20*24*60*60sec = 1728000sec):

{expiry_date_unixtimestamp.last()-expiry_date_unixtimestamp.now()}<1728000

Python one liner for converting DD/MM/YYY:

echo -n "30/12/2014" | python -c 'exec("import time, sys;from time import mktime;print int(mktime(time.strptime(sys.stdin.read(), \"%d/%m/%Y\")))")'

So your userparameter should be:

 UserParameter=expiry_date_unixtimestamp,<code: obtain DD/MM/YYY string, no new line at he end of string> | python -c 'exec("import time, sys;from time import mktime;print int(mktime(time.strptime(sys.stdin.read(), \"%d/%m/%Y\")))")'