Communicating with Zabbix from REXX



IBM's Command List programming language & Restructured Extended Executor

Communicating with Zabbix from REXX

Postby AllardK » Mon Mar 01, 2021 10:42 pm

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!
AllardK
 
Posts: 17
Joined: Tue Apr 28, 2020 4:27 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Communicating with Zabbix from REXX

Postby enrico-sorichetti » Mon Mar 01, 2021 10:57 pm

do not expect from us to decode toy language snippets :evil:

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 ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Communicating with Zabbix from REXX

Postby AllardK » Tue Mar 02, 2021 1:47 am

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
AllardK
 
Posts: 17
Joined: Tue Apr 28, 2020 4:27 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Communicating with Zabbix from REXX

Postby AllardK » Tue Mar 02, 2021 1:54 am

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?
AllardK
 
Posts: 17
Joined: Tue Apr 28, 2020 4:27 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Communicating with Zabbix from REXX

Postby enrico-sorichetti » Tue Mar 02, 2021 2:29 am

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Communicating with Zabbix from REXX

Postby AllardK » Tue Mar 02, 2021 10:28 am

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
AllardK
 
Posts: 17
Joined: Tue Apr 28, 2020 4:27 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Communicating with Zabbix from REXX

Postby enrico-sorichetti » Tue Mar 02, 2021 2:26 pm

did you ever care about reading the manual about ...
string concatenation,
using hexdacimal representation of a byte :evil:

or even look at the rexx snippets posted here
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Communicating with Zabbix from REXX

Postby willy jensen » Tue Mar 02, 2021 3:06 pm

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.

These users thanked the author willy jensen for the post:
AllardK (Sat Mar 27, 2021 1:35 pm)
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: Communicating with Zabbix from REXX

Postby AllardK » Wed Mar 03, 2021 11:56 am

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
AllardK
 
Posts: 17
Joined: Tue Apr 28, 2020 4:27 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Communicating with Zabbix from REXX

Postby enrico-sorichetti » Wed Mar 03, 2021 12:37 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Next

Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post