|
| 1 | +/* |
| 2 | +** Zabbix |
| 3 | +** Copyright (C) 2001-2016 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 | + |
| 43 | +/* flags for command */ |
| 44 | +#define CF_HAVEPARAMS 0x01 /* item accepts either optional or mandatory parameters */ |
| 45 | +#define CF_MODULE 0x02 /* item is defined in a loadable module */ |
| 46 | +#define CF_USERPARAMETER 0x04 /* item is defined as user parameter */ |
| 47 | + |
| 48 | +typedef struct |
| 49 | +{ |
| 50 | + char *key; |
| 51 | + unsigned flags; |
| 52 | + int (*function)(); |
| 53 | + char *test_param; /* item test parameters; user parameter items keep command here */ |
| 54 | +} |
| 55 | +ZBX_METRIC; |
| 56 | + |
| 57 | +/* agent request structure */ |
| 58 | +typedef struct |
| 59 | +{ |
| 60 | + char *key; |
| 61 | + int nparam; |
| 62 | + char **params; |
| 63 | + zbx_uint64_t lastlogsize; |
| 64 | + int mtime; |
| 65 | +} |
| 66 | +AGENT_REQUEST; |
| 67 | + |
| 68 | +typedef struct |
| 69 | +{ |
| 70 | + char *value; |
| 71 | + char *source; |
| 72 | + int timestamp; |
| 73 | + int severity; |
| 74 | + int logeventid; |
| 75 | +} |
| 76 | +zbx_log_t; |
| 77 | + |
| 78 | +/* agent result types */ |
| 79 | +#define AR_UINT64 0x01 |
| 80 | +#define AR_DOUBLE 0x02 |
| 81 | +#define AR_STRING 0x04 |
| 82 | +#define AR_TEXT 0x08 |
| 83 | +#define AR_LOG 0x10 |
| 84 | +#define AR_MESSAGE 0x20 |
| 85 | +#define AR_META 0x40 |
| 86 | + |
| 87 | +/* agent return structure */ |
| 88 | +typedef struct |
| 89 | +{ |
| 90 | + zbx_uint64_t lastlogsize; /* meta information */ |
| 91 | + zbx_uint64_t ui64; |
| 92 | + double dbl; |
| 93 | + char *str; |
| 94 | + char *text; |
| 95 | + char *msg; /* possible error message */ |
| 96 | + zbx_log_t *log; |
| 97 | + int type; /* flags: see AR_* above */ |
| 98 | + int mtime; /* meta information */ |
| 99 | +} |
| 100 | +AGENT_RESULT; |
| 101 | + |
| 102 | +/* SET RESULT */ |
| 103 | + |
| 104 | +#define SET_UI64_RESULT(res, val) \ |
| 105 | +( \ |
| 106 | + (res)->type |= AR_UINT64, \ |
| 107 | + (res)->ui64 = (zbx_uint64_t)(val) \ |
| 108 | +) |
| 109 | + |
| 110 | +#define SET_DBL_RESULT(res, val) \ |
| 111 | +( \ |
| 112 | + (res)->type |= AR_DOUBLE, \ |
| 113 | + (res)->dbl = (double)(val) \ |
| 114 | +) |
| 115 | + |
| 116 | +/* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ |
| 117 | +#define SET_STR_RESULT(res, val) \ |
| 118 | +( \ |
| 119 | + (res)->type |= AR_STRING, \ |
| 120 | + (res)->str = (char *)(val) \ |
| 121 | +) |
| 122 | + |
| 123 | +/* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ |
| 124 | +#define SET_TEXT_RESULT(res, val) \ |
| 125 | +( \ |
| 126 | + (res)->type |= AR_TEXT, \ |
| 127 | + (res)->text = (char *)(val) \ |
| 128 | +) |
| 129 | + |
| 130 | +/* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ |
| 131 | +#define SET_LOG_RESULT(res, val) \ |
| 132 | +( \ |
| 133 | + (res)->type |= AR_LOG, \ |
| 134 | + (res)->log = (zbx_log_t *)(val) \ |
| 135 | +) |
| 136 | + |
| 137 | +/* NOTE: always allocate new memory for val! DON'T USE STATIC OR STACK MEMORY!!! */ |
| 138 | +#define SET_MSG_RESULT(res, val) \ |
| 139 | +( \ |
| 140 | + (res)->type |= AR_MESSAGE, \ |
| 141 | + (res)->msg = (char *)(val) \ |
| 142 | +) |
| 143 | + |
| 144 | +#define SYSINFO_RET_OK 0 |
| 145 | +#define SYSINFO_RET_FAIL 1 |
| 146 | + |
| 147 | +typedef struct |
| 148 | +{ |
| 149 | + zbx_uint64_t itemid; |
| 150 | + int clock; |
| 151 | + int ns; |
| 152 | + double value; |
| 153 | +} |
| 154 | +ZBX_HISTORY_FLOAT; |
| 155 | + |
| 156 | +typedef struct |
| 157 | +{ |
| 158 | + zbx_uint64_t itemid; |
| 159 | + int clock; |
| 160 | + int ns; |
| 161 | + zbx_uint64_t value; |
| 162 | +} |
| 163 | +ZBX_HISTORY_INTEGER; |
| 164 | + |
| 165 | +typedef struct |
| 166 | +{ |
| 167 | + zbx_uint64_t itemid; |
| 168 | + int clock; |
| 169 | + int ns; |
| 170 | + const char *value; |
| 171 | +} |
| 172 | +ZBX_HISTORY_STRING; |
| 173 | + |
| 174 | +typedef struct |
| 175 | +{ |
| 176 | + zbx_uint64_t itemid; |
| 177 | + int clock; |
| 178 | + int ns; |
| 179 | + const char *value; |
| 180 | +} |
| 181 | +ZBX_HISTORY_TEXT; |
| 182 | + |
| 183 | +typedef struct |
| 184 | +{ |
| 185 | + zbx_uint64_t itemid; |
| 186 | + int clock; |
| 187 | + int ns; |
| 188 | + const char *value; |
| 189 | + const char *source; |
| 190 | + int timestamp; |
| 191 | + int logeventid; |
| 192 | + int severity; |
| 193 | +} |
| 194 | +ZBX_HISTORY_LOG; |
| 195 | + |
| 196 | +typedef struct |
| 197 | +{ |
| 198 | + void (*history_float_cb)(const ZBX_HISTORY_FLOAT *history, int history_num); |
| 199 | + void (*history_integer_cb)(const ZBX_HISTORY_INTEGER *history, int history_num); |
| 200 | + void (*history_string_cb)(const ZBX_HISTORY_STRING *history, int history_num); |
| 201 | + void (*history_text_cb)(const ZBX_HISTORY_TEXT *history, int history_num); |
| 202 | + void (*history_log_cb)(const ZBX_HISTORY_LOG *history, int history_num); |
| 203 | +} |
| 204 | +ZBX_HISTORY_WRITE_CBS; |
| 205 | + |
| 206 | +#endif |
0 commit comments