[ZBX-4218] Cannot add and update item at type of log with multi byte character in key. Created: 2011 Oct 10  Updated: 2017 May 30  Resolved: 2014 Jan 18

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 1.8.6, 1.8.7, 1.8.8
Fix Version/s: 2.0.11rc1, 2.2.2rc1, 2.3.0

Type: Incident report Priority: Minor
Reporter: Ryuji Ebine Assignee: Unassigned
Resolution: Fixed Votes: 2
Labels: api, items, multibyte
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS release 5.4 (Final)

mysql-server-5.0.77-4.el5_5.3

zabbix-1.8.7-1.el5.JP
zabbix-server-mysql-1.8.7-1.el5.JP
zabbix-server-1.8.7-1.el5.JP
zabbix-jp-release-5-3
zabbix-web-1.8.7-1.el5.JP
zabbix-web-mysql-1.8.7-1.el5.JP
zabbix-agent-1.8.7-1.el5.JP


Attachments: JPEG File screenshot-1.jpg     PNG File screenshot.238.png    
Issue Links:
Duplicate
duplicates ZBX-3128 no host or item information printed f... Closed
is duplicated by ZBX-4389 Can't add Item key with Russian text Closed

 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.



 Comments   
Comment by Kodai Terashima [ 2011 Oct 12 ]

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'

Comment by richlv [ 2011 Oct 12 ]

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 ?

Comment by Kodai Terashima [ 2011 Oct 12 ]

I haven't known that I will check it

Comment by richlv [ 2011 Oct 18 ]

any luck without mbstring overloading ?

Comment by José Roberto Prado [ 2011 Nov 16 ]

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.

Comment by Kodai Terashima [ 2011 Dec 06 ]

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.

Comment by Alexander Vladishev [ 2014 Jan 02 ]

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

Comment by Ivo Kurzemnieks [ 2014 Jan 09 ]

(1) please remove

 @package API 

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

sasha RESOLVED in r41517

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 09 ]

(2) constants should come before private and protected variables

sasha RESOLVED in r41518

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 09 ]

(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

sasha RESOLVED in r41521, r41530

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 09 ]

(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.

sasha RESOLVED in r41530

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

iivs 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.

sasha It will be better. Thanks!

RESOLVED in r41638.

iivs Great work and nice algorithm! Thanks!

CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 09 ]

(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.

sasha WAITING... will be fixed in 2.2 and trunk only

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

For example:

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

sasha 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[ ...".

iivs 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 ..."

sasha RESOLVED in r41853.

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 10 ]

(6) code piece in CITemKey.php: 91

 $state == 1 

probably should be

 $state == self::STATE_END 

since we have 'state' as constant.

sasha RESOLVED in r41524

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 10 ]

(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 "Г""

sasha RESOLVED in r41530

iivs CLOSED.

Comment by Ivo Kurzemnieks [ 2014 Jan 22 ]

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

Comment by Alexander Vladishev [ 2014 Jan 23 ]

Fixed in pre-2.0.11 r41821

Comment by Alexander Vladishev [ 2014 Jan 24 ]

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

Comment by Ivo Kurzemnieks [ 2014 Jan 24 ]

2.2 TESTED

Comment by Alexander Vladishev [ 2014 Jan 24 ]

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

Generated at Fri Apr 19 16:28:49 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.