6 Header

Overview

The header is present in all request and response messages between Zabbix components. It is required to determine the message length, if it is compressed or not, if it is a large packet or not.

Zabbix communications protocol has 1GB packet size limit per connection. The limit of 1GB is applied to both the received packet data length and the uncompressed data length.

When sending configuration to Zabbix proxy, the packet size limit is increased to 4GB to allow syncing large configurations. When data length before compression exceeds 4GB, Zabbix server automatically starts using the large packet format (0x04 flag) which increases the packet size limit to 16GB.

Note that while a large packet format can be used for sending any data, currently only the Zabbix proxy configuration syncer can handle packets that are larger than 1GB.

Structure

The header consists of four fields. All numbers in the header are formatted as little-endian.

FieldSizeSize
(large packet)
Description
<PROTOCOL>44“ZBXD” or 5A 42 58 44
<FLAGS>11Protocol flags:
0x01 - Zabbix communications protocol
0x02 - compression
0x04 - large packet
<DATALEN>48Data length.
<RESERVED>48When compression is used (0x02 flag) - the length of uncompressed data
When compression is not used - 00 00 00 00

Examples

Here are some code snippets showing how to add Zabbix protocol header to the data you want to send in order to obtain the packet you should send to Zabbix so that it is interpreted correctly. These code snippets assume that the data is not larger than 1GB, thus the large packet format is not used.

Python
  1. packet = b"ZBXD\1" + struct.pack("<II", len(data), 0) + data

or

  1. def zbx_create_header(plain_data_size, compressed_data_size=None):
  2. protocol = b"ZBXD"
  3. flags = 0x01
  4. if compressed_data_size is None:
  5. datalen = plain_data_size
  6. reserved = 0
  7. else:
  8. flags |= 0x02
  9. datalen = compressed_data_size
  10. reserved = plain_data_size
  11. return protocol + struct.pack("<BII", flags, datalen, reserved)
  12. packet = zbx_create_header(len(data)) + data
Perl
  1. my $packet = "ZBXD\1" . pack("(II)<", length($data), 0) . $data;

or

  1. sub zbx_create_header($;$)
  2. {
  3. my $plain_data_size = shift;
  4. my $compressed_data_size = shift;
  5. my $protocol = "ZBXD";
  6. my $flags = 0x01;
  7. my $datalen;
  8. my $reserved;
  9. if (!defined($compressed_data_size))
  10. {
  11. $datalen = $plain_data_size;
  12. $reserved = 0;
  13. }
  14. else
  15. {
  16. $flags |= 0x02;
  17. $datalen = $compressed_data_size;
  18. $reserved = $plain_data_size;
  19. }
  20. return $protocol . chr($flags) . pack("(II)<", $datalen, $reserved);
  21. }
  22. my $packet = zbx_create_header(length($data)) . $data;
PHP
  1. $packet = "ZBXD\1" . pack("VV", strlen($data), 0) . $data;

or

  1. function zbx_create_header($plain_data_size, $compressed_data_size = null)
  2. {
  3. $protocol = "ZBXD";
  4. $flags = 0x01;
  5. if (is_null($compressed_data_size))
  6. {
  7. $datalen = $plain_data_size;
  8. $reserved = 0;
  9. }
  10. else
  11. {
  12. $flags |= 0x02;
  13. $datalen = $compressed_data_size;
  14. $reserved = $plain_data_size;
  15. }
  16. return $protocol . chr($flags) . pack("VV", $datalen, $reserved);
  17. }
  18. $packet = zbx_create_header(strlen($data)) . $data;
Bash
  1. datalen=$(printf "%08x" ${#data})
  2. datalen="\\x${datalen:6:2}\\x${datalen:4:2}\\x${datalen:2:2}\\x${datalen:0:2}"
  3. printf "ZBXD\1${datalen}\0\0\0\0%s" "$data"