Ad Widget

Collapse

How to convert ASCII String to other formats

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pmvw@alaskapublic.org
    Junior Member
    • Jul 2020
    • 5

    #1

    How to convert ASCII String to other formats

    After fighting and winning my SNMP battle earlier today, I felt really confident that I would have all the data I needed from my 10 Microwave SNMP devices. They were quick to offer up their SNMP data, after getting their OIDs correct.

    I went for the low hanging fruit first, a simple number?!? This is what was retrieved:
    "20 20 20 32 35 2E 30 30 00"

    OMG.... NOOOoooo. It's ASCII code!! Is there anything built into Zabbix that I can push this through and all the other texts to actually get it converted. Either to store the regular text or to the numbers they need to be?
    (Yes every text is this way... even text is in ASCII code.)

    Thanks.
    Piet
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    JS preprocessing ...

    Comment

    • pmvw@alaskapublic.org
      Junior Member
      • Jul 2020
      • 5

      #3
      Ok... cyber was indeed correct. JS Preprocessing is the answer. (Thank you!)

      Since I HATE to leave questions unanswered on forums...

      Found a gem of a JS Preprocessing snippits here...
      remove duplicate text values: function uniq(a) { return a.sort().filter(function(item, pos, ary) { return !pos || item != ary[...


      Their solution works!!

      Convert to a String

      var out = "";
      for (var i = 0, nums = value.split(" "); i < nums.length; i++) {
      out += String.fromCharCode(parseInt(nums[i], 16));
      }

      return out;
      Convert to an integer...

      var out = "";
      var int_out = 0;
      for (var i = 0, nums = value.split(" "); i < nums.length; i++) {
      out += String.fromCharCode(parseInt(nums[i], 16));
      }
      int_out=parseInt(out);
      return int_out;
      Last edited by [email protected]; 24-01-2022, 21:30.

      Comment

      Working...