Ad Widget

Collapse

Date and time change detection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Piotrekzielony
    Junior Member
    • Oct 2021
    • 17

    #1

    Date and time change detection

    Hi All

    Zabbix v5.4

    I've got a timestamp from SQL database that i need to monitor.
    This is the format returned from SQL - this is single cell value that i need to work with:

    2022-06-23 10:57:54.030

    Checks are done every 1 minute via SQL query and pulling intervals can be adjusted. This field in database is updated by 3rd party program every 5 min and I need to detect if this field in database hasn't been updated in 5 min so if the value is 2022-06-23 10:57:54.030 for more than 10 min I need to fire trigger

    But i don't know how to approach this in the best possible way


    I new to zabbix - i have it for a year now but actually never had a chance to learn about its all functionality.


    Can someone help me with this or point me to right direction, please?
    Last edited by Piotrekzielony; 23-06-2022, 12:21.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    The right direction is to convert the string you received to unixtime and make a normal time comparison.
    All this can be done in preprocessing using JS.

    Comment

    • Piotrekzielony
      Junior Member
      • Oct 2021
      • 17

      #3
      Originally posted by Hamardaban
      The right direction is to convert the string you received to unixtime and make a normal time comparison.
      All this can be done in preprocessing using JS.
      Thanks

      I did it like this (i cannot get my head around unixtime to be honest):

      var date1 = new Date(value);
      var date2 = new Date();

      var diff = date2.getTime() - date1.getTime();

      var msec = diff;
      var hh = Math.floor(msec / 1000 / 60 / 60);
      msec -= hh * 1000 * 60 * 60;
      var mm = Math.floor(msec / 1000 / 60);
      msec -= mm * 1000 * 60;
      //var ss = Math.floor(msec / 1000);
      //msec -= ss * 1000;

      return mm;

      Returns difference in minutes

      Comment

      • Hamardaban
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • May 2019
        • 2713

        #4
        You don't have to translate in minutes, but use the difference in seconds and set Units as uptime. Zabbix will recalculate itself and show the readable value.
        Or if you are only interested in the divergence of time by a constant, then you can simply output 1\0 depending on whether there is a divergence or not.

        Comment

        • Piotrekzielony
          Junior Member
          • Oct 2021
          • 17

          #5
          Thank you @Hamardaban for tips

          I'll play with this later on this week but just a small question - does JS can use host's macro values?

          Comment

          • Hamardaban
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • May 2019
            • 2713

            #6
            The answer is here:


            in short - no. Only user macros.

            Comment

            Working...