Exemplo n.º 1
0
/******************************************************************************
 *                                                                            *
 * Function: get_value_aggregate                                              *
 *                                                                            *
 * Purpose: retrieve data from Zabbix server (aggregate items)                *
 *                                                                            *
 * Parameters: item - item we are interested in                               *
 *                                                                            *
 * Return value: SUCCEED - data successfully retrieved and stored in result   *
 *                         and result_str (as string)                         *
 *               NOTSUPPORTED - requested item is not supported               *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int	get_value_aggregate(DC_ITEM *item, AGENT_RESULT *result)
{
	const char	*__function_name = "get_value_aggregate";
	char		key[8], params[MAX_STRING_LEN],
			groups[MAX_STRING_LEN], itemkey[MAX_STRING_LEN], func[8], funcp[32];
	int		ret = SUCCEED;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() key:'%s'", __function_name, item->key_orig);

	init_result(result);

	if (2 != parse_command(item->key, key, sizeof(key), params, sizeof(params)))
		return NOTSUPPORTED;

	if (num_param(params) != 4)
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters"));
		return NOTSUPPORTED;
	}

	if (0 != get_param(params, 1, groups, sizeof(groups)))
		return NOTSUPPORTED;

	if (0 != get_param(params, 2, itemkey, sizeof(itemkey)))
		return NOTSUPPORTED;

	if (0 != get_param(params, 3, func, sizeof(func)))
		return NOTSUPPORTED;

	if (0 != get_param(params, 4, funcp, sizeof(funcp)))
		return NOTSUPPORTED;

	if (SUCCEED != evaluate_aggregate(result, key, groups, itemkey, func, funcp))
		ret = NOTSUPPORTED;

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
/******************************************************************************
 *                                                                            *
 * Function: get_value_aggregate                                              *
 *                                                                            *
 * Purpose: retrieve data from Zabbix server (aggregate items)                *
 *                                                                            *
 * Parameters: item - item we are interested in                               *
 *                                                                            *
 * Return value: SUCCEED - data successfully retrieved and stored in result   *
 *                         and result_str (as string)                         *
 *               NOTSUPPORTED - requested item is not supported               *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int	get_value_aggregate(DC_ITEM *item, AGENT_RESULT *result)
{
    const char	*__function_name = "get_value_aggregate";

    char		tmp[8], params[MAX_STRING_LEN], groups[MAX_STRING_LEN], itemkey[MAX_STRING_LEN], funcp[32];
    int		grp_func, item_func, ret = SUCCEED;

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() key:'%s'", __function_name, item->key_orig);

    if (ITEM_VALUE_TYPE_FLOAT != item->value_type && ITEM_VALUE_TYPE_UINT64 != item->value_type)
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Value type must be Numeric for aggregate items"));
        return NOTSUPPORTED;
    }

    if (2 != parse_command(item->key, tmp, sizeof(tmp), params, sizeof(params)))
        return NOTSUPPORTED;

    if (0 == strcmp(tmp, "grpmin"))
        grp_func = ZBX_GRP_FUNC_MIN;
    else if (0 == strcmp(tmp, "grpavg"))
        grp_func = ZBX_GRP_FUNC_AVG;
    else if (0 == strcmp(tmp, "grpmax"))
        grp_func = ZBX_GRP_FUNC_MAX;
    else if (0 == strcmp(tmp, "grpsum"))
        grp_func = ZBX_GRP_FUNC_SUM;
    else
        return NOTSUPPORTED;

    if (4 != num_param(params))
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters"));
        return NOTSUPPORTED;
    }

    if (0 != get_param(params, 1, groups, sizeof(groups)))
        return NOTSUPPORTED;

    if (0 != get_param(params, 2, itemkey, sizeof(itemkey)))
        return NOTSUPPORTED;

    if (0 != get_param(params, 3, tmp, sizeof(tmp)))
        return NOTSUPPORTED;

    if (0 == strcmp(tmp, "min"))
        item_func = ZBX_DB_GET_HIST_MIN;
    else if (0 == strcmp(tmp, "avg"))
        item_func = ZBX_DB_GET_HIST_AVG;
    else if (0 == strcmp(tmp, "max"))
        item_func = ZBX_DB_GET_HIST_MAX;
    else if (0 == strcmp(tmp, "sum"))
        item_func = ZBX_DB_GET_HIST_SUM;
    else if (0 == strcmp(tmp, "count"))
        item_func = ZBX_DB_GET_HIST_COUNT;
    else if (0 == strcmp(tmp, "last"))
        item_func = ZBX_DB_GET_HIST_VALUE;
    else
    {
        SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter"));
        return NOTSUPPORTED;
    }

    if (0 != get_param(params, 4, funcp, sizeof(funcp)))
        return NOTSUPPORTED;

    if (SUCCEED != evaluate_aggregate(item, result, grp_func, groups, itemkey, item_func, funcp))
        ret = NOTSUPPORTED;

    zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

    return ret;
}
Exemplo n.º 3
0
/******************************************************************************
 *                                                                            *
 * Function: get_value_aggregate                                              *
 *                                                                            *
 * Purpose: retrieve data from Zabbix server (aggregate items)                *
 *                                                                            *
 * Parameters: item - item we are interested in                               *
 *                                                                            *
 * Return value: SUCCEED - data successfully retrieved and stored in result   *
 *                         and result_str (as string)                         *
 *               NOTSUPPORTED - requested item is not supported               *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 ******************************************************************************/
int	get_value_aggregate(DC_ITEM *item, AGENT_RESULT *result)
{
	const char	*__function_name = "get_value_aggregate";

	AGENT_REQUEST	request;
	int		ret = NOTSUPPORTED;
	const char	*tmp, *groups, *itemkey, *funcp = NULL;
	int		grp_func, item_func, params_num;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() key:'%s'", __function_name, item->key_orig);

	init_request(&request);

	if (ITEM_VALUE_TYPE_FLOAT != item->value_type && ITEM_VALUE_TYPE_UINT64 != item->value_type)
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Value type must be Numeric for aggregate items"));
		goto out;
	}

	if (SUCCEED != parse_item_key(item->key, &request))
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item key format."));
		goto out;
	}

	if (0 == strcmp(get_rkey(&request), "grpmin"))
	{
		grp_func = ZBX_VALUE_FUNC_MIN;
	}
	else if (0 == strcmp(get_rkey(&request), "grpavg"))
	{
		grp_func = ZBX_VALUE_FUNC_AVG;
	}
	else if (0 == strcmp(get_rkey(&request), "grpmax"))
	{
		grp_func = ZBX_VALUE_FUNC_MAX;
	}
	else if (0 == strcmp(get_rkey(&request), "grpsum"))
	{
		grp_func = ZBX_VALUE_FUNC_SUM;
	}
	else
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item key."));
		goto out;
	}

	params_num = get_rparams_num(&request);

	if (3 > params_num || params_num > 4)
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
		goto out;
	}

	groups = get_rparam(&request, 0);
	itemkey = get_rparam(&request, 1);
	tmp = get_rparam(&request, 2);

	if (0 == strcmp(tmp, "min"))
		item_func = ZBX_VALUE_FUNC_MIN;
	else if (0 == strcmp(tmp, "avg"))
		item_func = ZBX_VALUE_FUNC_AVG;
	else if (0 == strcmp(tmp, "max"))
		item_func = ZBX_VALUE_FUNC_MAX;
	else if (0 == strcmp(tmp, "sum"))
		item_func = ZBX_VALUE_FUNC_SUM;
	else if (0 == strcmp(tmp, "count"))
		item_func = ZBX_VALUE_FUNC_COUNT;
	else if (0 == strcmp(tmp, "last"))
		item_func = ZBX_VALUE_FUNC_LAST;
	else
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
		goto out;
	}

	if (4 == params_num)
	{
		funcp = get_rparam(&request, 3);
	}
	else if (3 == params_num && ZBX_VALUE_FUNC_LAST != item_func)
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
		goto out;
	}

	if (SUCCEED != evaluate_aggregate(item, result, grp_func, groups, itemkey, item_func, funcp))
		goto out;

	ret = SUCCEED;
out:
	free_request(&request);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}