pluginsd_parser.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "pluginsd_parser.h"
  3. /*
  4. * This is the action defined for the FLUSH command
  5. */
  6. PARSER_RC pluginsd_set_action(void *user, RRDSET *st, RRDDIM *rd, long long int value)
  7. {
  8. UNUSED(user);
  9. rrddim_set_by_pointer(st, rd, value);
  10. return PARSER_RC_OK;
  11. }
  12. PARSER_RC pluginsd_flush_action(void *user, RRDSET *st)
  13. {
  14. UNUSED(user);
  15. UNUSED(st);
  16. return PARSER_RC_OK;
  17. }
  18. PARSER_RC pluginsd_begin_action(void *user, RRDSET *st, usec_t microseconds, int trust_durations)
  19. {
  20. UNUSED(user);
  21. if (likely(st->counter_done)) {
  22. if (likely(microseconds)) {
  23. if (trust_durations)
  24. rrdset_next_usec_unfiltered(st, microseconds);
  25. else
  26. rrdset_next_usec(st, microseconds);
  27. } else
  28. rrdset_next(st);
  29. }
  30. return PARSER_RC_OK;
  31. }
  32. PARSER_RC pluginsd_end_action(void *user, RRDSET *st)
  33. {
  34. UNUSED(user);
  35. rrdset_done(st);
  36. return PARSER_RC_OK;
  37. }
  38. PARSER_RC pluginsd_chart_action(void *user, char *type, char *id, char *name, char *family, char *context, char *title, char *units, char *plugin,
  39. char *module, int priority, int update_every, RRDSET_TYPE chart_type, char *options)
  40. {
  41. RRDSET *st = NULL;
  42. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  43. st = rrdset_create(
  44. host, type, id, name, family, context, title, units,
  45. plugin, module, priority, update_every,
  46. chart_type);
  47. if (options && *options) {
  48. if (strstr(options, "obsolete"))
  49. rrdset_is_obsolete(st);
  50. else
  51. rrdset_isnot_obsolete(st);
  52. if (strstr(options, "detail"))
  53. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  54. else
  55. rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
  56. if (strstr(options, "hidden"))
  57. rrdset_flag_set(st, RRDSET_FLAG_HIDDEN);
  58. else
  59. rrdset_flag_clear(st, RRDSET_FLAG_HIDDEN);
  60. if (strstr(options, "store_first"))
  61. rrdset_flag_set(st, RRDSET_FLAG_STORE_FIRST);
  62. else
  63. rrdset_flag_clear(st, RRDSET_FLAG_STORE_FIRST);
  64. } else {
  65. rrdset_isnot_obsolete(st);
  66. rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
  67. rrdset_flag_clear(st, RRDSET_FLAG_STORE_FIRST);
  68. }
  69. ((PARSER_USER_OBJECT *)user)->st = st;
  70. return PARSER_RC_OK;
  71. }
  72. PARSER_RC pluginsd_disable_action(void *user)
  73. {
  74. UNUSED(user);
  75. info("called DISABLE. Disabling it.");
  76. ((PARSER_USER_OBJECT *) user)->enabled = 0;
  77. return PARSER_RC_ERROR;
  78. }
  79. PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global, calculated_number value)
  80. {
  81. UNUSED(user);
  82. if (global) {
  83. RRDVAR *rv = rrdvar_custom_host_variable_create(host, name);
  84. if (rv)
  85. rrdvar_custom_host_variable_set(host, rv, value);
  86. else
  87. error("cannot find/create HOST VARIABLE '%s' on host '%s'", name, host->hostname);
  88. } else {
  89. RRDSETVAR *rs = rrdsetvar_custom_chart_variable_create(st, name);
  90. if (rs)
  91. rrdsetvar_custom_chart_variable_set(rs, value);
  92. else
  93. error("cannot find/create CHART VARIABLE '%s' on host '%s', chart '%s'", name, host->hostname, st->id);
  94. }
  95. return PARSER_RC_OK;
  96. }
  97. PARSER_RC pluginsd_dimension_action(void *user, RRDSET *st, char *id, char *name, char *algorithm, long multiplier, long divisor, char *options,
  98. RRD_ALGORITHM algorithm_type)
  99. {
  100. UNUSED(user);
  101. UNUSED(algorithm);
  102. RRDDIM *rd = rrddim_add(st, id, name, multiplier, divisor, algorithm_type);
  103. rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
  104. rrddim_flag_clear(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
  105. if (options && *options) {
  106. if (strstr(options, "obsolete") != NULL)
  107. rrddim_is_obsolete(st, rd);
  108. else
  109. rrddim_isnot_obsolete(st, rd);
  110. if (strstr(options, "hidden") != NULL)
  111. rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
  112. if (strstr(options, "noreset") != NULL)
  113. rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
  114. if (strstr(options, "nooverflow") != NULL)
  115. rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
  116. } else {
  117. rrddim_isnot_obsolete(st, rd);
  118. }
  119. return PARSER_RC_OK;
  120. }
  121. PARSER_RC pluginsd_label_action(void *user, char *key, char *value, LABEL_SOURCE source)
  122. {
  123. ((PARSER_USER_OBJECT *) user)->new_labels = add_label_to_list(((PARSER_USER_OBJECT *) user)->new_labels, key, value, source);
  124. return PARSER_RC_OK;
  125. }
  126. PARSER_RC pluginsd_overwrite_action(void *user, RRDHOST *host, struct label *new_labels)
  127. {
  128. UNUSED(user);
  129. if (!host->labels) {
  130. host->labels = new_labels;
  131. } else {
  132. rrdhost_rdlock(host);
  133. replace_label_list(host, new_labels);
  134. rrdhost_unlock(host);
  135. }
  136. return PARSER_RC_OK;
  137. }
  138. PARSER_RC pluginsd_set(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  139. {
  140. char *dimension = words[1];
  141. char *value = words[2];
  142. RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
  143. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  144. if (unlikely(!dimension || !*dimension)) {
  145. error("requested a SET on chart '%s' of host '%s', without a dimension. Disabling it.", st->id, host->hostname);
  146. goto disable;
  147. }
  148. if (unlikely(!value || !*value))
  149. value = NULL;
  150. if (unlikely(!st)) {
  151. error(
  152. "requested a SET on dimension %s with value %s on host '%s', without a BEGIN. Disabling it.", dimension,
  153. value ? value : "<nothing>", host->hostname);
  154. goto disable;
  155. }
  156. if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
  157. debug(D_PLUGINSD, "is setting dimension %s/%s to %s", st->id, dimension, value ? value : "<nothing>");
  158. if (value) {
  159. RRDDIM *rd = rrddim_find(st, dimension);
  160. if (unlikely(!rd)) {
  161. error(
  162. "requested a SET to dimension with id '%s' on stats '%s' (%s) on host '%s', which does not exist. Disabling it.",
  163. dimension, st->name, st->id, st->rrdhost->hostname);
  164. goto disable;
  165. } else {
  166. if (plugins_action->set_action) {
  167. return plugins_action->set_action(
  168. user, st, rd, strtoll(value, NULL, 0));
  169. }
  170. }
  171. }
  172. return PARSER_RC_OK;
  173. disable:
  174. ((PARSER_USER_OBJECT *) user)->enabled = 0;
  175. return PARSER_RC_ERROR;
  176. }
  177. PARSER_RC pluginsd_begin(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  178. {
  179. char *id = words[1];
  180. char *microseconds_txt = words[2];
  181. RRDSET *st = NULL;
  182. RRDHOST *host = ((PARSER_USER_OBJECT *)user)->host;
  183. if (unlikely(!id)) {
  184. error("requested a BEGIN without a chart id for host '%s'. Disabling it.", host->hostname);
  185. goto disable;
  186. }
  187. st = rrdset_find(host, id);
  188. if (unlikely(!st)) {
  189. error("requested a BEGIN on chart '%s', which does not exist on host '%s'. Disabling it.", id, host->hostname);
  190. goto disable;
  191. }
  192. ((PARSER_USER_OBJECT *)user)->st = st;
  193. usec_t microseconds = 0;
  194. if (microseconds_txt && *microseconds_txt)
  195. microseconds = str2ull(microseconds_txt);
  196. if (plugins_action->begin_action) {
  197. return plugins_action->begin_action(user, st, microseconds,
  198. ((PARSER_USER_OBJECT *)user)->trust_durations);
  199. }
  200. return PARSER_RC_OK;
  201. disable:
  202. ((PARSER_USER_OBJECT *)user)->enabled = 0;
  203. return PARSER_RC_ERROR;
  204. }
  205. PARSER_RC pluginsd_end(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  206. {
  207. UNUSED(words);
  208. RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
  209. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  210. if (unlikely(!st)) {
  211. error("requested an END, without a BEGIN on host '%s'. Disabling it.", host->hostname);
  212. ((PARSER_USER_OBJECT *) user)->enabled = 0;
  213. return PARSER_RC_ERROR;
  214. }
  215. if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
  216. debug(D_PLUGINSD, "requested an END on chart %s", st->id);
  217. ((PARSER_USER_OBJECT *) user)->st = NULL;
  218. ((PARSER_USER_OBJECT *) user)->count++;
  219. if (plugins_action->end_action) {
  220. return plugins_action->end_action(user, st);
  221. }
  222. return PARSER_RC_OK;
  223. }
  224. PARSER_RC pluginsd_chart(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  225. {
  226. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  227. char *type = words[1];
  228. char *name = words[2];
  229. char *title = words[3];
  230. char *units = words[4];
  231. char *family = words[5];
  232. char *context = words[6];
  233. char *chart = words[7];
  234. char *priority_s = words[8];
  235. char *update_every_s = words[9];
  236. char *options = words[10];
  237. char *plugin = words[11];
  238. char *module = words[12];
  239. int have_action = ((plugins_action->chart_action) != NULL);
  240. // parse the id from type
  241. char *id = NULL;
  242. if (likely(type && (id = strchr(type, '.')))) {
  243. *id = '\0';
  244. id++;
  245. }
  246. // make sure we have the required variables
  247. if (unlikely((!type || !*type || !id || !*id))) {
  248. error("requested a CHART, without a type.id, on host '%s'. Disabling it.", host->hostname);
  249. ((PARSER_USER_OBJECT *) user)->enabled = 0;
  250. return PARSER_RC_ERROR;
  251. }
  252. // parse the name, and make sure it does not include 'type.'
  253. if (unlikely(name && *name)) {
  254. // when data are coming from slaves
  255. // name will be type.name
  256. // so we have to remove 'type.' from name too
  257. size_t len = strlen(type);
  258. if (strncmp(type, name, len) == 0 && name[len] == '.')
  259. name = &name[len + 1];
  260. // if the name is the same with the id,
  261. // or is just 'NULL', clear it.
  262. if (unlikely(strcmp(name, id) == 0 || strcasecmp(name, "NULL") == 0 || strcasecmp(name, "(NULL)") == 0))
  263. name = NULL;
  264. }
  265. int priority = 1000;
  266. if (likely(priority_s && *priority_s))
  267. priority = str2i(priority_s);
  268. int update_every = ((PARSER_USER_OBJECT *) user)->cd->update_every;
  269. if (likely(update_every_s && *update_every_s))
  270. update_every = str2i(update_every_s);
  271. if (unlikely(!update_every))
  272. update_every = ((PARSER_USER_OBJECT *) user)->cd->update_every;
  273. RRDSET_TYPE chart_type = RRDSET_TYPE_LINE;
  274. if (unlikely(chart))
  275. chart_type = rrdset_type_id(chart);
  276. if (unlikely(name && !*name))
  277. name = NULL;
  278. if (unlikely(family && !*family))
  279. family = NULL;
  280. if (unlikely(context && !*context))
  281. context = NULL;
  282. if (unlikely(!title))
  283. title = "";
  284. if (unlikely(!units))
  285. units = "unknown";
  286. debug(
  287. D_PLUGINSD,
  288. "creating chart type='%s', id='%s', name='%s', family='%s', context='%s', chart='%s', priority=%d, update_every=%d",
  289. type, id, name ? name : "", family ? family : "", context ? context : "", rrdset_type_name(chart_type),
  290. priority, update_every);
  291. if (have_action) {
  292. return plugins_action->chart_action(
  293. user, type, id, name, family, context, title, units,
  294. (plugin && *plugin) ? plugin : ((PARSER_USER_OBJECT *)user)->cd->filename, module, priority, update_every,
  295. chart_type, options);
  296. }
  297. return PARSER_RC_OK;
  298. }
  299. PARSER_RC pluginsd_dimension(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  300. {
  301. char *id = words[1];
  302. char *name = words[2];
  303. char *algorithm = words[3];
  304. char *multiplier_s = words[4];
  305. char *divisor_s = words[5];
  306. char *options = words[6];
  307. RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
  308. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  309. if (unlikely(!id)) {
  310. error(
  311. "requested a DIMENSION, without an id, host '%s' and chart '%s'. Disabling it.", host->hostname,
  312. st ? st->id : "UNSET");
  313. goto disable;
  314. }
  315. if (unlikely(!st)) {
  316. error("requested a DIMENSION, without a CHART, on host '%s'. Disabling it.", host->hostname);
  317. goto disable;
  318. }
  319. long multiplier = 1;
  320. if (multiplier_s && *multiplier_s) {
  321. multiplier = strtol(multiplier_s, NULL, 0);
  322. if (unlikely(!multiplier))
  323. multiplier = 1;
  324. }
  325. long divisor = 1;
  326. if (likely(divisor_s && *divisor_s)) {
  327. divisor = strtol(divisor_s, NULL, 0);
  328. if (unlikely(!divisor))
  329. divisor = 1;
  330. }
  331. if (unlikely(!algorithm || !*algorithm))
  332. algorithm = "absolute";
  333. if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
  334. debug(
  335. D_PLUGINSD,
  336. "creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'",
  337. st->id, id, name ? name : "", rrd_algorithm_name(rrd_algorithm_id(algorithm)), multiplier, divisor,
  338. options ? options : "");
  339. if (plugins_action->dimension_action) {
  340. return plugins_action->dimension_action(
  341. user, st, id, name, algorithm,
  342. multiplier, divisor, (options && *options)?options:NULL, rrd_algorithm_id(algorithm));
  343. }
  344. return PARSER_RC_OK;
  345. disable:
  346. ((PARSER_USER_OBJECT *)user)->enabled = 0;
  347. return PARSER_RC_ERROR;
  348. }
  349. PARSER_RC pluginsd_variable(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  350. {
  351. char *name = words[1];
  352. char *value = words[2];
  353. calculated_number v;
  354. RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
  355. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  356. int global = (st) ? 0 : 1;
  357. if (name && *name) {
  358. if ((strcmp(name, "GLOBAL") == 0 || strcmp(name, "HOST") == 0)) {
  359. global = 1;
  360. name = words[2];
  361. value = words[3];
  362. } else if ((strcmp(name, "LOCAL") == 0 || strcmp(name, "CHART") == 0)) {
  363. global = 0;
  364. name = words[2];
  365. value = words[3];
  366. }
  367. }
  368. if (unlikely(!name || !*name)) {
  369. error("requested a VARIABLE on host '%s', without a variable name. Disabling it.", host->hostname);
  370. ((PARSER_USER_OBJECT *)user)->enabled = 0;
  371. return PARSER_RC_ERROR;
  372. }
  373. if (unlikely(!value || !*value))
  374. value = NULL;
  375. if (unlikely(!value)) {
  376. error("cannot set %s VARIABLE '%s' on host '%s' to an empty value", (global) ? "HOST" : "CHART", name,
  377. host->hostname);
  378. return PARSER_RC_OK;
  379. }
  380. if (!global && !st) {
  381. error("cannot find/create CHART VARIABLE '%s' on host '%s' without a chart", name, host->hostname);
  382. return PARSER_RC_OK;
  383. }
  384. char *endptr = NULL;
  385. v = (calculated_number)str2ld(value, &endptr);
  386. if (unlikely(endptr && *endptr)) {
  387. if (endptr == value)
  388. error(
  389. "the value '%s' of VARIABLE '%s' on host '%s' cannot be parsed as a number", value, name,
  390. host->hostname);
  391. else
  392. error(
  393. "the value '%s' of VARIABLE '%s' on host '%s' has leftovers: '%s'", value, name, host->hostname,
  394. endptr);
  395. }
  396. if (plugins_action->variable_action) {
  397. return plugins_action->variable_action(user, host, st, name, global, v);
  398. }
  399. return PARSER_RC_OK;
  400. }
  401. PARSER_RC pluginsd_flush(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  402. {
  403. UNUSED(words);
  404. debug(D_PLUGINSD, "requested a FLUSH");
  405. RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
  406. ((PARSER_USER_OBJECT *) user)->st = NULL;
  407. if (plugins_action->flush_action) {
  408. return plugins_action->flush_action(user, st);
  409. }
  410. return PARSER_RC_OK;
  411. }
  412. PARSER_RC pluginsd_disable(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  413. {
  414. UNUSED(user);
  415. UNUSED(words);
  416. if (plugins_action->disable_action) {
  417. return plugins_action->disable_action(user);
  418. }
  419. return PARSER_RC_ERROR;
  420. }
  421. PARSER_RC pluginsd_label(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  422. {
  423. char *store;
  424. if (!words[4])
  425. store = words[3];
  426. else {
  427. store = callocz(PLUGINSD_LINE_MAX + 1, sizeof(char));
  428. size_t remaining = PLUGINSD_LINE_MAX;
  429. char *move = store;
  430. int i = 3;
  431. while (i < PLUGINSD_MAX_WORDS) {
  432. size_t length = strlen(words[i]);
  433. if ((length + 1) >= remaining)
  434. break;
  435. remaining -= (length + 1);
  436. memcpy(move, words[i], length);
  437. move += length;
  438. *move++ = ' ';
  439. i++;
  440. if (!words[i])
  441. break;
  442. }
  443. }
  444. if (plugins_action->label_action) {
  445. PARSER_RC rc = plugins_action->label_action(user, words[1], store, strtol(words[2], NULL, 10));
  446. if (store != words[3])
  447. freez(store);
  448. return rc;
  449. }
  450. if (store != words[3])
  451. freez(store);
  452. return PARSER_RC_OK;
  453. }
  454. PARSER_RC pluginsd_overwrite(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  455. {
  456. UNUSED(words);
  457. RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
  458. debug(D_PLUGINSD, "requested a OVERWITE a variable");
  459. struct label *new_labels = ((PARSER_USER_OBJECT *)user)->new_labels;
  460. ((PARSER_USER_OBJECT *)user)->new_labels = NULL;
  461. if (plugins_action->overwrite_action) {
  462. return plugins_action->overwrite_action(user, host, new_labels);
  463. }
  464. return PARSER_RC_OK;
  465. }
  466. PARSER_RC pluginsd_guid(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  467. {
  468. char *uuid_str = words[1];
  469. uuid_t uuid;
  470. if (unlikely(!uuid_str)) {
  471. error("requested a GUID, without a uuid.");
  472. return PARSER_RC_ERROR;
  473. }
  474. if (unlikely(strlen(uuid_str) != GUID_LEN || uuid_parse(uuid_str, uuid) == -1)) {
  475. error("requested a GUID, without a valid uuid string.");
  476. return PARSER_RC_ERROR;
  477. }
  478. debug(D_PLUGINSD, "Parsed uuid=%s", uuid_str);
  479. if (plugins_action->guid_action) {
  480. return plugins_action->guid_action(user, &uuid);
  481. }
  482. return PARSER_RC_OK;
  483. }
  484. PARSER_RC pluginsd_context(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  485. {
  486. char *uuid_str = words[1];
  487. uuid_t uuid;
  488. if (unlikely(!uuid_str)) {
  489. error("requested a CONTEXT, without a uuid.");
  490. return PARSER_RC_ERROR;
  491. }
  492. if (unlikely(strlen(uuid_str) != GUID_LEN || uuid_parse(uuid_str, uuid) == -1)) {
  493. error("requested a CONTEXT, without a valid uuid string.");
  494. return PARSER_RC_ERROR;
  495. }
  496. debug(D_PLUGINSD, "Parsed uuid=%s", uuid_str);
  497. if (plugins_action->context_action) {
  498. return plugins_action->context_action(user, &uuid);
  499. }
  500. return PARSER_RC_OK;
  501. }
  502. PARSER_RC pluginsd_tombstone(char **words, void *user, PLUGINSD_ACTION *plugins_action)
  503. {
  504. char *uuid_str = words[1];
  505. uuid_t uuid;
  506. if (unlikely(!uuid_str)) {
  507. error("requested a TOMBSTONE, without a uuid.");
  508. return PARSER_RC_ERROR;
  509. }
  510. if (unlikely(strlen(uuid_str) != GUID_LEN || uuid_parse(uuid_str, uuid) == -1)) {
  511. error("requested a TOMBSTONE, without a valid uuid string.");
  512. return PARSER_RC_ERROR;
  513. }
  514. debug(D_PLUGINSD, "Parsed uuid=%s", uuid_str);
  515. if (plugins_action->tombstone_action) {
  516. return plugins_action->tombstone_action(user, &uuid);
  517. }
  518. return PARSER_RC_OK;
  519. }
  520. // New plugins.d parser
  521. inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int trust_durations)
  522. {
  523. int enabled = cd->enabled;
  524. if (!fp || !enabled) {
  525. cd->enabled = 0;
  526. return 0;
  527. }
  528. if (unlikely(fileno(fp) == -1)) {
  529. error("file descriptor given is not a valid stream");
  530. cd->serial_failures++;
  531. return 0;
  532. }
  533. clearerr(fp);
  534. PARSER_USER_OBJECT *user = callocz(1, sizeof(*user));
  535. ((PARSER_USER_OBJECT *) user)->enabled = cd->enabled;
  536. ((PARSER_USER_OBJECT *) user)->host = host;
  537. ((PARSER_USER_OBJECT *) user)->cd = cd;
  538. ((PARSER_USER_OBJECT *) user)->trust_durations = trust_durations;
  539. PARSER *parser = parser_init(host, user, fp, PARSER_INPUT_SPLIT);
  540. if (unlikely(!parser)) {
  541. error("Failed to initialize parser");
  542. cd->serial_failures++;
  543. return 0;
  544. }
  545. parser->plugins_action->begin_action = &pluginsd_begin_action;
  546. parser->plugins_action->flush_action = &pluginsd_flush_action;
  547. parser->plugins_action->end_action = &pluginsd_end_action;
  548. parser->plugins_action->disable_action = &pluginsd_disable_action;
  549. parser->plugins_action->variable_action = &pluginsd_variable_action;
  550. parser->plugins_action->dimension_action = &pluginsd_dimension_action;
  551. parser->plugins_action->label_action = &pluginsd_label_action;
  552. parser->plugins_action->overwrite_action = &pluginsd_overwrite_action;
  553. parser->plugins_action->chart_action = &pluginsd_chart_action;
  554. parser->plugins_action->set_action = &pluginsd_set_action;
  555. user->parser = parser;
  556. while (likely(!parser_next(parser))) {
  557. if (unlikely(netdata_exit || parser_action(parser, NULL)))
  558. break;
  559. }
  560. info("PARSER ended");
  561. parser_destroy(parser);
  562. cd->enabled = ((PARSER_USER_OBJECT *) user)->enabled;
  563. size_t count = ((PARSER_USER_OBJECT *) user)->count;
  564. freez(user);
  565. if (likely(count)) {
  566. cd->successful_collections += count;
  567. cd->serial_failures = 0;
  568. } else
  569. cd->serial_failures++;
  570. return count;
  571. }