1 /* 2 ** Zabbix 3 ** Copyright (C) 2001-2021 Zabbix SIA 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ** GNU General Public License for more details. 14 ** 15 ** You should have received a copy of the GNU General Public License 16 ** along with this program; if not, write to the Free Software 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 **/ 19 20 #ifndef ZABBIX_MODULE_H 21 #define ZABBIX_MODULE_H 22 23 #include "zbxtypes.h" 24 25 #define ZBX_MODULE_OK 0 26 #define ZBX_MODULE_FAIL -1 27 28 /* zbx_module_api_version() MUST return this constant */ 29 #define ZBX_MODULE_API_VERSION 2 30 31 /* old name alias is kept for source compatibility only, SHOULD NOT be used */ 32 #define ZBX_MODULE_API_VERSION_ONE ZBX_MODULE_API_VERSION 33 34 /* HINT: For conditional compilation with different module.h versions modules can use: */ 35 /* #if ZBX_MODULE_API_VERSION == X */ 36 /* ... */ 37 /* #endif */ 38 39 #define get_rkey(request) (request)->key 40 #define get_rparams_num(request) (request)->nparam 41 #define get_rparam(request, num) ((request)->nparam > num ? (request)->params[num] : NULL) 42 #define get_rparam_type(request, num) ((request)->nparam > num ? (request)->types[num] : \ 43 REQUEST_PARAMETER_TYPE_UNDEFINED) 44 45 /* flags for command */ 46 #define CF_HAVEPARAMS 0x01 /* item accepts either optional or mandatory parameters */ 47 #define CF_MODULE 0x02 /* item is defined in a loadable module */ 48 #define CF_USERPARAMETER 0x04 /* item is defined as user parameter */ 49 50 typedef enum 51 { 52 REQUEST_PARAMETER_TYPE_UNDEFINED = 0, 53 REQUEST_PARAMETER_TYPE_STRING, 54 REQUEST_PARAMETER_TYPE_ARRAY 55 } 56 zbx_request_parameter_type_t; 57 58 /* agent request structure */ 59 typedef struct 60 { 61 char *key; 62 int nparam; 63 char **params; 64 zbx_uint64_t lastlogsize; 65 int mtime; 66 zbx_request_parameter_type_t *types; 67 } 68 AGENT_REQUEST; 69 70 typedef struct 71 { 72 char *value; 73 char *source; 74 int timestamp; 75 int severity; 76 int logeventid; 77 } 78 zbx_log_t; 79 80 /* agent result types */ 81 #define AR_UINT64 0x01 82 #define AR_DOUBLE 0x02 83 #define AR_STRING 0x04 84 #define AR_TEXT 0x08 85 #define AR_LOG 0x10 86 #define AR_MESSAGE 0x20 87 #define AR_META 0x40 88 89 /* agent return structure */ 90 typedef struct 91 { 92 zbx_uint64_t lastlogsize; /* meta information */ 93 zbx_uint64_t ui64; 94 double dbl; 95 char *str; 96 char *text; 97 char *msg; /* possible error message */ 98 zbx_log_t *log; 99 int type; /* flags: see AR_* above */ 100 int mtime; /* meta information */ 101 } 102 AGENT_RESULT; 103 104 typedef struct 105 { 106 char *key; 107 unsigned flags; 108 int (*function)(AGENT_REQUEST *request, AGENT_RESULT *result); 109 char *test_param; /* item test parameters; user parameter items keep command here */ 110 } 111 ZBX_METRIC; 112 113 /* SET RESULT */ 114 115 #define SET_UI64_RESULT(res, val) \ 116 ( \ 117 (res)->type |= AR_UINT64, \ 118 (res)->ui64 = (zbx_uint64_t)(val) \ 119 ) 120 121 #define SET_DBL_RESULT(res, val) \ 122 ( \ 123 (res)->type |= AR_DOUBLE, \ 124 (res)->dbl = (double)(val) \ 125 ) 126 127 /* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ 128 #define SET_STR_RESULT(res, val) \ 129 ( \ 130 (res)->type |= AR_STRING, \ 131 (res)->str = (char *)(val) \ 132 ) 133 134 /* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ 135 #define SET_TEXT_RESULT(res, val) \ 136 ( \ 137 (res)->type |= AR_TEXT, \ 138 (res)->text = (char *)(val) \ 139 ) 140 141 /* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ 142 #define SET_LOG_RESULT(res, val) \ 143 ( \ 144 (res)->type |= AR_LOG, \ 145 (res)->log = (zbx_log_t *)(val) \ 146 ) 147 148 /* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ 149 #define SET_MSG_RESULT(res, val) \ 150 ( \ 151 (res)->type |= AR_MESSAGE, \ 152 (res)->msg = (char *)(val) \ 153 ) 154 155 #define SYSINFO_RET_OK 0 156 #define SYSINFO_RET_FAIL 1 157 158 typedef struct 159 { 160 zbx_uint64_t itemid; 161 int clock; 162 int ns; 163 double value; 164 } 165 ZBX_HISTORY_FLOAT; 166 167 typedef struct 168 { 169 zbx_uint64_t itemid; 170 int clock; 171 int ns; 172 zbx_uint64_t value; 173 } 174 ZBX_HISTORY_INTEGER; 175 176 typedef struct 177 { 178 zbx_uint64_t itemid; 179 int clock; 180 int ns; 181 const char *value; 182 } 183 ZBX_HISTORY_STRING; 184 185 typedef struct 186 { 187 zbx_uint64_t itemid; 188 int clock; 189 int ns; 190 const char *value; 191 } 192 ZBX_HISTORY_TEXT; 193 194 typedef struct 195 { 196 zbx_uint64_t itemid; 197 int clock; 198 int ns; 199 const char *value; 200 const char *source; 201 int timestamp; 202 int logeventid; 203 int severity; 204 } 205 ZBX_HISTORY_LOG; 206 207 typedef struct 208 { 209 void (*history_float_cb)(const ZBX_HISTORY_FLOAT *history, int history_num); 210 void (*history_integer_cb)(const ZBX_HISTORY_INTEGER *history, int history_num); 211 void (*history_string_cb)(const ZBX_HISTORY_STRING *history, int history_num); 212 void (*history_text_cb)(const ZBX_HISTORY_TEXT *history, int history_num); 213 void (*history_log_cb)(const ZBX_HISTORY_LOG *history, int history_num); 214 } 215 ZBX_HISTORY_WRITE_CBS; 216 217 int zbx_module_api_version(void); 218 int zbx_module_init(void); 219 int zbx_module_uninit(void); 220 void zbx_module_item_timeout(int timeout); 221 ZBX_METRIC *zbx_module_item_list(void); 222 ZBX_HISTORY_WRITE_CBS zbx_module_history_write_cbs(void); 223 224 #endif 225