Page 1 of 4
Communicating with Zabbix from REXX
Posted:
Mon Mar 01, 2021 10:42 pm
by AllardK
hi,
i am writing a Zabbix agent in REXX. However I have a problem.
Zabbix has its own protocol for messages. It is based on a byte-array.
If you want to send “data” tot the zabbix server here are a few examples in other programming languages:
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);
PHP:
$packet = "ZBXD\1" . pack('P', strlen($data)) . $data;
or
$packet = "ZBXD\1" . pack('V', strlen($data)) . "\0\0\0\0" . $data;
Perl:
my $packet = "ZBXD\1" . pack('<Q', length($data)) . $data;
or
my $packet = "ZBXD\1" . pack('V', length($data)) . "\0\0\0\0" . $data;
Python:
packet = "ZBXD\1" + struct.pack('<Q', len(data)) + data
How do i do this in REXX?
any help appreciated!
Re: Communicating with Zabbix from REXX
Posted:
Mon Mar 01, 2021 10:57 pm
by enrico-sorichetti
do not expect from us to decode toy language snippets
show the input data/buffer
show the output data/buffer
both in char and hex format
and use the code tags
help people who spend their time helping
on what platform do you expect your rexx to run ?
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 1:47 am
by AllardK
Hello Enrico,
I cannot show outputdata because I don’t know how to program them in REXX.
The format of the output should be in byte array format (as seen in the code examples in other programmig languages)
I am running my REXX on z/OS
I suspect there is also a big-endian - little endian problem to solve, but I am not sure.
ASCII-EBCDIC translation is done by setting the socket option in REXX.
Hope someone can help
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 1:54 am
by AllardK
The specifications for a Zabbix-message are:
<PROTOCOL> - "ZBXD" (4 bytes).
<FLAGS> -the protocol flags, (1 byte). 0x01 - Zabbix communications protocol, 0x02 - compression).
<DATALEN> - data length (4 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).
<DATA>
How do I code this in REXX?
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 2:29 am
by enrico-sorichetti
I cannot show outputdata because I don’t know how to program them in REXX.
why not ...
I am not asking You to code it, I am asking to show what the sequence of bytes You are going to send looks like
in terms of ..
position, length,format, representation
1, 4, char, ascii/ebcdic
2 ,1, binary
3.4, binary,
and so on and so on
and the sequence of bytes is the buffer you are going to send ...
and if You expect a proper translation from/to ascii/ebcdic for binary data
well... You are facing a long and windy road ahead
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 10:28 am
by AllardK
Hello Enrico,
from the protocol description I would come to this:
4,4 char,
5,2 binary, 0x01
6,4 binary, integer I , formatted as 32bit number, in little indian firmat
8,4 char
13, I char
where integer I is the lenth of the data-part
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 2:26 pm
by enrico-sorichetti
did you ever care about reading the manual about ...
string concatenation,
using hexdacimal representation of a byte
or even look at the rexx snippets posted here
Re: Communicating with Zabbix from REXX
Posted:
Tue Mar 02, 2021 3:06 pm
by willy jensen
As mentioned before you really should look at REXX General Concepts: 'Literal Strings' and 'Hexadecimal Strings' and 'Numbers and arithmetic' in the manual.
However in your case you can probably make do with Literal Strings like 'ABC45' - note the quotes - and Hexadecimal Strings like '04AF'x - note the quotes and the trailing 'x'.
You use || to concatenation strings, i.e. 'ABC45' || '04AF'x. There are other ways, but that one will do fine.
I believe that '\0' is the same as '00'x.
Re: Communicating with Zabbix from REXX
Posted:
Wed Mar 03, 2021 11:56 am
by AllardK
Hello Enrico, Willy
here is my code-snippet:
result = Calculate_Result(key)
dl_out = length(result)
dl_out_hex = D2X(dl_out)
packet = 'ZBXD'||'01'x||dl_out_hex||'00'x||'00'x||'00'x||'00'x||result
fc = SOCKET('SEND',accepted_socket,packet,'')
I calculate a esut that has to be sent back to the zabbix-server: result
I calculate the length of the result
I do a conversion of that length to hex
I concatenate the packet to send
I send the packet to the zabbix server
In my test the string resut = ‘ZOS4’
So the length of the data is 4
However when sending the packet the zabbix-server is giving an error “because message is shorter than expected 52 bytes”
So the problem must be in the wrong format of dl_out in the packet.
I hope you can help me solve this.
Kind regards Allard
Re: Communicating with Zabbix from REXX
Posted:
Wed Mar 03, 2021 12:37 pm
by enrico-sorichetti
because message is shorter than expected 52 bytes
and what do you expect us to do ???
it' s up to you to build a packet of the proper length