dyncfg.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef LIBNETDATA_DYNCFG_H
  3. #define LIBNETDATA_DYNCFG_H
  4. #define DYNCFG_VERSION (size_t)1
  5. #define DYNCFG_RESP_SUCCESS(code) (code >= 200 && code <= 299)
  6. #define DYNCFG_RESP_RUNNING 200 // accepted and running
  7. #define DYNCFG_RESP_ACCEPTED 202 // accepted, but not running yet
  8. #define DYNCFG_RESP_ACCEPTED_RESTART_REQUIRED 299 // accepted, but restart is required to apply it
  9. typedef enum __attribute__((packed)) {
  10. DYNCFG_TYPE_SINGLE = 0,
  11. DYNCFG_TYPE_TEMPLATE,
  12. DYNCFG_TYPE_JOB,
  13. } DYNCFG_TYPE;
  14. DYNCFG_TYPE dyncfg_type2id(const char *type);
  15. const char *dyncfg_id2type(DYNCFG_TYPE type);
  16. typedef enum __attribute__((packed)) {
  17. DYNCFG_SOURCE_TYPE_INTERNAL = 0,
  18. DYNCFG_SOURCE_TYPE_STOCK,
  19. DYNCFG_SOURCE_TYPE_USER,
  20. DYNCFG_SOURCE_TYPE_DYNCFG,
  21. DYNCFG_SOURCE_TYPE_DISCOVERED,
  22. } DYNCFG_SOURCE_TYPE;
  23. DYNCFG_SOURCE_TYPE dyncfg_source_type2id(const char *source_type);
  24. const char *dyncfg_id2source_type(DYNCFG_SOURCE_TYPE source_type);
  25. typedef enum __attribute__((packed)) {
  26. DYNCFG_STATUS_NONE = 0,
  27. DYNCFG_STATUS_ACCEPTED, // the plugin has accepted the configuration
  28. DYNCFG_STATUS_RUNNING, // the plugin runs the accepted configuration
  29. DYNCFG_STATUS_FAILED, // the plugin fails to run the accepted configuration
  30. DYNCFG_STATUS_DISABLED, // the configuration is disabled by a user
  31. DYNCFG_STATUS_ORPHAN, // no plugin has claimed this configurations
  32. DYNCFG_STATUS_INCOMPLETE, // a special kind of failed configuration
  33. } DYNCFG_STATUS;
  34. DYNCFG_STATUS dyncfg_status2id(const char *status);
  35. const char *dyncfg_id2status(DYNCFG_STATUS status);
  36. typedef enum __attribute__((packed)) {
  37. DYNCFG_CMD_NONE = 0,
  38. DYNCFG_CMD_GET = (1 << 0),
  39. DYNCFG_CMD_SCHEMA = (1 << 1),
  40. DYNCFG_CMD_UPDATE = (1 << 2),
  41. DYNCFG_CMD_ADD = (1 << 3),
  42. DYNCFG_CMD_TEST = (1 << 4),
  43. DYNCFG_CMD_REMOVE = (1 << 5),
  44. DYNCFG_CMD_ENABLE = (1 << 6),
  45. DYNCFG_CMD_DISABLE = (1 << 7),
  46. DYNCFG_CMD_RESTART = (1 << 8),
  47. } DYNCFG_CMDS;
  48. DYNCFG_CMDS dyncfg_cmds2id(const char *cmds);
  49. void dyncfg_cmds2buffer(DYNCFG_CMDS cmds, struct web_buffer *wb);
  50. void dyncfg_cmds2json_array(DYNCFG_CMDS cmds, const char *key, struct web_buffer *wb);
  51. void dyncfg_cmds2fp(DYNCFG_CMDS cmds, FILE *fp);
  52. const char *dyncfg_id2cmd_one(DYNCFG_CMDS cmd);
  53. bool dyncfg_is_valid_id(const char *id);
  54. char *dyncfg_escape_id_for_filename(const char *id);
  55. #include "../clocks/clocks.h"
  56. #include "../buffer/buffer.h"
  57. #include "../dictionary/dictionary.h"
  58. typedef int (*dyncfg_cb_t)(const char *transaction, const char *id, DYNCFG_CMDS cmd, BUFFER *payload, usec_t *stop_monotonic_ut, bool *cancelled, BUFFER *result, const char *source, void *data);
  59. struct dyncfg_node {
  60. DYNCFG_TYPE type;
  61. DYNCFG_CMDS cmds;
  62. dyncfg_cb_t cb;
  63. void *data;
  64. };
  65. #define dyncfg_nodes_dictionary_create() dictionary_create_advanced(DICT_OPTION_FIXED_SIZE, NULL, sizeof(struct dyncfg_node))
  66. int dyncfg_default_response(BUFFER *wb, int code, const char *msg);
  67. int dyncfg_node_find_and_call(DICTIONARY *dyncfg_nodes, const char *transaction, const char *function,
  68. usec_t *stop_monotonic_ut, bool *cancelled,
  69. BUFFER *payload, const char *source, BUFFER *result);
  70. #endif //LIBNETDATA_DYNCFG_H