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_DBSYNC_H 21 #define ZABBIX_DBSYNC_H 22 23 #include "common.h" 24 25 /* no changes */ 26 #define ZBX_DBSYNC_ROW_NONE 0 27 /* a new object must be added to configuration cache */ 28 #define ZBX_DBSYNC_ROW_ADD 1 29 /* a cached object must be updated in configuration cache */ 30 #define ZBX_DBSYNC_ROW_UPDATE 2 31 /* a cached object must be removed from configuration cache */ 32 #define ZBX_DBSYNC_ROW_REMOVE 3 33 34 #define ZBX_DBSYNC_UPDATE_HOSTS __UINT64_C(0x0001) 35 #define ZBX_DBSYNC_UPDATE_ITEMS __UINT64_C(0x0002) 36 #define ZBX_DBSYNC_UPDATE_FUNCTIONS __UINT64_C(0x0004) 37 #define ZBX_DBSYNC_UPDATE_TRIGGERS __UINT64_C(0x0008) 38 #define ZBX_DBSYNC_UPDATE_TRIGGER_DEPENDENCY __UINT64_C(0x0010) 39 #define ZBX_DBSYNC_UPDATE_HOST_GROUPS __UINT64_C(0x0020) 40 #define ZBX_DBSYNC_UPDATE_MAINTENANCE_GROUPS __UINT64_C(0x0040) 41 42 43 #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) 44 # define ZBX_HOST_TLS_OFFSET 4 45 #else 46 # define ZBX_HOST_TLS_OFFSET 0 47 #endif 48 49 /****************************************************************************** 50 * * 51 * Function: zbx_dbsync_preproc_row_func_t * 52 * * 53 * Purpose: applies necessary preprocessing before row is compared/used * 54 * * 55 * Parameter: row - [IN] the row to preprocess * 56 * * 57 * Return value: the preprocessed row * 58 * * 59 * Comments: The row preprocessing can be used to expand user macros in * 60 * some columns. * 61 * * 62 * * 63 ******************************************************************************/ 64 typedef char **(*zbx_dbsync_preproc_row_func_t)(char **row); 65 66 typedef struct 67 { 68 /* a row tag, describing the changes (see ZBX_DBSYNC_ROW_* defines) */ 69 unsigned char tag; 70 71 /* the identifier of the object represented by the row */ 72 zbx_uint64_t rowid; 73 74 /* the column values, NULL if the tag is ZBX_DBSYNC_ROW_REMOVE */ 75 char **row; 76 } 77 zbx_dbsync_row_t; 78 79 struct zbx_dbsync 80 { 81 /* the synchronization mode (see ZBX_DBSYNC_* defines) */ 82 unsigned char mode; 83 84 /* the number of columns in diff */ 85 int columns_num; 86 87 /* the current row */ 88 int row_index; 89 90 /* the changed rows */ 91 zbx_vector_ptr_t rows; 92 93 /* the database result set for ZBX_DBSYNC_ALL mode */ 94 DB_RESULT dbresult; 95 96 /* the row preprocessing function */ 97 zbx_dbsync_preproc_row_func_t preproc_row_func; 98 99 /* the pre-processed row */ 100 char **row; 101 102 /* the preprocessed columns */ 103 zbx_vector_ptr_t columns; 104 105 /* statistics */ 106 zbx_uint64_t add_num; 107 zbx_uint64_t update_num; 108 zbx_uint64_t remove_num; 109 }; 110 111 void zbx_dbsync_init_env(ZBX_DC_CONFIG *cache); 112 void zbx_dbsync_free_env(void); 113 114 void zbx_dbsync_init(zbx_dbsync_t *sync, unsigned char mode); 115 void zbx_dbsync_clear(zbx_dbsync_t *sync); 116 int zbx_dbsync_next(zbx_dbsync_t *sync, zbx_uint64_t *rowid, char ***row, unsigned char *tag); 117 118 int zbx_dbsync_compare_config(zbx_dbsync_t *sync); 119 int zbx_dbsync_compare_autoreg_psk(zbx_dbsync_t *sync); 120 int zbx_dbsync_compare_hosts(zbx_dbsync_t *sync); 121 int zbx_dbsync_compare_host_inventory(zbx_dbsync_t *sync); 122 int zbx_dbsync_compare_host_templates(zbx_dbsync_t *sync); 123 int zbx_dbsync_compare_global_macros(zbx_dbsync_t *sync); 124 int zbx_dbsync_compare_host_macros(zbx_dbsync_t *sync); 125 int zbx_dbsync_compare_interfaces(zbx_dbsync_t *sync); 126 int zbx_dbsync_compare_items(zbx_dbsync_t *sync); 127 int zbx_dbsync_compare_template_items(zbx_dbsync_t *sync); 128 int zbx_dbsync_compare_prototype_items(zbx_dbsync_t *sync); 129 int zbx_dbsync_compare_triggers(zbx_dbsync_t *sync); 130 int zbx_dbsync_compare_trigger_dependency(zbx_dbsync_t *sync); 131 int zbx_dbsync_compare_functions(zbx_dbsync_t *sync); 132 int zbx_dbsync_compare_expressions(zbx_dbsync_t *sync); 133 int zbx_dbsync_compare_actions(zbx_dbsync_t *sync); 134 int zbx_dbsync_compare_action_ops(zbx_dbsync_t *sync); 135 int zbx_dbsync_compare_action_conditions(zbx_dbsync_t *sync); 136 int zbx_dbsync_compare_trigger_tags(zbx_dbsync_t *sync); 137 int zbx_dbsync_compare_host_tags(zbx_dbsync_t *sync); 138 int zbx_dbsync_compare_correlations(zbx_dbsync_t *sync); 139 int zbx_dbsync_compare_corr_conditions(zbx_dbsync_t *sync); 140 int zbx_dbsync_compare_corr_operations(zbx_dbsync_t *sync); 141 int zbx_dbsync_compare_host_groups(zbx_dbsync_t *sync); 142 int zbx_dbsync_compare_item_preprocs(zbx_dbsync_t *sync); 143 int zbx_dbsync_compare_maintenances(zbx_dbsync_t *sync); 144 int zbx_dbsync_compare_maintenance_tags(zbx_dbsync_t *sync); 145 int zbx_dbsync_compare_maintenance_periods(zbx_dbsync_t *sync); 146 int zbx_dbsync_compare_maintenance_groups(zbx_dbsync_t *sync); 147 int zbx_dbsync_compare_maintenance_hosts(zbx_dbsync_t *sync); 148 int zbx_dbsync_compare_host_group_hosts(zbx_dbsync_t *sync); 149 150 #endif /* BUILD_SRC_LIBS_ZBXDBCACHE_DBSYNC_H_ */ 151