Ad Widget

Collapse

Change integer item to date format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dade
    Member
    • Jan 2021
    • 34

    #1

    Change integer item to date format


    Hi guys, Sorry for that silly question:

    There is a snmp item returning an integer, but I want to switch to the date format like HH: MM: SS

    Example (attached image): The value is 171941 I intend to change it to 17:19:41, is it possible?

    Greetings

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

    #2
    First you need to figure out what exactly this number means. Different devices can use different counters - time in seconds from the start of operation, epoch time / unix time, or something else. Then, with the use of preprocessing and JS, you can do any value conversion.

    Comment

    • dade
      Member
      • Jan 2021
      • 34

      #3
      Hey Hamardaban,

      Thanks for your reply.

      The number means exactly this, its a specific time.

      Can you show me a example How to use preprocessing or js to do this? I read documentation but i didnt understand.

      Thanks friend

      Comment

      • Singularity
        Member
        • Aug 2020
        • 81

        #4
        In the pre-processing tab select add and then select Javascript from the drop down then you can write a function.
        var result = "";
        var date_val = value;
        var factor = 2;
        var str_len = date_val.length;
        for( i = 0; i < str_len; i++ ) {
        if( i > 0 && i % factor == 0 ) {
        result+=":";
        result+=date_val[i];
        } else result+=date_val[i];
        }
        return result;

        Comment

        • dade
          Member
          • Jan 2021
          • 34

          #5
          Hello, guys!!

          Thanks a lot! Now i understand how the things works. Zabbix is really powerful tool!

          Singularity, i really appreciate your help, now i can handle my returning values. So i just need to improve my knowledge about js.

          I really appreciate your replies, guys! Thanks

          Comment

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

            #6
            //if device always return 6 digits (with a leading zero) then you can do this way
            return value.substring(0,2)+':'+ value.substring(2,4)+':'+ value.substring(4,6);

            Comment

            • Semiadmin
              Senior Member
              • Oct 2014
              • 1625

              #7
              Is this a competition for the simplest solution?
              Regular expression:
              Code:
              (\d\d)(\d\d)(\d\d)               \1:\2:\3

              Comment

              • dade
                Member
                • Jan 2021
                • 34

                #8
                wow! Thanks for showing me the different possibilities, please dont fight each other, rs
                Nice weekend for all!

                Comment


                • Hamardaban
                  Hamardaban commented
                  Editing a comment
                  It just shows how flexible the system is and the result can be achieved by different methods.
              • Singularity
                Member
                • Aug 2020
                • 81

                #9
                I agree with Hamardaban. It's not a fight. It's purely exchange of thoughts

                Comment


                • dade
                  dade commented
                  Editing a comment
                  Yeah, It was joke! Thanks for your answers, It opened my mind! I really appreciate
              Working...