plugins_d.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_PLUGINS_D_H
  3. #define NETDATA_PLUGINS_D_H 1
  4. #include "daemon/common.h"
  5. #define PLUGINSD_FILE_SUFFIX ".plugin"
  6. #define PLUGINSD_FILE_SUFFIX_LEN strlen(PLUGINSD_FILE_SUFFIX)
  7. #define PLUGINSD_CMD_MAX (FILENAME_MAX*2)
  8. #define PLUGINSD_STOCK_PLUGINS_DIRECTORY_PATH 0
  9. #define PLUGINSD_KEYWORD_CHART "CHART"
  10. #define PLUGINSD_KEYWORD_CHART_DEFINITION_END "CHART_DEFINITION_END"
  11. #define PLUGINSD_KEYWORD_DIMENSION "DIMENSION"
  12. #define PLUGINSD_KEYWORD_BEGIN "BEGIN"
  13. #define PLUGINSD_KEYWORD_SET "SET"
  14. #define PLUGINSD_KEYWORD_END "END"
  15. #define PLUGINSD_KEYWORD_FLUSH "FLUSH"
  16. #define PLUGINSD_KEYWORD_DISABLE "DISABLE"
  17. #define PLUGINSD_KEYWORD_VARIABLE "VARIABLE"
  18. #define PLUGINSD_KEYWORD_LABEL "LABEL"
  19. #define PLUGINSD_KEYWORD_OVERWRITE "OVERWRITE"
  20. #define PLUGINSD_KEYWORD_CLABEL "CLABEL"
  21. #define PLUGINSD_KEYWORD_CLABEL_COMMIT "CLABEL_COMMIT"
  22. #define PLUGINSD_KEYWORD_FUNCTION "FUNCTION"
  23. #define PLUGINSD_KEYWORD_FUNCTION_RESULT_BEGIN "FUNCTION_RESULT_BEGIN"
  24. #define PLUGINSD_KEYWORD_FUNCTION_RESULT_END "FUNCTION_RESULT_END"
  25. #define PLUGINSD_KEYWORD_REPLAY_CHART "REPLAY_CHART"
  26. #define PLUGINSD_KEYWORD_REPLAY_BEGIN "RBEGIN"
  27. #define PLUGINSD_KEYWORD_REPLAY_SET "RSET"
  28. #define PLUGINSD_KEYWORD_REPLAY_RRDDIM_STATE "RDSTATE"
  29. #define PLUGINSD_KEYWORD_REPLAY_RRDSET_STATE "RSSTATE"
  30. #define PLUGINSD_KEYWORD_REPLAY_END "REND"
  31. #define PLUGINSD_KEYWORD_BEGIN_V2 "BEGIN2"
  32. #define PLUGINSD_KEYWORD_SET_V2 "SET2"
  33. #define PLUGINSD_KEYWORD_END_V2 "END2"
  34. #define PLUGINSD_KEYWORD_HOST_DEFINE "HOST_DEFINE"
  35. #define PLUGINSD_KEYWORD_HOST_DEFINE_END "HOST_DEFINE_END"
  36. #define PLUGINSD_KEYWORD_HOST_LABEL "HOST_LABEL"
  37. #define PLUGINSD_KEYWORD_HOST "HOST"
  38. #define PLUGINSD_KEYWORD_EXIT "EXIT"
  39. #define PLUGINS_FUNCTIONS_TIMEOUT_DEFAULT 10 // seconds
  40. #define PLUGINSD_LINE_MAX_SSL_READ 512
  41. #define PLUGINSD_MAX_WORDS 20
  42. #define PLUGINSD_MAX_DIRECTORIES 20
  43. extern char *plugin_directories[PLUGINSD_MAX_DIRECTORIES];
  44. struct plugind {
  45. char id[CONFIG_MAX_NAME+1]; // config node id
  46. char filename[FILENAME_MAX+1]; // just the filename
  47. char fullfilename[FILENAME_MAX+1]; // with path
  48. char cmd[PLUGINSD_CMD_MAX+1]; // the command that it executes
  49. size_t successful_collections; // the number of times we have seen
  50. // values collected from this plugin
  51. size_t serial_failures; // the number of times the plugin started
  52. // without collecting values
  53. RRDHOST *host; // the host the plugin collects data for
  54. int update_every; // the plugin default data collection frequency
  55. struct {
  56. SPINLOCK spinlock;
  57. bool running; // do not touch this structure after setting this to 1
  58. bool enabled; // if this is enabled or not
  59. netdata_thread_t thread;
  60. pid_t pid;
  61. } unsafe;
  62. time_t started_t;
  63. struct plugind *prev;
  64. struct plugind *next;
  65. };
  66. extern struct plugind *pluginsd_root;
  67. size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp_plugin_input, FILE *fp_plugin_output, int trust_durations);
  68. void pluginsd_process_thread_cleanup(void *ptr);
  69. size_t pluginsd_initialize_plugin_directories();
  70. #define pluginsd_function_result_begin_to_buffer(wb, transaction, code, content_type, expires) \
  71. buffer_sprintf(wb \
  72. , PLUGINSD_KEYWORD_FUNCTION_RESULT_BEGIN " \"%s\" %d \"%s\" %ld\n" \
  73. , (transaction) ? (transaction) : "" \
  74. , (int)(code) \
  75. , (content_type) ? (content_type) : "" \
  76. , (long int)(expires) \
  77. )
  78. #define pluginsd_function_result_end_to_buffer(wb) \
  79. buffer_strcat(wb, "\n" PLUGINSD_KEYWORD_FUNCTION_RESULT_END "\n")
  80. #define pluginsd_function_result_begin_to_stdout(transaction, code, content_type, expires) \
  81. fprintf(stdout \
  82. , PLUGINSD_KEYWORD_FUNCTION_RESULT_BEGIN " \"%s\" %d \"%s\" %ld\n" \
  83. , (transaction) ? (transaction) : "" \
  84. , (int)(code) \
  85. , (content_type) ? (content_type) : "" \
  86. , (long int)(expires) \
  87. )
  88. #define pluginsd_function_result_end_to_stdout() \
  89. fprintf(stdout, "\n" PLUGINSD_KEYWORD_FUNCTION_RESULT_END "\n")
  90. #endif /* NETDATA_PLUGINS_D_H */