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