Class JabbixJSONProtocol
- java.lang.Object
-
- org.altlinux.jabbix.JabbixJSONProtocol
-
public class JabbixJSONProtocol extends java.lang.Object
Constants and functions for the Zabbix agent JSON based protocol.- Author:
- Paul Wolneykien
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ZBX_PROTO_TAG_AVAILABLE
static java.lang.String
ZBX_PROTO_TAG_CLOCK
Defines the time stamp of an entry.static java.lang.String
ZBX_PROTO_TAG_DATA
The entry key of an array of metric entries.static java.lang.String
ZBX_PROTO_TAG_DCHECK
static java.lang.String
ZBX_PROTO_TAG_DELAY
Defines the update period of an active metric defined by the corresponding entry.static java.lang.String
ZBX_PROTO_TAG_DRULE
static java.lang.String
ZBX_PROTO_TAG_ERROR
static java.lang.String
ZBX_PROTO_TAG_HOST
Defines the name of the local host of the agent expected by the server.static java.lang.String
ZBX_PROTO_TAG_HOSTID
static java.lang.String
ZBX_PROTO_TAG_INFO
Defines a comment for a data processing operation has been done by the server or an error message.static java.lang.String
ZBX_PROTO_TAG_IP
static java.lang.String
ZBX_PROTO_TAG_IPMI_AVAILABLE
static java.lang.String
ZBX_PROTO_TAG_IPMI_ERROR
static java.lang.String
ZBX_PROTO_TAG_KEY
Defines the name of an entry.static java.lang.String
ZBX_PROTO_TAG_KEY_ORIG
static java.lang.String
ZBX_PROTO_TAG_LOGEVENTID
static java.lang.String
ZBX_PROTO_TAG_LOGLASTSIZE
static java.lang.String
ZBX_PROTO_TAG_LOGSEVERITY
static java.lang.String
ZBX_PROTO_TAG_LOGSOURCE
static java.lang.String
ZBX_PROTO_TAG_LOGTIMESTAMP
static java.lang.String
ZBX_PROTO_TAG_MTIME
static java.lang.String
ZBX_PROTO_TAG_NODEID
static java.lang.String
ZBX_PROTO_TAG_PORT
static java.lang.String
ZBX_PROTO_TAG_PROXY
static java.lang.String
ZBX_PROTO_TAG_REGEXP
static java.lang.String
ZBX_PROTO_TAG_REQUEST
States the message to be a request to a Zabbix server.static java.lang.String
ZBX_PROTO_TAG_RESPONSE
States the message to be a response from a Zabbix server.static java.lang.String
ZBX_PROTO_TAG_SCRIPTID
static java.lang.String
ZBX_PROTO_TAG_SNMP_AVAILABLE
static java.lang.String
ZBX_PROTO_TAG_SNMP_ERROR
static java.lang.String
ZBX_PROTO_TAG_STATUS
static java.lang.String
ZBX_PROTO_TAG_TYPE
static java.lang.String
ZBX_PROTO_TAG_VALUE
Defines the value an entry.static java.lang.String
ZBX_PROTO_VALUE_AGENT_DATA
States that the agent sends the list of fresh metric values corresponding to the previously requested set of active checks (seeActiveAgent
).static java.lang.String
ZBX_PROTO_VALUE_AUTO_REGISTRATION_DATA
static java.lang.String
ZBX_PROTO_VALUE_DISCOVERY_DATA
static java.lang.String
ZBX_PROTO_VALUE_FAILED
States that the server failed to perform the previously requested operation.static java.lang.String
ZBX_PROTO_VALUE_GET_ACTIVE_CHECKS
States that the agent requests the list of active checks, the set of metrics (JabbixActiveMetric
) the server is interested in.static java.lang.String
ZBX_PROTO_VALUE_HISTORY_DATA
static java.lang.String
ZBX_PROTO_VALUE_HOST_AVAILABILITY
static java.lang.String
ZBX_PROTO_VALUE_PROXY_CONFIG
static java.lang.String
ZBX_PROTO_VALUE_PROXY_HEARTBEAT
static java.lang.String
ZBX_PROTO_VALUE_SENDER_DATA
static java.lang.String
ZBX_PROTO_VALUE_SUCCESS
States that the server has performed the previously requested operation successfully.
-
Constructor Summary
Constructors Constructor Description JabbixJSONProtocol()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Collection<JabbixActiveMetric<?>>
receiveActiveCheckList(JabbixReader reader)
Reads and returns an active check list.static java.lang.String
receiveMetricListResponse(JabbixReader reader)
Receives the server response for the sent metric data.static void
requestActiveCheckList(JabbixWriter writer, java.lang.String hostName)
Requests a set of metrics for "active" monitoring.static void
sendMetricList(JabbixWriter writer, java.lang.String hostName, java.util.Collection<? extends JabbixMetric<?>> metrics)
Sends the set of metric values to a Zabbix server.
-
-
-
Field Detail
-
ZBX_PROTO_TAG_CLOCK
public static java.lang.String ZBX_PROTO_TAG_CLOCK
Defines the time stamp of an entry.
-
ZBX_PROTO_TAG_DATA
public static java.lang.String ZBX_PROTO_TAG_DATA
The entry key of an array of metric entries.
-
ZBX_PROTO_TAG_REGEXP
public static java.lang.String ZBX_PROTO_TAG_REGEXP
-
ZBX_PROTO_TAG_DELAY
public static java.lang.String ZBX_PROTO_TAG_DELAY
Defines the update period of an active metric defined by the corresponding entry.
-
ZBX_PROTO_TAG_DRULE
public static java.lang.String ZBX_PROTO_TAG_DRULE
-
ZBX_PROTO_TAG_DCHECK
public static java.lang.String ZBX_PROTO_TAG_DCHECK
-
ZBX_PROTO_TAG_HOST
public static java.lang.String ZBX_PROTO_TAG_HOST
Defines the name of the local host of the agent expected by the server.
-
ZBX_PROTO_TAG_INFO
public static java.lang.String ZBX_PROTO_TAG_INFO
Defines a comment for a data processing operation has been done by the server or an error message.
-
ZBX_PROTO_TAG_IP
public static java.lang.String ZBX_PROTO_TAG_IP
-
ZBX_PROTO_TAG_KEY
public static java.lang.String ZBX_PROTO_TAG_KEY
Defines the name of an entry. If the entry represents a metric the name of the latter is marked with this tag.
-
ZBX_PROTO_TAG_KEY_ORIG
public static java.lang.String ZBX_PROTO_TAG_KEY_ORIG
-
ZBX_PROTO_TAG_LOGLASTSIZE
public static java.lang.String ZBX_PROTO_TAG_LOGLASTSIZE
-
ZBX_PROTO_TAG_MTIME
public static java.lang.String ZBX_PROTO_TAG_MTIME
-
ZBX_PROTO_TAG_LOGTIMESTAMP
public static java.lang.String ZBX_PROTO_TAG_LOGTIMESTAMP
-
ZBX_PROTO_TAG_LOGSOURCE
public static java.lang.String ZBX_PROTO_TAG_LOGSOURCE
-
ZBX_PROTO_TAG_LOGSEVERITY
public static java.lang.String ZBX_PROTO_TAG_LOGSEVERITY
-
ZBX_PROTO_TAG_LOGEVENTID
public static java.lang.String ZBX_PROTO_TAG_LOGEVENTID
-
ZBX_PROTO_TAG_PORT
public static java.lang.String ZBX_PROTO_TAG_PORT
-
ZBX_PROTO_TAG_PROXY
public static java.lang.String ZBX_PROTO_TAG_PROXY
-
ZBX_PROTO_TAG_REQUEST
public static java.lang.String ZBX_PROTO_TAG_REQUEST
States the message to be a request to a Zabbix server. The corresponding value should state the sort of the request being made.
-
ZBX_PROTO_TAG_RESPONSE
public static java.lang.String ZBX_PROTO_TAG_RESPONSE
States the message to be a response from a Zabbix server. The corresponding value should state the status of the response, i.e. the status of the requested operation.
-
ZBX_PROTO_TAG_STATUS
public static java.lang.String ZBX_PROTO_TAG_STATUS
-
ZBX_PROTO_TAG_TYPE
public static java.lang.String ZBX_PROTO_TAG_TYPE
-
ZBX_PROTO_TAG_VALUE
public static java.lang.String ZBX_PROTO_TAG_VALUE
Defines the value an entry. If the entry represents a metric the value of the latter is marked with this tag.
-
ZBX_PROTO_TAG_SCRIPTID
public static java.lang.String ZBX_PROTO_TAG_SCRIPTID
-
ZBX_PROTO_TAG_HOSTID
public static java.lang.String ZBX_PROTO_TAG_HOSTID
-
ZBX_PROTO_TAG_NODEID
public static java.lang.String ZBX_PROTO_TAG_NODEID
-
ZBX_PROTO_TAG_AVAILABLE
public static java.lang.String ZBX_PROTO_TAG_AVAILABLE
-
ZBX_PROTO_TAG_SNMP_AVAILABLE
public static java.lang.String ZBX_PROTO_TAG_SNMP_AVAILABLE
-
ZBX_PROTO_TAG_IPMI_AVAILABLE
public static java.lang.String ZBX_PROTO_TAG_IPMI_AVAILABLE
-
ZBX_PROTO_TAG_ERROR
public static java.lang.String ZBX_PROTO_TAG_ERROR
-
ZBX_PROTO_TAG_SNMP_ERROR
public static java.lang.String ZBX_PROTO_TAG_SNMP_ERROR
-
ZBX_PROTO_TAG_IPMI_ERROR
public static java.lang.String ZBX_PROTO_TAG_IPMI_ERROR
-
ZBX_PROTO_VALUE_FAILED
public static java.lang.String ZBX_PROTO_VALUE_FAILED
States that the server failed to perform the previously requested operation.
-
ZBX_PROTO_VALUE_SUCCESS
public static java.lang.String ZBX_PROTO_VALUE_SUCCESS
States that the server has performed the previously requested operation successfully.
-
ZBX_PROTO_VALUE_GET_ACTIVE_CHECKS
public static java.lang.String ZBX_PROTO_VALUE_GET_ACTIVE_CHECKS
States that the agent requests the list of active checks, the set of metrics (JabbixActiveMetric
) the server is interested in.
-
ZBX_PROTO_VALUE_PROXY_CONFIG
public static java.lang.String ZBX_PROTO_VALUE_PROXY_CONFIG
-
ZBX_PROTO_VALUE_PROXY_HEARTBEAT
public static java.lang.String ZBX_PROTO_VALUE_PROXY_HEARTBEAT
-
ZBX_PROTO_VALUE_DISCOVERY_DATA
public static java.lang.String ZBX_PROTO_VALUE_DISCOVERY_DATA
-
ZBX_PROTO_VALUE_HOST_AVAILABILITY
public static java.lang.String ZBX_PROTO_VALUE_HOST_AVAILABILITY
-
ZBX_PROTO_VALUE_HISTORY_DATA
public static java.lang.String ZBX_PROTO_VALUE_HISTORY_DATA
-
ZBX_PROTO_VALUE_AUTO_REGISTRATION_DATA
public static java.lang.String ZBX_PROTO_VALUE_AUTO_REGISTRATION_DATA
-
ZBX_PROTO_VALUE_SENDER_DATA
public static java.lang.String ZBX_PROTO_VALUE_SENDER_DATA
-
ZBX_PROTO_VALUE_AGENT_DATA
public static java.lang.String ZBX_PROTO_VALUE_AGENT_DATA
States that the agent sends the list of fresh metric values corresponding to the previously requested set of active checks (seeActiveAgent
).
-
-
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 thereceiveActiveCheckList(JabbixReader)
method.The following JSON message is composed and sent to the server:
{"request": "active checks", "host": "<host name>"}
Thehost name
(host) parameter is the name of the local host expected by the server (seeZabbixClient.getHostName()
).- Parameters:
writer
- a writer connected to a sockethostName
- 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
-
receiveActiveCheckList
public static java.util.Collection<JabbixActiveMetric<?>> receiveActiveCheckList(JabbixReader reader) throws java.io.IOException, JabbixException, JabbixProtocolException
Reads and returns an active check list. Used to read the previously requested information on metrics for "active" monitoring.The JSON message of the following form (structure) is expected:
{ "response": "success", "data": [ { "key": "<metric key>", "delay":"<update period>" }, { "key": "<metric key>", "delay":"<update period>" }, ... ] }
The
meric key
(key) parameter of each entry is the name of the metric (seeJabbixActiveMetric
) which value the server expects to receive periodically.The period of a metric value update is defined by the corresponding
update period
(delay) parameter.If the server is unable to send the requested active check list the server sends the message with an unsuccessful status and an optional comment (see
receiveMetricListResponse(JabbixReader)
).- Parameters:
reader
- a reader connected to a socket- Returns:
- a set of
JabbixActiveMetric
objects representing the active check list - Throws:
java.io.IOException
- if there was an I/O exception during the response receptionJabbixException
- if the server sent an unsuccessful statusJabbixProtocolException
- if the protocol was violated (i.e. an unexpected value was received)- See Also:
requestActiveCheckList(JabbixWriter,String)
,ZBX_PROTO_TAG_RESPONSE
,ZBX_PROTO_VALUE_SUCCESS
,ZBX_PROTO_TAG_DATA
,ZBX_PROTO_TAG_KEY
,ZBX_PROTO_TAG_DELAY
,ZBX_PROTO_VALUE_FAILED
-
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 (seereceiveMetricListResponse(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> }
Thehost name
(host) parameter is the name of the local host expected by the server (seeZabbixClient.getHostName()
).The
meric key
(key) parameter of each entry is the name of the metric (seeJabbixActiveMetric
) 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 specialmetric time stamp
(clock) entry parameter is used to explicitly state the update time (seeJabbixActiveMetric.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 sockethostName
- the name of the local hostmetrics
- 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 thestatus
(response) parameter is stated assuccess
. And thecomment
(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. Thecomment
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 receptionJabbixException
- if the server sent an unsuccessful statusJabbixProtocolException
- 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
-
-