#include "zbxcommon.h"
#include "zbxrtc.h"
#include "zbx_rtc_constants.h"
#include "zbxserialize.h"
#include "zbxjson.h"
#include "zbxnix.h"
#include "zbxdiag.h"
#include "zbxstr.h"
#include "zbxnum.h"
#include "zbxalgo.h"
#include "zbxipcservice.h"
#include "zbxprof.h"
#include "zbxtime.h"
#include "zbxcachehistory.h"
ZBX_PTR_VECTOR_IMPL(rtc_sub, zbx_rtc_sub_t *)
ZBX_PTR_VECTOR_IMPL(rtc_hook, zbx_rtc_hook_t *)
static int zbx_json_getuint64(const char *tag, const struct zbx_json_parse *jp, zbx_uint64_t *itemid,
char **error)
{
char buffer[MAX_ID_LEN];
if (SUCCEED != zbx_json_value_by_name(jp, tag, buffer, sizeof(buffer), NULL) ||
SUCCEED != zbx_is_uint64(buffer, itemid))
{
*error = zbx_dsprintf(NULL, "cannot retrieve value of tag \"%s\"", tag);
return FAIL;
}
return SUCCEED;
}
static void rtc_history_cache_clear(const char *data, char **out)
{
struct zbx_json_parse jp;
zbx_uint64_t itemid;
int num;
if (FAIL == zbx_json_open(data, &jp))
{
*out = zbx_dsprintf(NULL, "Invalid parameter format \"%s\"\n", data);
return;
}
if (SUCCEED != zbx_json_getuint64(ZBX_PROTO_TAG_ITEMID, &jp, &itemid, out))
return;
if (FAIL == (num = zbx_hc_clear_item_middle(itemid)))
*out = zbx_dsprintf(NULL, "Cannot clear item from history cache: item is not in cache\n");
else
*out = zbx_dsprintf(NULL, "Cleared %d values from history cache\n", num);
}
int zbx_rtc_get_command_target(const char *data, pid_t *pid, int *proc_type, int *proc_num, int *scope,
char **result)
{
struct zbx_json_parse jp;
char buf[MAX_STRING_LEN];
if (FAIL == zbx_json_open(data, &jp))
{
*result = zbx_dsprintf(NULL, "Invalid parameters \"%s\"\n", data);
return FAIL;
}