Ad Widget

Collapse

Problem to convert a data Hex-string in Zabbix Item Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Naillik
    Junior Member
    • Jun 2018
    • 5

    #1

    Problem to convert a data Hex-string in Zabbix Item Value

    Hello, here is my problem "Item preprocessing step #1 failed: cannot convert value "" of type "string" from hexadecimal format: invalid value format"

    In fact, I use SNMP to get information on a printer : OID .1.3.6.1.2.1.25.3.5.1.2.1 and i get this normaly :

    1000 0000 0000 0000 : Low Paper
    0100 0000 0000 0000 : No Paper
    0010 0000 0000 0000 : Low Toner = 0020 Hex
    0001 0000 0000 0000 : No Toner
    0000 1000 0000 0000 : Door Open
    0000 0100 0000 0000 : Jammed
    0000 0010 0000 0000 : Offline
    0000 0001 0000 0000 : Service Requested
    0000 0000 1000 0000 : Input Tray Missing
    0000 0000 0100 0000 : Output Tray Missing
    0000 0000 0010 0000 : Marker Supply Missing
    0000 0000 0001 0000 : Output Near Full
    0000 0000 0000 1000 : Output Full
    0000 0000 0000 0100 : Input Tray Empty
    0000 0000 0000 0010 : Overdue Preventive Maintainance
    0000 0000 0000 0001 : Not assigned

    But when i catch the data it appears like that " " = 20 (ascii = Hex)

    ----------------------- New Test -----------------------
    Paessler SNMP Tester 5.2.3 Computername: INFO-0062 Interface: ZZZ.YY.Z.YY
    11/06/2018 15:27:49 (10 ms) : Device: ZZZ.YY.Z.YY
    11/06/2018 15:27:49 (14 ms) : SNMP V1
    11/06/2018 15:27:49 (18 ms) : Custom OID .1.3.6.1.2.1.25.3.5.1.2.1
    11/06/2018 15:27:49 (26 ms) : SNMP Datatype: ASN_OCTET_STR
    11/06/2018 15:27:49 (48 ms) : -------
    11/06/2018 15:27:49 (52 ms) : Value:
    11/06/2018 15:27:49 (57 ms) : Done


    ----------------------- New Test -----------------------
    Paessler SNMP Tester 5.2.3 Computername: INFO-0062 Interface: ZZZ.YY.Z.YY
    11/06/2018 15:27:53 (9 ms) : Device: ZZZ.YY.Z.YY
    11/06/2018 15:27:53 (13 ms) : SNMP V1
    11/06/2018 15:27:53 (17 ms) : Custom OID .1.3.6.1.2.1.25.3.5.1.2.1
    11/06/2018 15:27:53 (23 ms) : SNMP Datatype: ASN_OCTET_STR
    11/06/2018 15:27:53 (28 ms) : -------
    11/06/2018 15:27:53 (33 ms) : Value: 20
    11/06/2018 15:27:53 (38 ms) : Done

    So zabbix don't want to get this value and i don't know how to convert it, in Hex or Bit

    And also use a trigger to easely get a report of the problem.

    Thanks for help.
    Last edited by Naillik; 11-06-2018, 15:41. Reason: SNMP,Printers,Zabbix
  • kernbug
    Senior Member
    • Feb 2013
    • 330

    #2
    Hi,
    According to https://support.zabbix.com/browse/ZBXNEXT-1888 try using DISPLAY-HINT defined for the corresponding MIB object.
    Or use external check for parsing hex string. Also find this https://support.zabbix.com/browse/ZBX-2452, but it is for old versions of Zabbix.

    Comment

    • Naillik
      Junior Member
      • Jun 2018
      • 5

      #3
      Hi and Thanks

      Sorry if i'm misunderstand, (i'm new to zabbix and don't have a perfect english) but i don't understand how or where, i can change (in Zabbix, the item or administration) the Oa or DISPLAY-HINT defined for the corresponding MIB object.
      Or maybe will i use the Preprocessing steps to convert the value.I work on zabbix 3.4.9.

      Thanks for reply

      Comment

      • kernbug
        Senior Member
        • Feb 2013
        • 330

        #4
        Originally posted by Naillik
        Hi and Thanks

        Sorry if i'm misunderstand, (i'm new to zabbix and don't have a perfect english) but i don't understand how or where, i can change (in Zabbix, the item or administration) the Oa or DISPLAY-HINT defined for the corresponding MIB object.
        Or maybe will i use the Preprocessing steps to convert the value.I work on zabbix 3.4.9.

        Thanks for reply
        Here you can find working script to deal with parsing hex with whitespaces:


        Also there is an ability to choose data type HEX in item settings: https://www.zabbix.com/documentation...fig/items/item
        Last edited by kernbug; 12-06-2018, 13:59.

        Comment

        • keminc
          Junior Member
          • Sep 2020
          • 3

          #5
          Hello everyone, and thanks to people unsubscribed above ZBXNEXT-505. There is a little problem with 0x00 symbol in the SNMP, answer, so there is a little modified JS for converts HEX to String, for Zabbix data collectors prototypes and items.

          For discovery group:


          var regex = /"{#SNMPVALUE}":"([0-9 A-F ]*) "}/;
          var m;
          do{
          m = regex.exec(value);
          if (m) { var str = ''; hex = m[1];
          hex = hex.replace(/ /g,'');
          for (var n = 0; n < hex.length; n += 2) {
          if (hex.substr(n, 2) != '00'){ str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); }
          }
          value = value.replace(m[1], str);
          }

          } while (m);
          return (value);


          And for prototypes of items:


          var str1 = value;
          var hex = str1.toString();
          if (! hex.match(/\b[0-9A-F ]{6}\b/gi)) {
          return str1;
          } else {
          hex = hex.replace(/ /g,"");
          var str = '';
          for (var n = 0; n < hex.length; n += 2) { str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); }
          return str; }
          Last edited by keminc; 18-09-2020, 15:09.

          Comment

          Working...