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