Zabbix Documentation 4.4

3.04.04.4 (current)| In development:5.0 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


manual:appendix:protocols:header_datalen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
manual:appendix:protocols:header_datalen [2018/01/23 14:41]
vso created
manual:appendix:protocols:header_datalen [2019/05/14 08:05] (current)
vso ZBX-16123 fixed for loop to work on older bash versions
Line 1: Line 1:
-==== Header ​and data length ​====+==== Header ====
  
 === Overview === === Overview ===
  
-Header ​and data length ​is present in response and request messages between ​zabbix ​components, it is required to determine ​end of message. +Header is present in response and request messages between ​Zabbix ​components. It is required to determine ​the length ​of message. ​The header consists of:
 <​code>​ <​code>​
-<HEADER> - "ZBXD\x01" (bytes) +<PROTOCOL> - "​ZBXD"​ (bytes)
-<​DATALEN>​ - data length (bytes). 1 will be formatted as 01/​00/​00/​00/​00/00/00/00 (eight bytes, ​64 bit number in little-endian format)+<​FLAGS>​ -the protocol flags, (1 byte). 0x01 - Zabbix communications protocol, 0x02 - compression). 
 +<​DATALEN>​ - data length (bytes). 1 will be formatted as 01/00/00/00 (four bytes, ​32 bit number in little-endian format)
 +<​RESERVED>​ - reserved for protocol extensions (4 bytes).
 </​code>​ </​code>​
  
-To not exhaust memory (potentially) Zabbix ​server ​is limited to accept only 128MB in one connection ​when using the Zabbix protocol.+When compression is enabled (0x02 flag) the <​RESERVED>​ bytes contains uncompressed data size, 32 bit number in little-endian format. 
 + 
 +To not exhaust memory (potentially) Zabbix ​protocol ​is limited to accept only 128MB in one connection
 + 
 +=== Implementation === 
 + 
 +Here are code snippets showing how to add Zabbix protocol ​header to the ''​data''​ you //want// to send in order to obtain ''​packet''​ you //should// send to Zabbix so it is interpreted correctly. 
 + 
 +^Language^Code^ 
 +|bash|<​code bash> 
 +printf -v LENGTH '​%016x'​ "​${#​DATA}"​ 
 +PACK=""​ 
 +for (( i=14; i>=0; i-=2 )); do PACK="​$PACK\\x${LENGTH:​$i:​2}";​ done 
 +printf "​ZBXD\1$PACK%s"​ "​$DATA"​ 
 +</​code>​| 
 +|Java|<​code Java> 
 +byte[] header = new byte[] { 
 + '​Z',​ '​B',​ '​X',​ '​D',​ '​\1',​ 
 + (byte)(data.length & 0xFF), 
 + (byte)((data.length >> 8) & 0xFF), 
 + (byte)((data.length >> 16) & 0xFF), 
 + (byte)((data.length >> 24) & 0xFF), 
 + '​\0',​ '​\0',​ '​\0',​ '​\0'​};​ 
 + 
 +byte[] packet = new byte[header.length + data.length];​ 
 +System.arraycopy(header,​ 0, packet, 0, header.length);​ 
 +System.arraycopy(data,​ 0, packet, header.length,​ data.length);​ 
 +</​code>​| 
 +|PHP|<​code PHP> 
 +$packet = "​ZBXD\1"​ . pack('​P',​ strlen($data)) . $data; 
 +</​code>​or<​code PHP> 
 +$packet = "​ZBXD\1"​ . pack('​V',​ strlen($data)) . "​\0\0\0\0"​ . $data; 
 +</​code>​| 
 +|Perl|<​code Perl> 
 +my $packet = "​ZBXD\1"​ . pack('<​Q',​ length($data)) . $data; 
 +</​code>​or<​code Perl> 
 +my $packet = "​ZBXD\1"​ . pack('​V',​ length($data)) . "​\0\0\0\0"​ . $data; 
 +</​code>​| 
 +|Python|<​code Python>​ 
 +packet = "​ZBXD\1"​ + struct.pack('<​Q',​ len(data)) + data 
 +</​code>​|