Source
xxxxxxxxxx
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/******************************************************************************
* *
* Purpose: Zabbix destructor *
* *
******************************************************************************/
static duk_ret_t es_zabbix_dtor(duk_context *ctx)
{
ZBX_UNUSED(ctx);
return 0;
}
/******************************************************************************
* *
* Purpose: Zabbix constructor *
* *
******************************************************************************/
static duk_ret_t es_zabbix_ctor(duk_context *ctx)
{
if (!duk_is_constructor_call(ctx))
return DUK_RET_TYPE_ERROR;
duk_push_this(ctx);
duk_push_c_function(ctx, es_zabbix_dtor, 1);
duk_set_finalizer(ctx, -2);
return 0;
}
/******************************************************************************
* *
* Purpose: Zabbix.Status method *
* *
******************************************************************************/
static duk_ret_t es_zabbix_log(duk_context *ctx)
{
zbx_es_env_t *env;
char *message = NULL;
int level, err_index = -1;
duk_memory_functions out_funcs;
level = duk_to_int(ctx, 0);
if (SUCCEED != es_duktape_string_decode(duk_safe_to_string(ctx, 1), &message))
{
message = zbx_strdup(message, duk_safe_to_string(ctx, 1));
zbx_replace_invalid_utf8(message);
}
duk_get_memory_functions(ctx, &out_funcs);
env = (zbx_es_env_t *)out_funcs.udata;
if (ZBX_ES_LOG_MSG_LIMIT <= env->logged_msgs)
{
err_index = duk_push_error_object(ctx, DUK_RET_EVAL_ERROR,
"maximum count of logged messages was reached");
goto out;
}
zabbix_log(level, "%s", message);
if (NULL == env->json)
goto out;
if (ZBX_ES_LOG_MEMORY_LIMIT < env->json->buffer_size) /* approximate limit */
{
err_index = duk_push_error_object(ctx, DUK_RET_EVAL_ERROR, "log exceeds the maximum size of "
ZBX_FS_UI64 " bytes.", ZBX_ES_LOG_MEMORY_LIMIT);
goto out;