Source
xxxxxxxxxx
void get_values_java(unsigned char request, const zbx_dc_item_t *items, AGENT_RESULT *results, int *errcodes, int num,
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
static int parse_response(AGENT_RESULT *results, int *errcodes, int num, char *response,
char *error, int max_error_len)
{
const char *p;
struct zbx_json_parse jp, jp_data, jp_row;
char *value = NULL;
size_t value_alloc = 0;
int i, ret = GATEWAY_ERROR;
if (SUCCEED == zbx_json_open(response, &jp))
{
if (SUCCEED != zbx_json_value_by_name_dyn(&jp, ZBX_PROTO_TAG_RESPONSE, &value, &value_alloc, NULL))
{
zbx_snprintf(error, max_error_len, "No '%s' tag in received JSON", ZBX_PROTO_TAG_RESPONSE);
goto exit;
}
if (0 == strcmp(value, ZBX_PROTO_VALUE_SUCCESS))
{
if (SUCCEED != zbx_json_brackets_by_name(&jp, ZBX_PROTO_TAG_DATA, &jp_data))
{
zbx_strlcpy(error, "Cannot open data array in received JSON", max_error_len);
goto exit;
}
p = NULL;
for (i = 0; i < num; i++)
{
if (SUCCEED != errcodes[i])
continue;
if (NULL == (p = zbx_json_next(&jp_data, p)))
{
zbx_strlcpy(error, "Not all values included in received JSON", max_error_len);
goto exit;
}
if (SUCCEED != zbx_json_brackets_open(p, &jp_row))
{
zbx_strlcpy(error, "Cannot open value object in received JSON", max_error_len);
goto exit;
}
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &value,
&value_alloc, NULL))
{
zbx_set_agent_result_type(&results[i], ITEM_VALUE_TYPE_TEXT, value);
errcodes[i] = SUCCEED;
}
else if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_ERROR, &value,
&value_alloc, NULL))
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, value));
errcodes[i] = NOTSUPPORTED;
}
else
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, "Cannot get item value or error message"));
errcodes[i] = AGENT_ERROR;
}
}
ret = SUCCEED;
}
else if (0 == strcmp(value, ZBX_PROTO_VALUE_FAILED))
{