Class JabbixJSONProtocol


  • public class JabbixJSONProtocol
    extends java.lang.Object
    Constants and functions for the Zabbix agent JSON based protocol.
    Author:
    Paul Wolneykien
    • Constructor Detail

      • JabbixJSONProtocol

        public JabbixJSONProtocol()
    • Method Detail

      • requestActiveCheckList

        public static void requestActiveCheckList​(JabbixWriter writer,
                                                  java.lang.String hostName)
                                           throws java.io.IOException
        Requests a set of metrics for "active" monitoring. The requested set can be received with the use of the receiveActiveCheckList(JabbixReader) method.

        The following JSON message is composed and sent to the server:

         {"request": "active checks",
          "host": "<host name>"}
         
        The host name (host) parameter is the name of the local host expected by the server (see ZabbixClient.getHostName()).
        Parameters:
        writer - a writer connected to a socket
        hostName - the name of the local host
        Throws:
        java.io.IOException - if there was an I/O exception during the request dispatch
        See Also:
        ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_GET_ACTIVE_CHECKS, ZBX_PROTO_TAG_HOST
      • sendMetricList

        public static void sendMetricList​(JabbixWriter writer,
                                          java.lang.String hostName,
                                          java.util.Collection<? extends JabbixMetric<?>> metrics)
                                   throws java.io.IOException
        Sends the set of metric values to a Zabbix server. The server replies with the status message (see receiveMetricListResponse(JabbixReader)).

        The following JSON message is composed and sent to the server:

         {
             "request": "agent data",
             "data":
             [
                 { "host": "<host name>",
                   "key": "<metric key>",
                   "value": "<metric value>",
                   "clock": <metric time stamp>" },
                 { "host": "<host name>",
                   "key": "<metric key>",
                   "value": "<metric value>",
                   "clock": <metric time stamp>" },
        
                 ...
        
             ]
             "clock": <message time stamp>
         }
         
        The host name (host) parameter is the name of the local host expected by the server (see ZabbixClient.getHostName()).

        The meric key (key) parameter of each entry is the name of the metric (see JabbixActiveMetric) which value the server expects to receive periodically.

        The metric value (value) parameter is the value of the metric represented as a textual string. Because of the metric value has not to be sent just after its update, the special metric time stamp (clock) entry parameter is used to explicitly state the update time (see JabbixActiveMetric.getUpdated()).

        It also seems to be useful to state the time of the request itself. The message time stamp (clock) top-level parameter is used for that porpose.

        Parameters:
        writer - a writer connected to a socket
        hostName - the name of the local host
        metrics - the set of metrics
        Throws:
        java.io.IOException - if there was an I/O exception during the dispatch
        See Also:
        ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_AGENT_DATA, ZBX_PROTO_TAG_HOST, ZBX_PROTO_TAG_KEY, ZBX_PROTO_TAG_VALUE, ZBX_PROTO_TAG_CLOCK, ZBX_PROTO_TAG_DATA
      • receiveMetricListResponse

        public static java.lang.String receiveMetricListResponse​(JabbixReader reader)
                                                          throws java.io.IOException,
                                                                 JabbixException,
                                                                 JabbixProtocolException
        Receives the server response for the sent metric data.

        The JSON message of the following form (structure) is expected:

         { "response": "<status>",
           "info": "<comment>" }
         
        In the successful case the status (response) parameter is stated as success. And the comment (info) parameter contains a human-readable comment on the data processing has been done.

        In the case of an error the status can be stated as failed or any other non-successful value. The comment parameter may or may not be present.

        Parameters:
        reader - a reader connected to a socket
        Returns:
        the server response message
        Throws:
        java.io.IOException - if there was an I/O exception during the response reception
        JabbixException - if the server sent an unsuccessful status
        JabbixProtocolException - if the protocol was violated (i.e. an unexpected value was received)
        See Also:
        ZBX_PROTO_TAG_RESPONSE, ZBX_PROTO_VALUE_SUCCESS, ZBX_PROTO_TAG_INFO, ZBX_PROTO_VALUE_FAILED