ZABBIX BUGS AND ISSUES
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-4218

Cannot add and update item at type of log with multi byte character in key.

    Details

    • Type: Incident report Incident report
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.6, 1.8.7, 1.8.8
    • Fix Version/s: 2.0.11rc1, 2.2.2rc1, 2.3.0
    • Component/s: API (A)
    • Labels:
    • Environment:

      Description

      When item with multi byte character in key is created or updated ,Error messages display.
      I found that is equal to 'S_INVALID_KEY_FORMAT'(define).

      == Error messages ==


      Title: ERROR: Cannot add item
      Details: Error in item key: Invalid item key format.


      Title: ERROR: Cannot update item
      Details: Error in item key: Invalid item key format.


      Item Detail is below.

      == Item details ==


      Host: Zabbix server
      Type: Zabbix agent(active)
      Keys: log[/var/log/messages,'日本語',"UTF-8",100]
      Type of information: Log


      I found detail message at ./api/classes/class.citemkey.php in 319.
      End of key "]" is not judged in this function.I would.

      == class.citemkey.php ==


      104 private function parseKeyParameters(){
      .....
      140 // for every byte, starting after '['
      141 for($this->currentByte+; $this->currentByte < $this->keyByteCnt; $this->currentByte+) {
      142 switch($this->state){
      143 // initial state
      144 case 0:
      .....
      191 // all nestings are closed correctly
      192 if ($this->nestLevel == 0 && isset($this->key[$this->currentByte+1]) && $this->key[$this->currentByte+1] == ']' && !isset($this->key[$this->currentByte+2]))

      { 193 return; 194 }

      195
      .....
      315 break;
      316 }
      317 }
      318 $this->isValid = false;
      319 $this->error = S_INVALID_KEY_FORMAT;


      == Try to find a cause ==
      I consider to be caused by mb_strlen override strlen.
      Mb_strlen returns number not of byte but of character.It's too small than byte of key.
      "for loop"in 141 cannnot reach end of key "]".I would.

      Affecting Apache configration is found.
      But this param needs for JP package to work.

      1. cat /etc/httpd/conf.d/zabbix.conf

        php_value mbstring.func_overload 6


      == A provisional avoiding ==

      Modify class.citemkey.php
      57c57
      < $this->keyByteCnt = strlen($this->key);

      > $this->keyByteCnt = strlen(bin2hex($this->key)) / 2;

      Regards.

        Issue Links

          Activity

          Hide
          Kodai Terashima added a comment -

          We need to set 'mbstring.func_overload=6' to use frontend in Japanese.
          This issue can be reproduced if we set 'mbstring.func_overload=6'

          Show
          Kodai Terashima added a comment - We need to set 'mbstring.func_overload=6' to use frontend in Japanese. This issue can be reproduced if we set 'mbstring.func_overload=6'
          Hide
          richlv added a comment -

          i believe frontend was supposed to be utf-8 ready w/o mbstring function overloading since 1.8.2 or so - does it not work in japanese without overloading ?

          Show
          richlv added a comment - i believe frontend was supposed to be utf-8 ready w/o mbstring function overloading since 1.8.2 or so - does it not work in japanese without overloading ?
          Hide
          Kodai Terashima added a comment -

          I haven't known that I will check it

          Show
          Kodai Terashima added a comment - I haven't known that I will check it
          Hide
          richlv added a comment -

          any luck without mbstring overloading ?

          Show
          richlv added a comment - any luck without mbstring overloading ?
          Hide
          José Roberto Prado added a comment - - edited

          I have the same problem but in Web Monitoring. I used the solution above reported and solved the problem.

          Modify class.citemkey.php

          < $this->keyByteCnt = strlen($this->key);

          > $this->keyByteCnt = strlen(bin2hex($this->key)) / 2;

          Zabbix 1.8.8
          Language: English and Portuguese.

          Show
          José Roberto Prado added a comment - - edited I have the same problem but in Web Monitoring. I used the solution above reported and solved the problem. Modify class.citemkey.php < $this->keyByteCnt = strlen($this->key); — > $this->keyByteCnt = strlen(bin2hex($this->key)) / 2; Zabbix 1.8.8 Language: English and Portuguese.
          Hide
          Kodai Terashima added a comment -

          I tested multibyte character (Japanese) on 1.8.9 frontend without mbstring.func_overload.

          • Input description, key in item configuration
          • Imput description, expression in trigger configuration
          • log monitoring with Japanese character
          • eventlog monitoring with Japanese character
          • displaying item, trigger, history with Japanese character

          It seems that no problem on above situations at least, but I have not checked multibyte character on all situation.

          Show
          Kodai Terashima added a comment - I tested multibyte character (Japanese) on 1.8.9 frontend without mbstring.func_overload. Input description, key in item configuration Imput description, expression in trigger configuration log monitoring with Japanese character eventlog monitoring with Japanese character displaying item, trigger, history with Japanese character It seems that no problem on above situations at least, but I have not checked multibyte character on all situation.
          Hide
          Alexander Vladishev added a comment -

          Fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-4218

          Show
          Alexander Vladishev added a comment - Fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-4218
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (1) please remove

           @package API 

          in CItemKey.php: 31. We don't really use @package

          Alexander Vladishev RESOLVED in r41517

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (1) please remove @ package API in CItemKey.php: 31. We don't really use @package Alexander Vladishev RESOLVED in r41517 Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (2) constants should come before private and protected variables

          Alexander Vladishev RESOLVED in r41518

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (2) constants should come before private and protected variables Alexander Vladishev RESOLVED in r41518 Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (3) function description sentences require a dot at the end of line, new line after description and new line before @return
          Like so:

          /**
           * Function description.
           *
           * @param some_parameter
           *
           * @return some_value
           */
          

          and

           @return void 

          is not required and can be removed

          Alexander Vladishev RESOLVED in r41521, r41530

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (3) function description sentences require a dot at the end of line, new line after description and new line before @return Like so: /** * Function description. * * @param some_parameter * * @ return some_value */ and @ return void is not required and can be removed Alexander Vladishev RESOLVED in r41521, r41530 Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (4) giving a message like "error at position 158" for a 255 character long string will be very tough for user. Previously it had error message like "Incorrect syntax near ..." Would be good to return this approach just like we have it in trigger expressions.

          Alexander Vladishev RESOLVED in r41530

          I use zbx_substr() and zbx_strlen() to create error message. It should be discussed.

          Ivo Kurzemnieks Discussed with devs and support. Usage of functions zbx_substr() and zbx_strlen() is OK. But we still can improve the error message. Also, please, see (5) about qoutes.

          For example we enter a key "abcd:efghij" and get an error

          Error in item key: incorrect syntax near "abcd:efghi ..." at position 5.

          In this case we still need to count which simbol is incorrect. We discussed this and decided that it would be better to start from the incorrect symbol. In this case the more correct error would be

          Error in item key: incorrect syntax near ":efghij".

          Also position is not necessary, because we always start from first wrong symbol. If incorrect symbol is last, it would be better to have an error message like

          Error in item key: unexpected end of key.

          Just like before we don't need position. The incorrect string can be not only 10, but 30 symbols long. Another example when we have a string with repeating symbols "aaaaaa:aa:a:aa:a" it will give

          Error in item key: incorrect syntax near "... aaaaa:aa:a ..." at position 7.

          and we are not sure what to count. It would be better to show the first wrong symbol. For example more correct error message would be

          Error in item key: incorrect syntax near ":aa:a:aa:a".

          Also CItemKey.php: 61 opening bracket should be on line 60.

          Alexander Vladishev It will be better. Thanks!

          RESOLVED in r41638.

          Ivo Kurzemnieks Great work and nice algorithm! Thanks!

          CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (4) giving a message like "error at position 158" for a 255 character long string will be very tough for user. Previously it had error message like "Incorrect syntax near ..." Would be good to return this approach just like we have it in trigger expressions. Alexander Vladishev RESOLVED in r41530 I use zbx_substr() and zbx_strlen() to create error message. It should be discussed. Ivo Kurzemnieks Discussed with devs and support. Usage of functions zbx_substr() and zbx_strlen() is OK. But we still can improve the error message. Also, please, see (5) about qoutes. For example we enter a key "abcd:efghij" and get an error Error in item key: incorrect syntax near "abcd:efghi ..." at position 5. In this case we still need to count which simbol is incorrect. We discussed this and decided that it would be better to start from the incorrect symbol. In this case the more correct error would be Error in item key: incorrect syntax near ":efghij" . Also position is not necessary, because we always start from first wrong symbol. If incorrect symbol is last, it would be better to have an error message like Error in item key: unexpected end of key. Just like before we don't need position. The incorrect string can be not only 10, but 30 symbols long. Another example when we have a string with repeating symbols "aaaaaa:aa:a:aa:a" it will give Error in item key: incorrect syntax near "... aaaaa:aa:a ..." at position 7. and we are not sure what to count. It would be better to show the first wrong symbol. For example more correct error message would be Error in item key: incorrect syntax near ":aa:a:aa:a" . Also CItemKey.php: 61 opening bracket should be on line 60. Alexander Vladishev It will be better. Thanks! RESOLVED in r41638. Ivo Kurzemnieks Great work and nice algorithm! Thanks! CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (5) would be good to unify error messages where $itemKey->getError() is called. discoveryconf.php: 109 has correct example.
          Error messages to be changed are in CItemGeneral.php: 267 and CDRule.php: 487
          Probably could be fixed for trunk only.

          Alexander Vladishev WAITING... will be fixed in 2.2 and trunk only

          Ivo Kurzemnieks Sorry, my mistake about correct example. Error description should be without quotes.

          For example:

          Error in item key: incorrect syntax near ":abdefghijkl ...".

          Alexander Vladishev I agree this, but not in 2.0. May be full error message should be like this:

          Invalid item key "invalid,key[param1, param2]": incorrect syntax near ",key[ ...".

          Ivo Kurzemnieks Yes, let's leave 2.0 as it is and for trunk we decided that we could show key, item name and host. It's long, but very accurate.

          Invalid item key %key% for item %item% on %host%: incorrect syntax near ":abde ..."

          Alexander Vladishev RESOLVED in r41853.

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (5) would be good to unify error messages where $itemKey->getError() is called. discoveryconf.php: 109 has correct example. Error messages to be changed are in CItemGeneral.php: 267 and CDRule.php: 487 Probably could be fixed for trunk only. Alexander Vladishev WAITING... will be fixed in 2.2 and trunk only Ivo Kurzemnieks Sorry, my mistake about correct example. Error description should be without quotes. For example: Error in item key: incorrect syntax near ":abdefghijkl ..." . Alexander Vladishev I agree this, but not in 2.0. May be full error message should be like this: Invalid item key "invalid,key[param1, param2]" : incorrect syntax near ",key[ ..." . Ivo Kurzemnieks Yes, let's leave 2.0 as it is and for trunk we decided that we could show key, item name and host. It's long, but very accurate. Invalid item key %key% for item %item% on %host%: incorrect syntax near ":abde ..." Alexander Vladishev RESOLVED in r41853. Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (6) code piece in CITemKey.php: 91

           $state == 1 

          probably should be

           $state == self::STATE_END 

          since we have 'state' as constant.

          Alexander Vladishev RESOLVED in r41524

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (6) code piece in CITemKey.php: 91 $state == 1 probably should be $state == self::STATE_END since we have 'state' as constant. Alexander Vladishev RESOLVED in r41524 Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment - - edited

          (7) before: if we entered a key which begins with, for example, a cyrillic char, it throwed an error "Invalid item key format."
          now: entering, for example, key "ГУГЛ", it throws error "key is empty". This is incorrect errror message. Should probably display same as described in (4). For example "Incorrect syntax near "Г""

          Alexander Vladishev RESOLVED in r41530

          Ivo Kurzemnieks CLOSED.

          Show
          Ivo Kurzemnieks added a comment - - edited (7) before: if we entered a key which begins with, for example, a cyrillic char, it throwed an error "Invalid item key format." now: entering, for example, key "ГУГЛ", it throws error "key is empty". This is incorrect errror message. Should probably display same as described in (4). For example "Incorrect syntax near "Г"" Alexander Vladishev RESOLVED in r41530 Ivo Kurzemnieks CLOSED.
          Hide
          Ivo Kurzemnieks added a comment -

          TESTED. But don't forget to close (5)

          Show
          Ivo Kurzemnieks added a comment - TESTED. But don't forget to close (5)
          Hide
          Alexander Vladishev added a comment -

          Fixed in pre-2.0.11 r41821

          Show
          Alexander Vladishev added a comment - Fixed in pre-2.0.11 r41821
          Hide
          Alexander Vladishev added a comment -

          The fix for 2.2 is ready for testing. Available in the development branch svn://svn.zabbix.com/branches/dev/ZBX-4218-22

          Show
          Alexander Vladishev added a comment - The fix for 2.2 is ready for testing. Available in the development branch svn://svn.zabbix.com/branches/dev/ZBX-4218-22
          Hide
          Ivo Kurzemnieks added a comment -

          2.2 TESTED

          Show
          Ivo Kurzemnieks added a comment - 2.2 TESTED
          Hide
          Alexander Vladishev added a comment -

          Fixed in pre-2.2.2 r41867 and pre-2.3.0 (trunk) r41869.

          Show
          Alexander Vladishev added a comment - Fixed in pre-2.2.2 r41867 and pre-2.3.0 (trunk) r41869.

            People

            • Assignee:
              Unassigned
              Reporter:
              Ryuji Ebine
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: