Class JabbixProtocol


  • public class JabbixProtocol
    extends java.lang.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

      Fields 
      Modifier and Type Field Description
      static int AGENT_PORT
      The default agent port number (10050).
      static java.lang.String HEADER
      Four-letter protocol header.
      static java.lang.String SEPARATORS
      The set of message separators.
      static int SERVER_PORT
      The default Zabbix server port number (10051).
      static java.lang.String VERSION
      Protocol version (one byte).
    • Constructor Summary

      Constructors 
      Constructor Description
      JabbixProtocol()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static JabbixReader getReader​(java.io.InputStream in)
      Returns a reader connected to the specified stream.
      static JabbixWriter getWriter​(java.io.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 java.lang.String removeSeparators​(java.lang.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 java.lang.String HEADER
        Four-letter protocol header.

        For Zabbix the character sequence ZBXD is used.

      • VERSION

        public static java.lang.String VERSION
        Protocol version (one byte).

        Currently the protocol version is 1 (01h).

      • SEPARATORS

        public static java.lang.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:

        • newline (0Dh);
        • carrige return (0Ah);
        • zero byte (00h).
      • 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​(java.io.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​(java.io.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 java.lang.String removeSeparators​(java.lang.String str)
        Returns the given string with all separator characters removed.
        Parameters:
        str - a string
        Returns:
        given string with all separators removed