// SPDX-License-Identifier: GPL-3.0-or-later
#include "pluginsd_parser.h"
/*
* This is the action defined for the FLUSH command
*/
PARSER_RC pluginsd_set_action(void *user, RRDSET *st, RRDDIM *rd, long long int value)
{
UNUSED(user);
rrddim_set_by_pointer(st, rd, value);
return PARSER_RC_OK;
}
PARSER_RC pluginsd_flush_action(void *user, RRDSET *st)
{
UNUSED(user);
UNUSED(st);
return PARSER_RC_OK;
}
PARSER_RC pluginsd_begin_action(void *user, RRDSET *st, usec_t microseconds, int trust_durations)
{
UNUSED(user);
if (likely(st->counter_done)) {
if (likely(microseconds)) {
if (trust_durations)
rrdset_next_usec_unfiltered(st, microseconds);
else
rrdset_next_usec(st, microseconds);
} else
rrdset_next(st);
}
return PARSER_RC_OK;
}
PARSER_RC pluginsd_end_action(void *user, RRDSET *st)
{
UNUSED(user);
rrdset_done(st);
return PARSER_RC_OK;
}
PARSER_RC pluginsd_chart_action(void *user, char *type, char *id, char *name, char *family, char *context, char *title, char *units, char *plugin,
char *module, int priority, int update_every, RRDSET_TYPE chart_type, char *options)
{
RRDSET *st = NULL;
RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
st = rrdset_create(
host, type, id, name, family, context, title, units,
plugin, module, priority, update_every,
chart_type);
if (options && *options) {
if (strstr(options, "obsolete"))
rrdset_is_obsolete(st);
else
rrdset_isnot_obsolete(st);
if (strstr(options, "detail"))
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
else
rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
if (strstr(options, "hidden"))
rrdset_flag_set(st, RRDSET_FLAG_HIDDEN);
else
rrdset_flag_clear(st, RRDSET_FLAG_HIDDEN);
if (strstr(options, "store_first"))
rrdset_flag_set(st, RRDSET_FLAG_STORE_FIRST);
else
rrdset_flag_clear(st, RRDSET_FLAG_STORE_FIRST);
} else {
rrdset_isnot_obsolete(st);
rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
rrdset_flag_clear(st, RRDSET_FLAG_STORE_FIRST);
}
((PARSER_USER_OBJECT *)user)->st = st;
return PARSER_RC_OK;
}
PARSER_RC pluginsd_disable_action(void *user)
{
UNUSED(user);
info("called DISABLE. Disabling it.");
((PARSER_USER_OBJECT *) user)->enabled = 0;
return PARSER_RC_ERROR;
}
PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global, calculated_number value)
{
UNUSED(user);
if (global) {
RRDVAR *rv = rrdvar_custom_host_variable_create(host, name);
if (rv)
rrdvar_custom_host_variable_set(host, rv, value);
else
error("cannot find/create HOST VARIABLE '%s' on host '%s'", name, host->hostname);
} else {
RRDSETVAR *rs = rrdsetvar_custom_chart_variable_create(st, name);
if (rs)
rrdsetvar_custom_chart_variable_set(rs, value);
else
error("cannot find/create CHART VARIABLE '%s' on host '%s', chart '%s'", name, host->hostname, st->id);
}
return PARSER_RC_OK;
}
PARSER_RC pluginsd_dimension_action(void *user, RRDSET *st, char *id, char *name, char *algorithm, long multiplier, long divisor, char *options,
RRD_ALGORITHM algorithm_type)
{
UNUSED(user);
UNUSED(algorithm);
RRDDIM *rd = rrddim_add(st, id, name, multiplier, divisor, algorithm_type);
int unhide_dimension = 1;
rrddim_flag_clear(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
if (options && *options) {
if (strstr(options, "obsolete") != NULL)
rrddim_is_obsolete(st, rd);
else
rrddim_isnot_obsolete(st, rd);
unhide_dimension = !strstr(options, "hidden");
if (strstr(options,