0

我正在使用 API 调用向我的注册商查询我的域的到期日期。数据以字符串形式返回,格式为 DD/MM/YYYY。大多数情况下,这是一个未来的日期。

我希望在到期日为 20 天或更短时触发触发器。

如何计算今天与脚本返回的字符串的日期值之间的天数差异(这实际上是一个用户参数)?

4

1 回答 1

3

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\")))")'
于 2014-12-14T20:51:02.217 回答