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_SENDER_H
21 #define ZABBIX_SENDER_H
22 
23 #ifdef ZBX_EXPORT
24 #	define ZBX_API __declspec(dllexport)
25 #else
26 #	define ZBX_API __declspec(dllimport)
27 #endif
28 
29 typedef struct
30 {
31 	/* host name, must match the name of target host in Zabbix */
32 	char	*host;
33 	/* the item key */
34 	char	*key;
35 	/* the item value */
36 	char	*value;
37 }
38 zabbix_sender_value_t;
39 
40 typedef struct
41 {
42 	/* number of total values processed */
43 	int	total;
44 	/* number of failed values */
45 	int	failed;
46 	/* time in seconds the server spent processing the sent values */
47 	double	time_spent;
48 }
49 zabbix_sender_info_t;
50 
51 /******************************************************************************
52  *                                                                            *
53  * Function: zabbix_sender_send_values                                        *
54  *                                                                            *
55  * Purpose: send values to Zabbix server/proxy                                *
56  *                                                                            *
57  * Parameters: address   - [IN] zabbix server/proxy address                   *
58  *             port      - [IN] zabbix server/proxy trapper port              *
59  *             source    - [IN] source IP, optional - can be NULL             *
60  *             values    - [IN] array of values to send                       *
61  *             count     - [IN] number of items in values array               *
62  *             result    - [OUT] the server response/error message, optional  *
63  *                         If result is specified it must always be freed     *
64  *                         afterwards with zabbix_sender_free_result()        *
65  *                         function.                                          *
66  *                                                                            *
67  * Return value: 0 - the values were sent successfully, result contains       *
68  *                         server response                                    *
69  *               -1 - an error occurred, result contains error message        *
70  *                                                                            *
71  ******************************************************************************/
72 ZBX_API int	zabbix_sender_send_values(const char *address, unsigned short port, const char *source,
73 		const zabbix_sender_value_t *values, int count, char **result);
74 
75 /******************************************************************************
76  *                                                                            *
77  * Function: zabbix_sender_parse_result                                       *
78  *                                                                            *
79  * Purpose: parses the result returned from zabbix_sender_send_values()       *
80  *          function                                                          *
81  *                                                                            *
82  * Parameters: result   - [IN] result to parse                                *
83  *             response - [OUT] the operation response                        *
84  *                           0 - operation was successful                     *
85  *                          -1 - operation failed                             *
86  *             info     - [OUT] the detailed information about processed      *
87  *                        values, optional                                    *
88  *                                                                            *
89  * Return value:  0 - the result was parsed successfully                      *
90  *               -1 - the result parsing failed                               *
91  *                                                                            *
92  * Comments: If info parameter was specified but the function failed to parse *
93  *           the result info field, then info->total is set to -1.            *
94  *                                                                            *
95  ******************************************************************************/
96 ZBX_API int	zabbix_sender_parse_result(const char *result, int *response, zabbix_sender_info_t *info);
97 
98 /******************************************************************************
99  *                                                                            *
100  * Function: zabbix_sender_free_result                                        *
101  *                                                                            *
102  * Purpose: free data allocated by zabbix_sender_send_values() function       *
103  *                                                                            *
104  * Parameters: ptr   - [IN] pointer to the data to free                       *
105  *                                                                            *
106  ******************************************************************************/
107 ZBX_API void	zabbix_sender_free_result(void *ptr);
108 
109 #endif	/* ZABBIX_SENDER_H */
110