Ad Widget

Collapse

Calc the difference between two dates: now and the date of an API return.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyberphantom
    Member
    • Dec 2021
    • 67

    #1

    Calc the difference between two dates: now and the date of an API return.

    ​​​​Hello everyone
    I’m new on zabbix and I get stuck in a problem. I’m using zabbix and grafana in the last versions.
    I have one API that returns me a date, this return means that I have data until this date. The problem is that this date changes eventually, and I have to calc this for when it remains less than 2 days of data (2 days from the date), it will alarm critical, 3 to 2 days it will be warning and more than 3 days will be OK.

    I tried it many ways (calc itens, triggers etc), but unsuccessfully. Actually, I have on my zabbix the return of this API, it is in epoch time, but I converted and zabbix is giving me the correct date (the "Expiration_Test on first image, that means I have data until 2021-12-17 23:35:00). I’ve made one of the current date too.

    There is a way to do this (not using external scripts)?

    Click image for larger version

Name:	apidate.png
Views:	2646
Size:	3.1 KB
ID:	435922 Click image for larger version

Name:	currentime.png
Views:	2750
Size:	2.6 KB
ID:	435923
    Attached Files
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    Hi there.

    I personally think it would have been much easier to calculate if you have value from API as epoch time. Then you can do calculated item like (API epoch time) - (current epoch time).

    If result > 259200 - OK
    If 259200 < result < 172800 - Warning
    If result < 127800 - Critical

    Alternative - go with JS script preprocessing writing a script that would do date-time conversion and do needed calculations.

    Comment

    • cyberphantom
      Member
      • Dec 2021
      • 67

      #3
      OK, it's better to let in epoch time, I agree. But this calc I can do with calculated items or triggers...? I can think just in this options, it's right?

      Comment

      • ISiroshtan
        Senior Member
        • Nov 2019
        • 324

        #4
        As you have both values as items (also not as epoch time yet) - you should be able to do so with calculated items, yes.

        Documentation of Zabbix also mentions now() functions available for trigger(also i did not really used it prior) which should allow you to do same in trigger without the need for "current time" item.

        So you should be able to achieve desired result both via calculated item or via trigger. But you'd need to test it out to see how it works for you. Maybe I will give it a go in my lab when have spare time, but can not promise anything as of right now.

        And as mentioned before, you also have JS preprocessing option, but that would require at least some basic JS skills.

        Comment

        Working...