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_ZBXHISTORY_H
21 #define ZABBIX_ZBXHISTORY_H
22 
23 #include "zbxvariant.h"
24 #include "zbxjson.h"
25 
26 /* the item history value */
27 typedef struct
28 {
29 	zbx_timespec_t	timestamp;
30 	history_value_t	value;
31 }
32 zbx_history_record_t;
33 
34 ZBX_VECTOR_DECL(history_record, zbx_history_record_t)
35 
36 void	zbx_history_record_vector_clean(zbx_vector_history_record_t *vector, int value_type);
37 void	zbx_history_record_vector_destroy(zbx_vector_history_record_t *vector, int value_type);
38 void	zbx_history_record_clear(zbx_history_record_t *value, int value_type);
39 
40 int	zbx_history_record_compare_asc_func(const zbx_history_record_t *d1, const zbx_history_record_t *d2);
41 int	zbx_history_record_compare_desc_func(const zbx_history_record_t *d1, const zbx_history_record_t *d2);
42 
43 void	zbx_history_value2str(char *buffer, size_t size, const history_value_t *value, int value_type);
44 char	*zbx_history_value2str_dyn(const history_value_t *value, int value_type);
45 void	zbx_history_value_print(char *buffer, size_t size, const history_value_t *value, int value_type);
46 void	zbx_history_value2variant(const history_value_t *value, unsigned char value_type, zbx_variant_t *var);
47 
48 /* In most cases zbx_history_record_vector_destroy() function should be used to free the  */
49 /* value vector filled by zbx_vc_get_value* functions. This define simply better          */
50 /* mirrors the vector creation function to vector destroying function.                    */
51 #define zbx_history_record_vector_create(vector)	zbx_vector_history_record_create(vector)
52 
53 
54 int	zbx_history_init(char **error);
55 void	zbx_history_destroy(void);
56 
57 int	zbx_history_add_values(const zbx_vector_ptr_t *history);
58 int	zbx_history_get_values(zbx_uint64_t itemid, int value_type, int start, int count, int end,
59 		zbx_vector_history_record_t *values);
60 
61 int	zbx_history_requires_trends(int value_type);
62 void	zbx_history_check_version(struct zbx_json *json);
63 
64 #endif
65