Ad Widget

Collapse

How to monitor NTP Diff

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bacteria666
    Junior Member
    • Oct 2019
    • 9

    #1

    How to monitor NTP Diff

    Hi everybody,

    Firstly this is my first post, Secondly my English is a little bit rusty.


    My doubt is simple: "HOWTO check if a host has time difference compared with Zabbix server".

    A long time ago I used nagios3, nowadays I am using zabbix, however I used a plugin check_snmp_time ( https://github.com/mludvig/nagios-pl...k_snmp_time.pl ) which simplily get a host time by SNMP and do a calc to show the time difference between host and zabbix server.

    Anyone could help or give the way to develop that solution ?

    thanks 2 take ur time to read me.
  • Answer selected by bacteria666 at 15-12-2022, 13:27.
    bacteria666
    Junior Member
    • Oct 2019
    • 9

    Originally posted by tserreyn
    Interested in the template, did you end up posting it somewhere?
    Hi tserreyn

    I uploaded to share zabix, please check the link below and please, try and vote.

    Any questions, just call me.

    Thanks.

    Comment


    • tserreyn
      tserreyn commented
      Editing a comment
      Downloaded installed and tested:

      definately detected my local host that was off by 10 minutes and triggered alert.

      However it also alerted on hosts in a different timezone that were in sync, just in a timezone two hours earlier than mine.

      I think the pre-processing isn't taking into account the timezone field if it exists, which means if the time is in local timezone, the epoch time is being calculated wrong because it is based on UTC not localtimezone.

    • bacteria666
      bacteria666 commented
      Editing a comment
      I really appreciate your feedback and I will revise about the timezones.

      Im my case I use the same timezone on zabbix server and monitored hosts and works fine for me.

      Could you send me the output results of "date" command on your zabbix server and the host.

      Thanks.

    • bacteria666
      bacteria666 commented
      Editing a comment
      hi tserreyn, do you have this template ?
      Once the old share zabbix has gone I am working to build a new one
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    https://www.zabbix.com/documentation...gers/functions --> fuzzytime

    Comment


    • bacteria666
      bacteria666 commented
      Editing a comment
      looks great, but via SNMP I get 2019-11-28,14:48:5.0,-3:0 .... not unix epoch time
  • bacteria666
    Junior Member
    • Oct 2019
    • 9

    #3
    fuzzytime seens great, however, I got date im this format "2019-11-28,14:48:5.0,-3:0" .... and my problem is .... I have no idea how to process the data to store and after that compare with now()

    I am getting this value through SNMP oid:
    .1.3.6.1.2.1.25.1.2.0 = STRING: 2019-11-28,14:51:5.0,-3:0

    Thanks.

    Comment

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

      #4
      You can use preprocessing (JS) at data item to convert string "2019-11-28,14:51:5.0,-3:0" to epoch (by JS script).

      Comment


      • bacteria666
        bacteria666 commented
        Editing a comment
        by JS ? really ? how ? hahahahah I'm gonna search that
    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #5
      https://www.zabbix.com/documentation...fig/items/item >> Item value preprocessing >>
      Javascript Enter JavaScript code in the block that appears when clicking in the parameter field or on Open.
      Note that available JavaScript length depends on the database used.
      For more information, see: Javascript preprocessing.

      Comment

      • bacteria666
        Junior Member
        • Oct 2019
        • 9

        #6
        Originally posted by Hamardaban
        You can use preprocessing (JS) at data item to convert string "2019-11-28,14:51:5.0,-3:0" to epoch (by JS script).
        This is exactly the thing I was searching.

        ps.: I really appreciate UR help. thanks


        [SOLUTION] =>
        Code:
        var p2 = value.split(',', 2).join(',').length;  // find 2nd ocurr of comma
        var dt = value.substr(0,p2);                    // to remove after that
        dt = dt.replace(',', ' ');                      // replace 1st comma to space
        dt = Date.parse(dt)/1000;                       // get time in unix epoch
        return  dt;                                     // output
        Last edited by bacteria666; 29-11-2019, 14:15. Reason: Solution

        Comment


        • tserreyn
          tserreyn commented
          Editing a comment
          hmm, converting to epoch using code above gives different epoch values depending on the timezone, maybe timezone offset is being ignored.

          2021-1-16,17:37:4.0,-8:0 ---> 1610818684
          2021-1-16,19:38:10.0,-6:0 ---> 1610825890

          of course the difference is 120 minutes, which is the difference in time zones.
      • bacteria666
        Junior Member
        • Oct 2019
        • 9

        #7
        Well, I did in another way in the follow steps below:
        • Get timedate via SNMP;
        • Convert datetime to unixepoch via javascript
        • Get time difference subtracting the remove date/time with local server date/time;
        • return the difference;

        After that I create two triggers with Average and Warning severity.


        I created a template also and I would like to know how to upload to share zabbix.

        Thanks.

        Comment

        • tserreyn
          Junior Member
          • Jun 2012
          • 26

          #8
          Interested in the template, did you end up posting it somewhere?

          Comment

          • bacteria666
            Junior Member
            • Oct 2019
            • 9

            #9
            Originally posted by tserreyn
            Interested in the template, did you end up posting it somewhere?
            Hi tserreyn

            I uploaded to share zabix, please check the link below and please, try and vote.

            Any questions, just call me.

            Thanks.

            Comment


            • tserreyn
              tserreyn commented
              Editing a comment
              Downloaded installed and tested:

              definately detected my local host that was off by 10 minutes and triggered alert.

              However it also alerted on hosts in a different timezone that were in sync, just in a timezone two hours earlier than mine.

              I think the pre-processing isn't taking into account the timezone field if it exists, which means if the time is in local timezone, the epoch time is being calculated wrong because it is based on UTC not localtimezone.

            • bacteria666
              bacteria666 commented
              Editing a comment
              I really appreciate your feedback and I will revise about the timezones.

              Im my case I use the same timezone on zabbix server and monitored hosts and works fine for me.

              Could you send me the output results of "date" command on your zabbix server and the host.

              Thanks.

            • bacteria666
              bacteria666 commented
              Editing a comment
              hi tserreyn, do you have this template ?
              Once the old share zabbix has gone I am working to build a new one
          • bacteria666
            Junior Member
            • Oct 2019
            • 9

            #10
            Here is my scrren with tests.

            I'm using the same timezone in both, server and host

            Click image for larger version

Name:	zbx1.png
Views:	6090
Size:	67.0 KB
ID:	417159
            Attached Files

            Comment

            • leonardogyn
              Junior Member
              • Nov 2022
              • 7

              #11
              Originally posted by bacteria666

              Hi tserreyn

              I uploaded to share zabix, please check the link below and please, try and vote.

              Any questions, just call me.

              Thanks.

              Couldn't find the template on Zabbix Integrations, the new platform for the old share.zabbix.com. Would you mind sharing it again? Thanks! (abraço, BR aqui também)

              Comment

              Working...