org.altlinux.jabbix
Class JabbixProtocol

java.lang.Object
  extended by org.altlinux.jabbix.JabbixProtocol

public class JabbixProtocol
extends Object

Constants and functions for the base Zabbix agent-server protocol.

The base Zabbix protocol for agent-server communication is a kind of a simple binary protocol and is used to transfer arbitrary portions of data between a Zabbix-compatible agent (for instance, Jabbix based program) and a Zabbix server.

Each such a transfer is called a message. Each message has the following form (structure):

 |   4 Bytes   | 1 Byte |    8 Bytes     |        LENGTH Bytes       |
     HEADER      VERION       LENGTH             MESSAGE   DATA
 
The HEADER field is a 4 byte 4 ASCII character sequence, currently defined as ZBXD. The next VERSION one byte width field states the used protocol version. The supported version now is 1 (which is 01h).

The next 8 byte field LENGTH contains the little-endian 64 bit integer number defining the length of the next MESSAGE DATA part. All numeric data is presented as little-endian numbres too.

For compatibility and to simplify the agent-server programs, the another separator-based protocol can be used. In that protocol the messages has no predefined structure, instead of that one of the separator characters is used to mark the end of each message. Because of the newline character (0Ah) is also in separator set, the plaintext messages can be transferred as is.

The main use of the unstructured plaintext message protocol is the Zabbix server to passive agent communication: the server sends a plaintext metric key to the passive agent without any header. However, the agent is not restricted to use the plaintext protocol and can answer using the structured version if convenient.

Also, the unstructurred answers can be originated by a Zabbix server in some cases.

Author:
Paul Wolneykien
See Also:
AgentServer

Field Summary
static int AGENT_PORT
          The default agent port number (10050).
static String HEADER
          Four-letter protocol header.
static String SEPARATORS
          The set of message separators.
static int SERVER_PORT
          The default Zabbix server port number (10051).
static String VERSION
          Protocol version (one byte).
 
Constructor Summary
JabbixProtocol()
           
 
Method Summary
static JabbixReader getReader(InputStream in)
          Returns a reader connected to the specified stream.
static JabbixWriter getWriter(OutputStream out)
          Returns a writer connected to the specified stream.
static boolean isSeparator(char c)
          Indicates if the specified character is a message separator.
static String removeSeparators(String str)
          Returns the given string with all separator characters removed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER

public static String HEADER
Four-letter protocol header.

For Zabbix the character sequence ZBXD is used.


VERSION

public static String VERSION
Protocol version (one byte).

Currently the protocol version is 1 (01h).


SEPARATORS

public static String SEPARATORS
The set of message separators.

If length of the message is not explicitly stated in the header, the end of the message is determined by a separator character. This string contains the sequence of that sort of characters.

Currently the separator characters are:


AGENT_PORT

public static int AGENT_PORT
The default agent port number (10050).


SERVER_PORT

public static int SERVER_PORT
The default Zabbix server port number (10051).

Constructor Detail

JabbixProtocol

public JabbixProtocol()
Method Detail

getReader

public static JabbixReader getReader(InputStream in)
Returns a reader connected to the specified stream.

Parameters:
in - the input stream to read from
Returns:
a reader connected to the stream

getWriter

public static JabbixWriter getWriter(OutputStream out)
Returns a writer connected to the specified stream.

Parameters:
out - the output stream to write to
Returns:
a writer connected to the stream

isSeparator

public static boolean isSeparator(char c)
Indicates if the specified character is a message separator.

Parameters:
c - the character to test
Returns:
true if the character is separator, false otherwise
See Also:
SEPARATORS

removeSeparators

public static String removeSeparators(String str)
Returns the given string with all separator characters removed.

Parameters:
str - a string
Returns:
given string with all separators removed