zabbix sender protocol

hursta

Member
Licensed User
Longtime User
Looking at the snippet of Java source, it appears that the “Zabbix header” is the string of characters, ZBXD, followed by 0×01 and a bit-packed/padded integer representing the length of the JSON blob which follows.

<HEADER> - "ZBXD\x01" (5 bytes)
<DATALEN> - data length (8 bytes). 1 will be formatted as 01/00/00/00/00/00/00/00 (eight bytes in HEX, 64 bit number)


String report = buildJSonString(...);
writeMessage(stream, report.getBytes());
...
private String buildJSonString(String host, String item, String value)
{
return "{"
+ "\"request\":\"sender data\",\n"
+ "\"data\":[\n"
+ "{\n"
+ "\"host\":\"" + host + "\",\n"
+ "\"key\":\"" + item + "\",\n"
+ "\"value\":\"" + value.replace("\\", "\\\\") + "\"}]}\n" ;
}

protected void writeMessage(OutputStream out, byte[] data) throws IOException {
int length = data.length;

out.write(new byte[] {
'Z', 'B', 'X', 'D',
'\1',
(byte)(length & 0xFF),
(byte)((length & 0x00FF) >> 8),
(byte)((length & 0x0000FF) >> 16),
(byte)((length & 0x000000FF) >> 24),
'\0','\0','\0','\0'});

out.write(data);
}

Need help to convert this code to Basic4Android.

Thanks, Andreas
 
Use JSON library to create the JSON string.
You can build the header with this code:
Code: Copy
Dim header() As Byte = Array As Byte(Asc("Z"), Asc("B"), Asc("X"), Asc("D"), _
   1, Bit.And(length, 0xFF), _
   Bit.ShiftRight(Bit.And(length, 0x00FF), 8), _
   Bit.ShiftRight(Bit.And(length, 0x0000FF), 16), _
   Bit.ShiftRight(Bit.And(length, 0x000000FF), 24), _
   0, 0, 0, 0)
 
Upvote 0
Back
Top