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 #include "common.h"
20 #include "log.h"
21 #include "zbxalgo.h"
22 #include "dbcache.h"
23 #include "mutexs.h"
24 
25 #define ZBX_DBCONFIG_IMPL
26 #include "dbconfig.h"
27 
DCdump_config(void)28 static void	DCdump_config(void)
29 {
30 	int	i;
31 
32 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
33 
34 	if (NULL == config->config)
35 		goto out;
36 
37 	zabbix_log(LOG_LEVEL_TRACE, "discovery_groupid:" ZBX_FS_UI64, config->config->discovery_groupid);
38 	zabbix_log(LOG_LEVEL_TRACE, "snmptrap_logging:%hhu", config->config->snmptrap_logging);
39 	zabbix_log(LOG_LEVEL_TRACE, "default_inventory_mode:%d", config->config->default_inventory_mode);
40 
41 	zabbix_log(LOG_LEVEL_TRACE, "db:");
42 	zabbix_log(LOG_LEVEL_TRACE, "  extension: %s", config->config->db.extension);
43 	zabbix_log(LOG_LEVEL_TRACE, "  history_compression_status: %d",
44 			config->config->db.history_compression_status);
45 	zabbix_log(LOG_LEVEL_TRACE, "  history_compress_older: %d", config->config->db.history_compress_older);
46 
47 	zabbix_log(LOG_LEVEL_TRACE, "autoreg_tls_accept:%hhu", config->config->autoreg_tls_accept);
48 
49 	zabbix_log(LOG_LEVEL_TRACE, "severity names:");
50 	for (i = 0; TRIGGER_SEVERITY_COUNT > i; i++)
51 		zabbix_log(LOG_LEVEL_TRACE, "  %s", config->config->severity_name[i]);
52 
53 	zabbix_log(LOG_LEVEL_TRACE, "housekeeping:");
54 	zabbix_log(LOG_LEVEL_TRACE, "  events, mode:%u period:[trigger:%d internal:%d autoreg:%d discovery:%d]",
55 			config->config->hk.events_mode, config->config->hk.events_trigger,
56 			config->config->hk.events_internal, config->config->hk.events_autoreg,
57 			config->config->hk.events_discovery);
58 
59 	zabbix_log(LOG_LEVEL_TRACE, "  audit, mode:%u period:%d", config->config->hk.audit_mode,
60 			config->config->hk.audit);
61 
62 	zabbix_log(LOG_LEVEL_TRACE, "  it services, mode:%u period:%d", config->config->hk.services_mode,
63 			config->config->hk.services);
64 
65 	zabbix_log(LOG_LEVEL_TRACE, "  user sessions, mode:%u period:%d", config->config->hk.sessions_mode,
66 			config->config->hk.sessions);
67 
68 	zabbix_log(LOG_LEVEL_TRACE, "  history, mode:%u global:%u period:%d", config->config->hk.history_mode,
69 			config->config->hk.history_global, config->config->hk.history);
70 
71 	zabbix_log(LOG_LEVEL_TRACE, "  trends, mode:%u global:%u period:%d", config->config->hk.trends_mode,
72 			config->config->hk.trends_global, config->config->hk.trends);
73 
74 	zabbix_log(LOG_LEVEL_TRACE, "  default timezone '%s'", config->config->default_timezone);
75 out:
76 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
77 }
78 
DCdump_hosts(void)79 static void	DCdump_hosts(void)
80 {
81 	ZBX_DC_HOST		*host;
82 	zbx_hashset_iter_t	iter;
83 	zbx_vector_ptr_t	index;
84 	int			i;
85 
86 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
87 
88 	zbx_vector_ptr_create(&index);
89 	zbx_hashset_iter_reset(&config->hosts, &iter);
90 
91 	while (NULL != (host = (ZBX_DC_HOST *)zbx_hashset_iter_next(&iter)))
92 		zbx_vector_ptr_append(&index, host);
93 
94 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
95 
96 	for (i = 0; i < index.values_num; i++)
97 	{
98 		int	j;
99 
100 		host = (ZBX_DC_HOST *)index.values[i];
101 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64 " host:'%s' name:'%s' status:%u", host->hostid,
102 				host->host, host->name, host->status);
103 
104 		zabbix_log(LOG_LEVEL_TRACE, "  proxy_hostid:" ZBX_FS_UI64, host->proxy_hostid);
105 		zabbix_log(LOG_LEVEL_TRACE, "  data_expected_from:%d", host->data_expected_from);
106 
107 		zabbix_log(LOG_LEVEL_TRACE, "  maintenanceid:" ZBX_FS_UI64 " maintenance_status:%u maintenance_type:%u"
108 				" maintenance_from:%d", host->maintenanceid, host->maintenance_status,
109 				host->maintenance_type, host->maintenance_from);
110 
111 		/* 'tls_connect' and 'tls_accept' must be respected even if encryption support is not compiled in */
112 		zabbix_log(LOG_LEVEL_TRACE, "  tls:[connect:%u accept:%u]", host->tls_connect, host->tls_accept);
113 #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
114 		zabbix_log(LOG_LEVEL_TRACE, "  tls:[issuer:'%s' subject:'%s']", host->tls_issuer, host->tls_subject);
115 
116 		if (NULL != host->tls_dc_psk)
117 		{
118 			zabbix_log(LOG_LEVEL_TRACE, "  tls:[psk_identity:'%s' psk:'%s' dc_psk:%u]",
119 					host->tls_dc_psk->tls_psk_identity, host->tls_dc_psk->tls_psk,
120 					host->tls_dc_psk->refcount);
121 		}
122 #endif
123 		for (j = 0; j < host->interfaces_v.values_num; j++)
124 		{
125 			ZBX_DC_INTERFACE	*interface = (ZBX_DC_INTERFACE *)host->interfaces_v.values[j];
126 
127 			zabbix_log(LOG_LEVEL_TRACE, "  interfaceid:" ZBX_FS_UI64, interface->interfaceid);
128 		}
129 	}
130 
131 	zbx_vector_ptr_destroy(&index);
132 
133 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
134 }
135 
DCdump_host_tags(void)136 static void	DCdump_host_tags(void)
137 {
138 	zbx_dc_host_tag_t	*host_tag;
139 	zbx_dc_host_tag_index_t	*host_tag_index;
140 	zbx_hashset_iter_t	iter;
141 	zbx_vector_ptr_t	index;
142 	int			i;
143 
144 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
145 
146 	zbx_vector_ptr_create(&index);
147 	zbx_hashset_iter_reset(&config->host_tags_index, &iter);
148 
149 	while (NULL != (host_tag_index = (zbx_dc_host_tag_index_t *)zbx_hashset_iter_next(&iter)))
150 		zbx_vector_ptr_append(&index, host_tag_index);
151 
152 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
153 
154 	for (i = 0; i < index.values_num; i++)
155 	{
156 		int	j;
157 
158 		host_tag_index = (zbx_dc_host_tag_index_t *)index.values[i];
159 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64,  host_tag_index->hostid);
160 
161 		for (j = 0; j < host_tag_index->tags.values_num; j++)
162 		{
163 			host_tag = (zbx_dc_host_tag_t *)host_tag_index->tags.values[j];
164 			zabbix_log(LOG_LEVEL_TRACE, "  '%s':'%s'", host_tag->tag, host_tag->value);
165 		}
166 	}
167 
168 	zbx_vector_ptr_destroy(&index);
169 
170 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
171 }
172 
DCdump_proxies(void)173 static void	DCdump_proxies(void)
174 {
175 	ZBX_DC_PROXY		*proxy;
176 	zbx_hashset_iter_t	iter;
177 	zbx_vector_ptr_t	index;
178 	int			i;
179 
180 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
181 
182 	zbx_vector_ptr_create(&index);
183 	zbx_hashset_iter_reset(&config->proxies, &iter);
184 
185 	while (NULL != (proxy = (ZBX_DC_PROXY *)zbx_hashset_iter_next(&iter)))
186 		zbx_vector_ptr_append(&index, proxy);
187 
188 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
189 
190 	for (i = 0; i < index.values_num; i++)
191 	{
192 		proxy = (ZBX_DC_PROXY *)index.values[i];
193 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64 " location:%u", proxy->hostid, proxy->location);
194 		zabbix_log(LOG_LEVEL_TRACE, "  proxy_address:'%s'", proxy->proxy_address);
195 		zabbix_log(LOG_LEVEL_TRACE, "  compress:%d", proxy->auto_compress);
196 
197 	}
198 
199 	zbx_vector_ptr_destroy(&index);
200 
201 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
202 }
203 
DCdump_ipmihosts(void)204 static void	DCdump_ipmihosts(void)
205 {
206 	ZBX_DC_IPMIHOST		*ipmihost;
207 	zbx_hashset_iter_t	iter;
208 	zbx_vector_ptr_t	index;
209 	int			i;
210 
211 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
212 
213 	zbx_vector_ptr_create(&index);
214 	zbx_hashset_iter_reset(&config->ipmihosts, &iter);
215 
216 	while (NULL != (ipmihost = (ZBX_DC_IPMIHOST *)zbx_hashset_iter_next(&iter)))
217 		zbx_vector_ptr_append(&index, ipmihost);
218 
219 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
220 
221 	for (i = 0; i < index.values_num; i++)
222 	{
223 		ipmihost = (ZBX_DC_IPMIHOST *)index.values[i];
224 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64 " ipmi:[username:'%s' password:'%s' authtype:%d"
225 				" privilege:%u]", ipmihost->hostid, ipmihost->ipmi_username, ipmihost->ipmi_password,
226 				ipmihost->ipmi_authtype, ipmihost->ipmi_privilege);
227 	}
228 
229 	zbx_vector_ptr_destroy(&index);
230 
231 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
232 }
233 
DCdump_host_inventories(void)234 static void	DCdump_host_inventories(void)
235 {
236 	ZBX_DC_HOST_INVENTORY	*host_inventory;
237 	zbx_hashset_iter_t	iter;
238 	zbx_vector_ptr_t	index;
239 	int			i, j;
240 
241 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
242 
243 	zbx_vector_ptr_create(&index);
244 	zbx_hashset_iter_reset(&config->host_inventories, &iter);
245 
246 	while (NULL != (host_inventory = (ZBX_DC_HOST_INVENTORY *)zbx_hashset_iter_next(&iter)))
247 		zbx_vector_ptr_append(&index, host_inventory);
248 
249 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
250 
251 	for (i = 0; i < index.values_num; i++)
252 	{
253 		host_inventory = (ZBX_DC_HOST_INVENTORY *)index.values[i];
254 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64 " inventory_mode:%u", host_inventory->hostid,
255 				host_inventory->inventory_mode);
256 
257 		for (j = 0; j < HOST_INVENTORY_FIELD_COUNT; j++)
258 		{
259 			zabbix_log(LOG_LEVEL_TRACE, "  %s: '%s'", DBget_inventory_field(j + 1),
260 					host_inventory->values[j]);
261 		}
262 	}
263 
264 	zbx_vector_ptr_destroy(&index);
265 
266 	zabbix_log(LOG_LEVEL_TRACE, "  End of %s()", __func__);
267 }
268 
DCdump_htmpls(void)269 static void	DCdump_htmpls(void)
270 {
271 	ZBX_DC_HTMPL		*htmpl = NULL;
272 	zbx_hashset_iter_t	iter;
273 	zbx_vector_ptr_t	index;
274 	int			i, j;
275 
276 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
277 
278 	zbx_vector_ptr_create(&index);
279 	zbx_hashset_iter_reset(&config->htmpls, &iter);
280 
281 	while (NULL != (htmpl = (ZBX_DC_HTMPL *)zbx_hashset_iter_next(&iter)))
282 		zbx_vector_ptr_append(&index, htmpl);
283 
284 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
285 
286 	for (i = 0; i < index.values_num; i++)
287 	{
288 		htmpl = (ZBX_DC_HTMPL *)index.values[i];
289 
290 		zabbix_log(LOG_LEVEL_TRACE, "hostid:" ZBX_FS_UI64, htmpl->hostid);
291 
292 		for (j = 0; j < htmpl->templateids.values_num; j++)
293 			zabbix_log(LOG_LEVEL_TRACE, "  templateid:" ZBX_FS_UI64, htmpl->templateids.values[j]);
294 	}
295 
296 	zbx_vector_ptr_destroy(&index);
297 
298 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
299 }
300 
DCdump_kvs_paths(void)301 static void	DCdump_kvs_paths(void)
302 {
303 	zbx_dc_kvs_path_t	*kvs_path;
304 	zbx_dc_kv_t		*kvs;
305 	zbx_hashset_iter_t	iter;
306 	int			i;
307 
308 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
309 
310 	for (i = 0; i < config->kvs_paths.values_num; i++)
311 	{
312 		kvs_path = (zbx_dc_kvs_path_t *)config->kvs_paths.values[i];
313 		zabbix_log(LOG_LEVEL_TRACE, "kvs_path:'%s'", kvs_path->path);
314 
315 		zbx_hashset_iter_reset(&kvs_path->kvs, &iter);
316 		while (NULL != (kvs = (zbx_dc_kv_t *)zbx_hashset_iter_next(&iter)))
317 			zabbix_log(LOG_LEVEL_TRACE, "  key:'%s' refcount:%d", kvs->key, kvs->refcount);
318 	}
319 
320 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
321 }
322 
DCdump_gmacros(void)323 static void	DCdump_gmacros(void)
324 {
325 	ZBX_DC_GMACRO		*gmacro;
326 	zbx_hashset_iter_t	iter;
327 	zbx_vector_ptr_t	index;
328 	int			i;
329 
330 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
331 
332 	zbx_vector_ptr_create(&index);
333 	zbx_hashset_iter_reset(&config->gmacros, &iter);
334 
335 	while (NULL != (gmacro = (ZBX_DC_GMACRO *)zbx_hashset_iter_next(&iter)))
336 		zbx_vector_ptr_append(&index, gmacro);
337 
338 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
339 
340 	for (i = 0; i < index.values_num; i++)
341 	{
342 		gmacro = (ZBX_DC_GMACRO *)index.values[i];
343 		zabbix_log(LOG_LEVEL_TRACE, "globalmacroid:" ZBX_FS_UI64 " macro:'%s' value:'%s' context:'%s' op:%d"
344 				" type:%d", gmacro->globalmacroid, gmacro->macro,
345 				gmacro->value, ZBX_NULL2EMPTY_STR(gmacro->context), gmacro->context_op, gmacro->type);
346 	}
347 
348 	zbx_vector_ptr_destroy(&index);
349 
350 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
351 }
352 
DCdump_hmacros(void)353 static void	DCdump_hmacros(void)
354 {
355 	ZBX_DC_HMACRO		*hmacro;
356 	zbx_hashset_iter_t	iter;
357 	zbx_vector_ptr_t	index;
358 	int			i;
359 
360 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
361 
362 	zbx_vector_ptr_create(&index);
363 	zbx_hashset_iter_reset(&config->hmacros, &iter);
364 
365 	while (NULL != (hmacro = (ZBX_DC_HMACRO *)zbx_hashset_iter_next(&iter)))
366 		zbx_vector_ptr_append(&index, hmacro);
367 
368 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
369 
370 	for (i = 0; i < index.values_num; i++)
371 	{
372 		hmacro = (ZBX_DC_HMACRO *)index.values[i];
373 		zabbix_log(LOG_LEVEL_TRACE, "hostmacroid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64 " macro:'%s' value:'%s'"
374 				" context '%s' op:%d type:%d", hmacro->hostmacroid, hmacro->hostid, hmacro->macro,
375 				hmacro->value, ZBX_NULL2EMPTY_STR(hmacro->context), hmacro->context_op, hmacro->type);
376 	}
377 
378 	zbx_vector_ptr_destroy(&index);
379 
380 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
381 }
382 
DCdump_interfaces(void)383 static void	DCdump_interfaces(void)
384 {
385 	ZBX_DC_INTERFACE	*interface;
386 	ZBX_DC_SNMPINTERFACE	*snmp;
387 	zbx_hashset_iter_t	iter;
388 	zbx_vector_ptr_t	index;
389 	char			*if_msg = NULL;
390 	size_t			alloc, offset;
391 	int			i;
392 
393 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
394 
395 	zbx_vector_ptr_create(&index);
396 	zbx_hashset_iter_reset(&config->interfaces, &iter);
397 
398 	while (NULL != (interface = (ZBX_DC_INTERFACE *)zbx_hashset_iter_next(&iter)))
399 		zbx_vector_ptr_append(&index, interface);
400 
401 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
402 
403 	for (i = 0; i < index.values_num; i++)
404 	{
405 		interface = (ZBX_DC_INTERFACE *)index.values[i];
406 
407 		zbx_snprintf_alloc(&if_msg, &alloc, &offset, "interfaceid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64
408 				" ip:'%s' dns:'%s' port:'%s' type:%u main:%u useip:%u"
409 				" available:%u errors_from:%d disable_until:%d error:'%s' availability_ts:%d"
410 				" reset_availability:%d items_num %d",
411 				interface->interfaceid, interface->hostid, interface->ip, interface->dns,
412 				interface->port, interface->type, interface->main, interface->useip,
413 				interface->available, interface->errors_from, interface->disable_until,
414 				interface->error, interface->availability_ts, interface->reset_availability,
415 				interface->items_num);
416 
417 		if (INTERFACE_TYPE_SNMP == interface->type &&
418 				NULL != (snmp = (ZBX_DC_SNMPINTERFACE *)zbx_hashset_search(&config->interfaces_snmp,
419 				&interface->interfaceid)))
420 		{
421 			zbx_snprintf_alloc(&if_msg, &alloc, &offset, "snmp:[bulk:%u snmp_type:%u community:'%s']",
422 					snmp->bulk, snmp->version, snmp->community);
423 
424 			if (ZBX_IF_SNMP_VERSION_3 == snmp->version)
425 			{
426 				zbx_snprintf_alloc(&if_msg, &alloc, &offset," snmpv3:["
427 					"securityname:'%s' securitylevel:%u authprotocol:%u privprotocol:%u"
428 					" contextname:'%s']", snmp->securityname, snmp->securitylevel,
429 					snmp->authprotocol, snmp->privprotocol, snmp->contextname);
430 			}
431 		}
432 
433 		zabbix_log(LOG_LEVEL_TRACE, "%s", if_msg);
434 	}
435 
436 	zbx_free(if_msg);
437 	zbx_vector_ptr_destroy(&index);
438 
439 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
440 }
441 
DCdump_numitem(const ZBX_DC_NUMITEM * numitem)442 static void	DCdump_numitem(const ZBX_DC_NUMITEM *numitem)
443 {
444 	zabbix_log(LOG_LEVEL_TRACE, "  units:'%s' trends:%d", numitem->units, numitem->trends);
445 }
446 
DCdump_snmpitem(const ZBX_DC_SNMPITEM * snmpitem)447 static void	DCdump_snmpitem(const ZBX_DC_SNMPITEM *snmpitem)
448 {
449 	zabbix_log(LOG_LEVEL_TRACE, "  snmp:[oid:'%s' oid_type:%u]", snmpitem->snmp_oid, snmpitem->snmp_oid_type);
450 }
451 
DCdump_ipmiitem(const ZBX_DC_IPMIITEM * ipmiitem)452 static void	DCdump_ipmiitem(const ZBX_DC_IPMIITEM *ipmiitem)
453 {
454 	zabbix_log(LOG_LEVEL_TRACE, "  ipmi_sensor:'%s'", ipmiitem->ipmi_sensor);
455 }
456 
DCdump_trapitem(const ZBX_DC_TRAPITEM * trapitem)457 static void	DCdump_trapitem(const ZBX_DC_TRAPITEM *trapitem)
458 {
459 	zabbix_log(LOG_LEVEL_TRACE, "  trapper_hosts:'%s'", trapitem->trapper_hosts);
460 }
461 
DCdump_logitem(ZBX_DC_LOGITEM * logitem)462 static void	DCdump_logitem(ZBX_DC_LOGITEM *logitem)
463 {
464 	zabbix_log(LOG_LEVEL_TRACE, "  logtimefmt:'%s'", logitem->logtimefmt);
465 }
466 
DCdump_dbitem(const ZBX_DC_DBITEM * dbitem)467 static void	DCdump_dbitem(const ZBX_DC_DBITEM *dbitem)
468 {
469 	zabbix_log(LOG_LEVEL_TRACE, "  db:[params:'%s' username:'%s' password:'%s']", dbitem->params,
470 			dbitem->username, dbitem->password);
471 }
472 
DCdump_sshitem(const ZBX_DC_SSHITEM * sshitem)473 static void	DCdump_sshitem(const ZBX_DC_SSHITEM *sshitem)
474 {
475 	zabbix_log(LOG_LEVEL_TRACE, "  ssh:[username:'%s' password:'%s' authtype:%u params:'%s']",
476 			sshitem->username, sshitem->password, sshitem->authtype, sshitem->params);
477 	zabbix_log(LOG_LEVEL_TRACE, "  ssh:[publickey:'%s' privatekey:'%s']", sshitem->publickey,
478 			sshitem->privatekey);
479 }
480 
DCdump_httpitem(const ZBX_DC_HTTPITEM * httpitem)481 static void	DCdump_httpitem(const ZBX_DC_HTTPITEM *httpitem)
482 {
483 	zabbix_log(LOG_LEVEL_TRACE, "  http:[url:'%s']", httpitem->url);
484 	zabbix_log(LOG_LEVEL_TRACE, "  http:[query fields:'%s']", httpitem->query_fields);
485 	zabbix_log(LOG_LEVEL_TRACE, "  http:[headers:'%s']", httpitem->headers);
486 	zabbix_log(LOG_LEVEL_TRACE, "  http:[posts:'%s']", httpitem->posts);
487 
488 	zabbix_log(LOG_LEVEL_TRACE, "  http:[timeout:'%s' status codes:'%s' follow redirects:%u post type:%u"
489 			" http proxy:'%s' retrieve mode:%u request method:%u output format:%u allow traps:%u"
490 			" trapper_hosts:'%s']",
491 			httpitem->timeout, httpitem->status_codes, httpitem->follow_redirects, httpitem->post_type,
492 			httpitem->http_proxy, httpitem->retrieve_mode, httpitem->request_method,
493 			httpitem->output_format, httpitem->allow_traps, httpitem->trapper_hosts);
494 
495 	zabbix_log(LOG_LEVEL_TRACE, "  http:[username:'%s' password:'%s' authtype:%u]",
496 			httpitem->username, httpitem->password, httpitem->authtype);
497 	zabbix_log(LOG_LEVEL_TRACE, "  http:[publickey:'%s' privatekey:'%s' ssl key password:'%s' verify peer:%u"
498 			" verify host:%u]", httpitem->ssl_cert_file, httpitem->ssl_key_file, httpitem->ssl_key_password,
499 			httpitem->verify_peer, httpitem->verify_host);
500 }
501 
DCdump_scriptitem(const ZBX_DC_SCRIPTITEM * scriptitem)502 static void	DCdump_scriptitem(const ZBX_DC_SCRIPTITEM *scriptitem)
503 {
504 	int	i;
505 
506 	zabbix_log(LOG_LEVEL_TRACE, "  script:[timeout:'%s' script:'%s']", scriptitem->timeout, scriptitem->script);
507 
508 	for (i = 0; i < scriptitem->params.values_num; i++)
509 	{
510 		zbx_dc_scriptitem_param_t	*params = (zbx_dc_scriptitem_param_t *)scriptitem->params.values[i];
511 
512 		zabbix_log(LOG_LEVEL_TRACE, "      item_script_paramid:" ZBX_FS_UI64 " name: '%s' value:'%s'",
513 				params->item_script_paramid, params->name, params->value);
514 	}
515 }
516 
DCdump_telnetitem(const ZBX_DC_TELNETITEM * telnetitem)517 static void	DCdump_telnetitem(const ZBX_DC_TELNETITEM *telnetitem)
518 {
519 	zabbix_log(LOG_LEVEL_TRACE, "  telnet:[username:'%s' password:'%s' params:'%s']", telnetitem->username,
520 			telnetitem->password, telnetitem->params);
521 }
522 
DCdump_simpleitem(const ZBX_DC_SIMPLEITEM * simpleitem)523 static void	DCdump_simpleitem(const ZBX_DC_SIMPLEITEM *simpleitem)
524 {
525 	zabbix_log(LOG_LEVEL_TRACE, "  simple:[username:'%s' password:'%s']", simpleitem->username,
526 			simpleitem->password);
527 }
528 
DCdump_jmxitem(const ZBX_DC_JMXITEM * jmxitem)529 static void	DCdump_jmxitem(const ZBX_DC_JMXITEM *jmxitem)
530 {
531 	zabbix_log(LOG_LEVEL_TRACE, "  jmx:[username:'%s' password:'%s' endpoint:'%s']",
532 			jmxitem->username, jmxitem->password, jmxitem->jmx_endpoint);
533 }
534 
DCdump_calcitem(const ZBX_DC_CALCITEM * calcitem)535 static void	DCdump_calcitem(const ZBX_DC_CALCITEM *calcitem)
536 {
537 	zabbix_log(LOG_LEVEL_TRACE, "  calc:[params:'%s']", calcitem->params);
538 }
539 
DCdump_masteritem(const ZBX_DC_MASTERITEM * masteritem)540 static void	DCdump_masteritem(const ZBX_DC_MASTERITEM *masteritem)
541 {
542 	int	i;
543 
544 	zabbix_log(LOG_LEVEL_TRACE, "  dependent:");
545 	for (i = 0; i < masteritem->dep_itemids.values_num; i++)
546 	{
547 		zabbix_log(LOG_LEVEL_TRACE, "    itemid:" ZBX_FS_UI64 " flags:" ZBX_FS_UI64,
548 				masteritem->dep_itemids.values[i].first, masteritem->dep_itemids.values[i].second);
549 	}
550 }
551 
DCdump_preprocitem(const ZBX_DC_PREPROCITEM * preprocitem)552 static void	DCdump_preprocitem(const ZBX_DC_PREPROCITEM *preprocitem)
553 {
554 	int	i;
555 
556 	zabbix_log(LOG_LEVEL_TRACE, "  preprocessing:");
557 	zabbix_log(LOG_LEVEL_TRACE, "  update_time:%d", preprocitem->update_time);
558 
559 	for (i = 0; i < preprocitem->preproc_ops.values_num; i++)
560 	{
561 		zbx_dc_preproc_op_t	*op = (zbx_dc_preproc_op_t *)preprocitem->preproc_ops.values[i];
562 		zabbix_log(LOG_LEVEL_TRACE, "      opid:" ZBX_FS_UI64 " step:%d type:%u params:'%s'"
563 				" error_handler:%d error_handler_params:'%s'",
564 				op->item_preprocid, op->step, op->type, op->params, op->error_handler, op->error_handler_params);
565 	}
566 }
567 
568 /* item type specific information debug logging support */
569 
570 typedef void (*zbx_dc_dump_func_t)(void *);
571 
572 typedef struct
573 {
574 	zbx_hashset_t		*hashset;
575 	zbx_dc_dump_func_t	dump_func;
576 }
577 zbx_trace_item_t;
578 
DCdump_item_tags(const ZBX_DC_ITEM * item)579 static void	DCdump_item_tags(const ZBX_DC_ITEM *item)
580 {
581 	int			i;
582 	zbx_vector_ptr_t	index;
583 
584 	zbx_vector_ptr_create(&index);
585 
586 	zbx_vector_ptr_append_array(&index, item->tags.values, item->tags.values_num);
587 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
588 
589 	zabbix_log(LOG_LEVEL_TRACE, "  tags:");
590 
591 	for (i = 0; i < index.values_num; i++)
592 	{
593 		zbx_dc_item_tag_t	*tag = (zbx_dc_item_tag_t *)index.values[i];
594 		zabbix_log(LOG_LEVEL_TRACE, "      tagid:" ZBX_FS_UI64 " tag:'%s' value:'%s'",
595 				tag->itemtagid, tag->tag, tag->value);
596 	}
597 
598 	zbx_vector_ptr_destroy(&index);
599 }
600 
DCdump_items(void)601 static void	DCdump_items(void)
602 {
603 	ZBX_DC_ITEM		*item;
604 	zbx_hashset_iter_t	iter;
605 	int			i, j;
606 	zbx_vector_ptr_t	index;
607 	void			*ptr;
608 	zbx_trace_item_t	trace_items[] =
609 	{
610 		{&config->numitems, (zbx_dc_dump_func_t)DCdump_numitem},
611 		{&config->snmpitems, (zbx_dc_dump_func_t)DCdump_snmpitem},
612 		{&config->ipmiitems, (zbx_dc_dump_func_t)DCdump_ipmiitem},
613 		{&config->trapitems, (zbx_dc_dump_func_t)DCdump_trapitem},
614 		{&config->logitems, (zbx_dc_dump_func_t)DCdump_logitem},
615 		{&config->dbitems, (zbx_dc_dump_func_t)DCdump_dbitem},
616 		{&config->sshitems, (zbx_dc_dump_func_t)DCdump_sshitem},
617 		{&config->telnetitems, (zbx_dc_dump_func_t)DCdump_telnetitem},
618 		{&config->simpleitems, (zbx_dc_dump_func_t)DCdump_simpleitem},
619 		{&config->jmxitems, (zbx_dc_dump_func_t)DCdump_jmxitem},
620 		{&config->calcitems, (zbx_dc_dump_func_t)DCdump_calcitem},
621 		{&config->masteritems, (zbx_dc_dump_func_t)DCdump_masteritem},
622 		{&config->preprocitems, (zbx_dc_dump_func_t)DCdump_preprocitem},
623 		{&config->httpitems, (zbx_dc_dump_func_t)DCdump_httpitem},
624 		{&config->scriptitems, (zbx_dc_dump_func_t)DCdump_scriptitem},
625 	};
626 
627 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
628 
629 	zbx_vector_ptr_create(&index);
630 	zbx_hashset_iter_reset(&config->items, &iter);
631 
632 	while (NULL != (item = (ZBX_DC_ITEM *)zbx_hashset_iter_next(&iter)))
633 		zbx_vector_ptr_append(&index, item);
634 
635 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
636 
637 	for (i = 0; i < index.values_num; i++)
638 	{
639 		item = (ZBX_DC_ITEM *)index.values[i];
640 		zabbix_log(LOG_LEVEL_TRACE, "itemid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64 " key:'%s'",
641 				item->itemid, item->hostid, item->key);
642 		zabbix_log(LOG_LEVEL_TRACE, "  type:%u value_type:%u", item->type, item->value_type);
643 		zabbix_log(LOG_LEVEL_TRACE, "  interfaceid:" ZBX_FS_UI64, item->interfaceid);
644 		zabbix_log(LOG_LEVEL_TRACE, "  state:%u error:'%s'", item->state, item->error);
645 		zabbix_log(LOG_LEVEL_TRACE, "  flags:%u status:%u", item->flags, item->status);
646 		zabbix_log(LOG_LEVEL_TRACE, "  valuemapid:" ZBX_FS_UI64, item->valuemapid);
647 		zabbix_log(LOG_LEVEL_TRACE, "  lastlogsize:" ZBX_FS_UI64 " mtime:%d", item->lastlogsize, item->mtime);
648 		zabbix_log(LOG_LEVEL_TRACE, "  delay:'%s' nextcheck:%d", item->delay, item->nextcheck);
649 		zabbix_log(LOG_LEVEL_TRACE, "  data_expected_from:%d", item->data_expected_from);
650 		zabbix_log(LOG_LEVEL_TRACE, "  history:%d history_sec:%d", item->history, item->history_sec);
651 		zabbix_log(LOG_LEVEL_TRACE, "  poller_type:%u location:%u", item->poller_type, item->location);
652 		zabbix_log(LOG_LEVEL_TRACE, "  inventory_link:%u", item->inventory_link);
653 		zabbix_log(LOG_LEVEL_TRACE, "  priority:%u schedulable:%u", item->queue_priority, item->schedulable);
654 
655 		for (j = 0; j < (int)ARRSIZE(trace_items); j++)
656 		{
657 			if (NULL != (ptr = zbx_hashset_search(trace_items[j].hashset, &item->itemid)))
658 				trace_items[j].dump_func(ptr);
659 		}
660 
661 		if (0 != item->tags.values_num)
662 			DCdump_item_tags(item);
663 
664 		if (NULL != item->triggers)
665 		{
666 			ZBX_DC_TRIGGER	*trigger;
667 
668 			zabbix_log(LOG_LEVEL_TRACE, "  triggers:");
669 
670 			for (j = 0; NULL != (trigger = item->triggers[j]); j++)
671 				zabbix_log(LOG_LEVEL_TRACE, "    triggerid:" ZBX_FS_UI64, trigger->triggerid);
672 		}
673 	}
674 
675 	zbx_vector_ptr_destroy(&index);
676 
677 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
678 }
679 
DCdump_interface_snmpitems(void)680 static void	DCdump_interface_snmpitems(void)
681 {
682 	ZBX_DC_INTERFACE_ITEM	*interface_snmpitem;
683 	zbx_hashset_iter_t	iter;
684 	int			i, j;
685 	zbx_vector_ptr_t	index;
686 
687 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
688 
689 	zbx_vector_ptr_create(&index);
690 	zbx_hashset_iter_reset(&config->interface_snmpitems, &iter);
691 
692 	while (NULL != (interface_snmpitem = (ZBX_DC_INTERFACE_ITEM *)zbx_hashset_iter_next(&iter)))
693 		zbx_vector_ptr_append(&index, interface_snmpitem);
694 
695 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
696 
697 	for (i = 0; i < index.values_num; i++)
698 	{
699 		interface_snmpitem = (ZBX_DC_INTERFACE_ITEM *)index.values[i];
700 		zabbix_log(LOG_LEVEL_TRACE, "interfaceid:" ZBX_FS_UI64, interface_snmpitem->interfaceid);
701 
702 		for (j = 0; j < interface_snmpitem->itemids.values_num; j++)
703 			zabbix_log(LOG_LEVEL_TRACE, "  itemid:" ZBX_FS_UI64, interface_snmpitem->itemids.values[j]);
704 	}
705 
706 	zbx_vector_ptr_destroy(&index);
707 
708 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
709 }
710 
DCdump_template_items(void)711 static void	DCdump_template_items(void)
712 {
713 	ZBX_DC_TEMPLATE_ITEM	*template_item;
714 	zbx_hashset_iter_t	iter;
715 	int			i;
716 	zbx_vector_ptr_t	index;
717 
718 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
719 
720 	zbx_vector_ptr_create(&index);
721 	zbx_hashset_iter_reset(&config->template_items, &iter);
722 
723 	while (NULL != (template_item = (ZBX_DC_TEMPLATE_ITEM *)zbx_hashset_iter_next(&iter)))
724 		zbx_vector_ptr_append(&index, template_item);
725 
726 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
727 
728 	for (i = 0; i < index.values_num; i++)
729 	{
730 		template_item = (ZBX_DC_TEMPLATE_ITEM *)index.values[i];
731 		zabbix_log(LOG_LEVEL_TRACE, "itemid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64 " templateid:" ZBX_FS_UI64,
732 				template_item->itemid, template_item->hostid, template_item->templateid);
733 	}
734 
735 	zbx_vector_ptr_destroy(&index);
736 
737 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
738 }
739 
DCdump_master_items(void)740 static void	DCdump_master_items(void)
741 {
742 	ZBX_DC_MASTERITEM	*master_item;
743 	zbx_hashset_iter_t	iter;
744 	int			i, j;
745 	zbx_vector_ptr_t	index;
746 
747 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
748 
749 	zbx_vector_ptr_create(&index);
750 	zbx_hashset_iter_reset(&config->masteritems, &iter);
751 
752 	while (NULL != (master_item = (ZBX_DC_MASTERITEM *)zbx_hashset_iter_next(&iter)))
753 		zbx_vector_ptr_append(&index, master_item);
754 
755 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
756 
757 	for (i = 0; i < index.values_num; i++)
758 	{
759 		master_item = (ZBX_DC_MASTERITEM *)index.values[i];
760 		zabbix_log(LOG_LEVEL_TRACE, "master itemid:" ZBX_FS_UI64, master_item->itemid);
761 
762 		for (j = 0; j < master_item->dep_itemids.values_num; j++)
763 		{
764 			zabbix_log(LOG_LEVEL_TRACE, "  itemid:" ZBX_FS_UI64 " flags:" ZBX_FS_UI64,
765 					master_item->dep_itemids.values[j].first,
766 					master_item->dep_itemids.values[j].second);
767 		}
768 	}
769 
770 	zbx_vector_ptr_destroy(&index);
771 
772 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
773 }
774 
DCdump_prototype_items(void)775 static void	DCdump_prototype_items(void)
776 {
777 	ZBX_DC_PROTOTYPE_ITEM	*proto_item;
778 	zbx_hashset_iter_t	iter;
779 	int			i;
780 	zbx_vector_ptr_t	index;
781 
782 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
783 
784 	zbx_vector_ptr_create(&index);
785 	zbx_hashset_iter_reset(&config->template_items, &iter);
786 
787 	while (NULL != (proto_item = (ZBX_DC_PROTOTYPE_ITEM *)zbx_hashset_iter_next(&iter)))
788 		zbx_vector_ptr_append(&index, proto_item);
789 
790 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
791 
792 	for (i = 0; i < index.values_num; i++)
793 	{
794 		proto_item = (ZBX_DC_PROTOTYPE_ITEM *)index.values[i];
795 		zabbix_log(LOG_LEVEL_TRACE, "itemid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64 " templateid:" ZBX_FS_UI64,
796 				proto_item->itemid, proto_item->hostid, proto_item->templateid);
797 	}
798 
799 	zbx_vector_ptr_destroy(&index);
800 
801 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
802 }
803 
DCdump_functions(void)804 static void	DCdump_functions(void)
805 {
806 	ZBX_DC_FUNCTION		*function;
807 	zbx_hashset_iter_t	iter;
808 	int			i;
809 	zbx_vector_ptr_t	index;
810 
811 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
812 
813 	zbx_vector_ptr_create(&index);
814 	zbx_hashset_iter_reset(&config->functions, &iter);
815 
816 	while (NULL != (function = (ZBX_DC_FUNCTION *)zbx_hashset_iter_next(&iter)))
817 		zbx_vector_ptr_append(&index, function);
818 
819 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
820 
821 	for (i = 0; i < index.values_num; i++)
822 	{
823 		function = (ZBX_DC_FUNCTION *)index.values[i];
824 		zabbix_log(LOG_LEVEL_DEBUG, "functionid:" ZBX_FS_UI64 " triggerid:" ZBX_FS_UI64 " itemid:"
825 				ZBX_FS_UI64 " function:'%s' parameter:'%s' type:%u timer_revision:%d",
826 				function->functionid, function->triggerid, function->itemid, function->function,
827 				function->parameter, function->type, function->timer_revision);
828 
829 	}
830 
831 	zbx_vector_ptr_destroy(&index);
832 
833 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
834 }
835 
DCdump_trigger_tags(const ZBX_DC_TRIGGER * trigger)836 static void	DCdump_trigger_tags(const ZBX_DC_TRIGGER *trigger)
837 {
838 	int			i;
839 	zbx_vector_ptr_t	index;
840 
841 	zbx_vector_ptr_create(&index);
842 
843 	zbx_vector_ptr_append_array(&index, trigger->tags.values, trigger->tags.values_num);
844 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
845 
846 	zabbix_log(LOG_LEVEL_TRACE, "  tags:");
847 
848 	for (i = 0; i < index.values_num; i++)
849 	{
850 		zbx_dc_trigger_tag_t	*tag = (zbx_dc_trigger_tag_t *)index.values[i];
851 		zabbix_log(LOG_LEVEL_TRACE, "      tagid:" ZBX_FS_UI64 " tag:'%s' value:'%s'",
852 				tag->triggertagid, tag->tag, tag->value);
853 	}
854 
855 	zbx_vector_ptr_destroy(&index);
856 }
857 
DCdump_triggers(void)858 static void	DCdump_triggers(void)
859 {
860 	ZBX_DC_TRIGGER		*trigger;
861 	zbx_hashset_iter_t	iter;
862 	int			i;
863 	zbx_vector_ptr_t	index;
864 
865 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
866 
867 	zbx_vector_ptr_create(&index);
868 	zbx_hashset_iter_reset(&config->triggers, &iter);
869 
870 	while (NULL != (trigger = (ZBX_DC_TRIGGER *)zbx_hashset_iter_next(&iter)))
871 		zbx_vector_ptr_append(&index, trigger);
872 
873 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
874 
875 	for (i = 0; i < index.values_num; i++)
876 	{
877 		trigger = (ZBX_DC_TRIGGER *)index.values[i];
878 
879 		zabbix_log(LOG_LEVEL_TRACE, "triggerid:" ZBX_FS_UI64 " description:'%s' event_name:'%s' type:%u"
880 				" status:%u priority:%u", trigger->triggerid, trigger->description, trigger->event_name,
881 				trigger->type, trigger->status, trigger->priority);
882 		zabbix_log(LOG_LEVEL_TRACE, "  expression:'%s' recovery_expression:'%s'", trigger->expression,
883 				trigger->recovery_expression);
884 		zabbix_log(LOG_LEVEL_TRACE, "  value:%u state:%u error:'%s' lastchange:%d", trigger->value,
885 				trigger->state, ZBX_NULL2EMPTY_STR(trigger->error), trigger->lastchange);
886 		zabbix_log(LOG_LEVEL_TRACE, "  correlation_tag:'%s' recovery_mode:'%u' correlation_mode:'%u'",
887 				trigger->correlation_tag, trigger->recovery_mode, trigger->correlation_mode);
888 		zabbix_log(LOG_LEVEL_TRACE, "  topoindex:%u functional:%u locked:%u", trigger->topoindex,
889 				trigger->functional, trigger->locked);
890 		zabbix_log(LOG_LEVEL_TRACE, "  opdata:'%s'", trigger->opdata);
891 
892 		if (0 != trigger->tags.values_num)
893 			DCdump_trigger_tags(trigger);
894 	}
895 
896 	zbx_vector_ptr_destroy(&index);
897 
898 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
899 }
900 
DCdump_trigdeps(void)901 static void	DCdump_trigdeps(void)
902 {
903 	ZBX_DC_TRIGGER_DEPLIST	*trigdep;
904 	zbx_hashset_iter_t	iter;
905 	int			i, j;
906 	zbx_vector_ptr_t	index;
907 
908 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
909 
910 	zbx_vector_ptr_create(&index);
911 	zbx_hashset_iter_reset(&config->trigdeps, &iter);
912 
913 	while (NULL != (trigdep = (ZBX_DC_TRIGGER_DEPLIST *)zbx_hashset_iter_next(&iter)))
914 		zbx_vector_ptr_append(&index, trigdep);
915 
916 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
917 
918 	for (i = 0; i < index.values_num; i++)
919 	{
920 		trigdep = (ZBX_DC_TRIGGER_DEPLIST *)index.values[i];
921 		zabbix_log(LOG_LEVEL_TRACE, "triggerid:" ZBX_FS_UI64 " refcount:%d", trigdep->triggerid,
922 				trigdep->refcount);
923 
924 		for (j = 0; j < trigdep->dependencies.values_num; j++)
925 		{
926 			const ZBX_DC_TRIGGER_DEPLIST	*trigdep_up = (ZBX_DC_TRIGGER_DEPLIST *)trigdep->dependencies.values[j];
927 
928 			zabbix_log(LOG_LEVEL_TRACE, "  triggerid:" ZBX_FS_UI64, trigdep_up->triggerid);
929 		}
930 	}
931 
932 	zbx_vector_ptr_destroy(&index);
933 
934 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
935 }
936 
DCdump_expressions(void)937 static void	DCdump_expressions(void)
938 {
939 	ZBX_DC_EXPRESSION	*expression;
940 	zbx_hashset_iter_t	iter;
941 	int			i;
942 	zbx_vector_ptr_t	index;
943 
944 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
945 
946 	zbx_vector_ptr_create(&index);
947 	zbx_hashset_iter_reset(&config->expressions, &iter);
948 
949 	while (NULL != (expression = (ZBX_DC_EXPRESSION *)zbx_hashset_iter_next(&iter)))
950 		zbx_vector_ptr_append(&index, expression);
951 
952 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
953 
954 	for (i = 0; i < index.values_num; i++)
955 	{
956 		expression = (ZBX_DC_EXPRESSION *)index.values[i];
957 		zabbix_log(LOG_LEVEL_TRACE, "expressionid:" ZBX_FS_UI64 " regexp:'%s' expression:'%s delimiter:%d"
958 				" type:%u case_sensitive:%u", expression->expressionid, expression->regexp,
959 				expression->expression, expression->delimiter, expression->type,
960 				expression->case_sensitive);
961 	}
962 
963 	zbx_vector_ptr_destroy(&index);
964 
965 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
966 }
967 
DCdump_actions(void)968 static void	DCdump_actions(void)
969 {
970 	zbx_dc_action_t		*action;
971 	zbx_hashset_iter_t	iter;
972 	int			i, j;
973 	zbx_vector_ptr_t	index;
974 
975 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
976 
977 	zbx_vector_ptr_create(&index);
978 	zbx_hashset_iter_reset(&config->actions, &iter);
979 
980 	while (NULL != (action = (zbx_dc_action_t *)zbx_hashset_iter_next(&iter)))
981 		zbx_vector_ptr_append(&index, action);
982 
983 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
984 
985 	for (i = 0; i < index.values_num; i++)
986 	{
987 		action = (zbx_dc_action_t *)index.values[i];
988 		zabbix_log(LOG_LEVEL_TRACE, "actionid:" ZBX_FS_UI64 " formula:'%s' eventsource:%u evaltype:%u"
989 				" opflags:%x", action->actionid, action->formula, action->eventsource, action->evaltype,
990 				action->opflags);
991 
992 		for (j = 0; j < action->conditions.values_num; j++)
993 		{
994 			zbx_dc_action_condition_t	*condition = (zbx_dc_action_condition_t *)action->conditions.values[j];
995 
996 			zabbix_log(LOG_LEVEL_TRACE, "  conditionid:" ZBX_FS_UI64 " conditiontype:%u operator:%u"
997 					" value:'%s' value2:'%s'", condition->conditionid, condition->conditiontype,
998 					condition->op, condition->value, condition->value2);
999 		}
1000 	}
1001 
1002 	zbx_vector_ptr_destroy(&index);
1003 
1004 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
1005 }
1006 
DCdump_corr_conditions(zbx_dc_correlation_t * correlation)1007 static void	DCdump_corr_conditions(zbx_dc_correlation_t *correlation)
1008 {
1009 	int			i;
1010 	zbx_vector_ptr_t	index;
1011 
1012 	zbx_vector_ptr_create(&index);
1013 
1014 	zbx_vector_ptr_append_array(&index, correlation->conditions.values, correlation->conditions.values_num);
1015 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1016 
1017 	zabbix_log(LOG_LEVEL_TRACE, "  conditions:");
1018 
1019 	for (i = 0; i < index.values_num; i++)
1020 	{
1021 		zbx_dc_corr_condition_t	*condition = (zbx_dc_corr_condition_t *)index.values[i];
1022 		zabbix_log(LOG_LEVEL_TRACE, "      conditionid:" ZBX_FS_UI64 " type:%d",
1023 				condition->corr_conditionid, condition->type);
1024 
1025 		switch (condition->type)
1026 		{
1027 			case ZBX_CORR_CONDITION_EVENT_TAG_PAIR:
1028 				zabbix_log(LOG_LEVEL_TRACE, "        oldtag:'%s' newtag:'%s'",
1029 						condition->data.tag_pair.oldtag, condition->data.tag_pair.newtag);
1030 				break;
1031 			case ZBX_CORR_CONDITION_NEW_EVENT_HOSTGROUP:
1032 				zabbix_log(LOG_LEVEL_TRACE, "        groupid:" ZBX_FS_UI64 " op:%u",
1033 						condition->data.group.groupid, condition->data.group.op);
1034 				break;
1035 			case ZBX_CORR_CONDITION_NEW_EVENT_TAG:
1036 			case ZBX_CORR_CONDITION_OLD_EVENT_TAG:
1037 				zabbix_log(LOG_LEVEL_TRACE, "        tag:'%s'", condition->data.tag.tag);
1038 				break;
1039 			case ZBX_CORR_CONDITION_NEW_EVENT_TAG_VALUE:
1040 			case ZBX_CORR_CONDITION_OLD_EVENT_TAG_VALUE:
1041 				zabbix_log(LOG_LEVEL_TRACE, "        tag:'%s' value:'%s'",
1042 						condition->data.tag_value.tag, condition->data.tag_value.value);
1043 				break;
1044 		}
1045 	}
1046 
1047 	zbx_vector_ptr_destroy(&index);
1048 }
1049 
DCdump_corr_operations(zbx_dc_correlation_t * correlation)1050 static void	DCdump_corr_operations(zbx_dc_correlation_t *correlation)
1051 {
1052 	int			i;
1053 	zbx_vector_ptr_t	index;
1054 
1055 	zbx_vector_ptr_create(&index);
1056 
1057 	zbx_vector_ptr_append_array(&index, correlation->operations.values, correlation->operations.values_num);
1058 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1059 
1060 	zabbix_log(LOG_LEVEL_TRACE, "  operations:");
1061 
1062 	for (i = 0; i < index.values_num; i++)
1063 	{
1064 		zbx_dc_corr_operation_t	*operation = (zbx_dc_corr_operation_t *)index.values[i];
1065 		zabbix_log(LOG_LEVEL_TRACE, "      operetionid:" ZBX_FS_UI64 " type:%d",
1066 				operation->corr_operationid, operation->type);
1067 	}
1068 
1069 	zbx_vector_ptr_destroy(&index);
1070 }
1071 
DCdump_correlations(void)1072 static void	DCdump_correlations(void)
1073 {
1074 	zbx_dc_correlation_t	*correlation;
1075 	zbx_hashset_iter_t	iter;
1076 	int			i;
1077 	zbx_vector_ptr_t	index;
1078 
1079 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
1080 
1081 	zbx_vector_ptr_create(&index);
1082 	zbx_hashset_iter_reset(&config->correlations, &iter);
1083 
1084 	while (NULL != (correlation = (zbx_dc_correlation_t *)zbx_hashset_iter_next(&iter)))
1085 		zbx_vector_ptr_append(&index, correlation);
1086 
1087 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1088 
1089 	for (i = 0; i < index.values_num; i++)
1090 	{
1091 		correlation = (zbx_dc_correlation_t *)index.values[i];
1092 		zabbix_log(LOG_LEVEL_TRACE, "correlationid:" ZBX_FS_UI64 " name:'%s' evaltype:%u formula:'%s'",
1093 				correlation->correlationid, correlation->name, correlation->evaltype,
1094 				correlation->formula);
1095 
1096 		DCdump_corr_conditions(correlation);
1097 		DCdump_corr_operations(correlation);
1098 	}
1099 
1100 	zbx_vector_ptr_destroy(&index);
1101 
1102 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
1103 }
1104 
DCdump_host_group_hosts(zbx_dc_hostgroup_t * group)1105 static void	DCdump_host_group_hosts(zbx_dc_hostgroup_t *group)
1106 {
1107 	zbx_hashset_iter_t	iter;
1108 	int			i;
1109 	zbx_vector_uint64_t	index;
1110 	zbx_uint64_t		*phostid;
1111 
1112 	zbx_vector_uint64_create(&index);
1113 	zbx_hashset_iter_reset(&group->hostids, &iter);
1114 
1115 	while (NULL != (phostid = (zbx_uint64_t *)zbx_hashset_iter_next(&iter)))
1116 		zbx_vector_uint64_append_ptr(&index, phostid);
1117 
1118 	zbx_vector_uint64_sort(&index, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
1119 
1120 	zabbix_log(LOG_LEVEL_TRACE, "  hosts:");
1121 
1122 	for (i = 0; i < index.values_num; i++)
1123 		zabbix_log(LOG_LEVEL_TRACE, "    hostid:" ZBX_FS_UI64, index.values[i]);
1124 
1125 	zbx_vector_uint64_destroy(&index);
1126 }
1127 
DCdump_host_groups(void)1128 static void	DCdump_host_groups(void)
1129 {
1130 	zbx_dc_hostgroup_t	*group;
1131 	zbx_hashset_iter_t	iter;
1132 	int			i;
1133 	zbx_vector_ptr_t	index;
1134 
1135 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
1136 
1137 	zbx_vector_ptr_create(&index);
1138 	zbx_hashset_iter_reset(&config->hostgroups, &iter);
1139 
1140 	while (NULL != (group = (zbx_dc_hostgroup_t *)zbx_hashset_iter_next(&iter)))
1141 		zbx_vector_ptr_append(&index, group);
1142 
1143 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1144 
1145 	for (i = 0; i < index.values_num; i++)
1146 	{
1147 		group = (zbx_dc_hostgroup_t *)index.values[i];
1148 		zabbix_log(LOG_LEVEL_TRACE, "groupid:" ZBX_FS_UI64 " name:'%s'", group->groupid, group->name);
1149 
1150 		if (0 != group->hostids.num_data)
1151 			DCdump_host_group_hosts(group);
1152 	}
1153 
1154 	zbx_vector_ptr_destroy(&index);
1155 
1156 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
1157 }
1158 
DCdump_host_group_index(void)1159 static void	DCdump_host_group_index(void)
1160 {
1161 	zbx_dc_hostgroup_t	*group;
1162 	int			i;
1163 
1164 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
1165 
1166 	zabbix_log(LOG_LEVEL_TRACE, "group index:");
1167 
1168 	for (i = 0; i < config->hostgroups_name.values_num; i++)
1169 	{
1170 		group = (zbx_dc_hostgroup_t *)config->hostgroups_name.values[i];
1171 		zabbix_log(LOG_LEVEL_TRACE, "  %s", group->name);
1172 	}
1173 
1174 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
1175 }
1176 
DCdump_maintenance_groups(zbx_dc_maintenance_t * maintenance)1177 static void	DCdump_maintenance_groups(zbx_dc_maintenance_t *maintenance)
1178 {
1179 	int			i;
1180 	zbx_vector_uint64_t	index;
1181 
1182 	zbx_vector_uint64_create(&index);
1183 
1184 	if (0 != maintenance->groupids.values_num)
1185 	{
1186 		zbx_vector_uint64_append_array(&index, maintenance->groupids.values, maintenance->groupids.values_num);
1187 		zbx_vector_uint64_sort(&index, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
1188 	}
1189 
1190 	zabbix_log(LOG_LEVEL_TRACE, "  groups:");
1191 
1192 	for (i = 0; i < index.values_num; i++)
1193 		zabbix_log(LOG_LEVEL_TRACE, "    groupid:" ZBX_FS_UI64, index.values[i]);
1194 
1195 	zbx_vector_uint64_destroy(&index);
1196 }
1197 
DCdump_maintenance_hosts(zbx_dc_maintenance_t * maintenance)1198 static void	DCdump_maintenance_hosts(zbx_dc_maintenance_t *maintenance)
1199 {
1200 	int			i;
1201 	zbx_vector_uint64_t	index;
1202 
1203 	zbx_vector_uint64_create(&index);
1204 
1205 	if (0 != maintenance->hostids.values_num)
1206 	{
1207 		zbx_vector_uint64_append_array(&index, maintenance->hostids.values, maintenance->hostids.values_num);
1208 		zbx_vector_uint64_sort(&index, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
1209 	}
1210 
1211 	zabbix_log(LOG_LEVEL_TRACE, "  hosts:");
1212 
1213 	for (i = 0; i < index.values_num; i++)
1214 		zabbix_log(LOG_LEVEL_TRACE, "    hostid:" ZBX_FS_UI64, index.values[i]);
1215 
1216 	zbx_vector_uint64_destroy(&index);
1217 }
1218 
maintenance_tag_compare(const void * v1,const void * v2)1219 static int	maintenance_tag_compare(const void *v1, const void *v2)
1220 {
1221 	const zbx_dc_maintenance_tag_t	*tag1 = *(const zbx_dc_maintenance_tag_t **)v1;
1222 	const zbx_dc_maintenance_tag_t	*tag2 = *(const zbx_dc_maintenance_tag_t **)v2;
1223 	int				ret;
1224 
1225 	if (0 != (ret = (strcmp(tag1->tag, tag2->tag))))
1226 		return ret;
1227 
1228 	if (0 != (ret = (strcmp(tag1->value, tag2->value))))
1229 		return ret;
1230 
1231 	ZBX_RETURN_IF_NOT_EQUAL(tag1->op, tag2->op);
1232 
1233 	return 0;
1234 }
1235 
DCdump_maintenance_tags(zbx_dc_maintenance_t * maintenance)1236 static void	DCdump_maintenance_tags(zbx_dc_maintenance_t *maintenance)
1237 {
1238 	int			i;
1239 	zbx_vector_ptr_t	index;
1240 
1241 	zbx_vector_ptr_create(&index);
1242 
1243 	if (0 != maintenance->tags.values_num)
1244 	{
1245 		zbx_vector_ptr_append_array(&index, maintenance->tags.values, maintenance->tags.values_num);
1246 		zbx_vector_ptr_sort(&index, maintenance_tag_compare);
1247 	}
1248 
1249 	zabbix_log(LOG_LEVEL_TRACE, "  tags:");
1250 
1251 	for (i = 0; i < index.values_num; i++)
1252 	{
1253 		zbx_dc_maintenance_tag_t	*tag = (zbx_dc_maintenance_tag_t *)index.values[i];
1254 		zabbix_log(LOG_LEVEL_TRACE, "    maintenancetagid:" ZBX_FS_UI64 " operator:%u tag:'%s' value:'%s'",
1255 				tag->maintenancetagid, tag->op, tag->tag, tag->value);
1256 	}
1257 
1258 	zbx_vector_ptr_destroy(&index);
1259 }
1260 
DCdump_maintenance_periods(zbx_dc_maintenance_t * maintenance)1261 static void	DCdump_maintenance_periods(zbx_dc_maintenance_t *maintenance)
1262 {
1263 	int			i;
1264 	zbx_vector_ptr_t	index;
1265 
1266 	zbx_vector_ptr_create(&index);
1267 
1268 	zbx_vector_ptr_append_array(&index, maintenance->periods.values, maintenance->periods.values_num);
1269 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1270 
1271 	zabbix_log(LOG_LEVEL_TRACE, "  periods:");
1272 
1273 	for (i = 0; i < index.values_num; i++)
1274 	{
1275 		zbx_dc_maintenance_period_t	*period = (zbx_dc_maintenance_period_t *)index.values[i];
1276 		zabbix_log(LOG_LEVEL_TRACE, "    timeperiodid:" ZBX_FS_UI64 " type:%u every:%d month:%d dayofweek:%d"
1277 				" day:%d start_time:%d period:%d start_date:%d",
1278 				period->timeperiodid, period->type, period->every, period->month, period->dayofweek,
1279 				period->day, period->start_time, period->period, period->start_date);
1280 	}
1281 
1282 	zbx_vector_ptr_destroy(&index);
1283 }
1284 
DCdump_maintenances(void)1285 static void	DCdump_maintenances(void)
1286 {
1287 	zbx_dc_maintenance_t	*maintenance;
1288 	zbx_hashset_iter_t	iter;
1289 	int			i;
1290 	zbx_vector_ptr_t	index;
1291 
1292 	zabbix_log(LOG_LEVEL_TRACE, "In %s()", __func__);
1293 
1294 	zbx_vector_ptr_create(&index);
1295 	zbx_hashset_iter_reset(&config->maintenances, &iter);
1296 
1297 	while (NULL != (maintenance = (zbx_dc_maintenance_t *)zbx_hashset_iter_next(&iter)))
1298 		zbx_vector_ptr_append(&index, maintenance);
1299 
1300 	zbx_vector_ptr_sort(&index, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
1301 
1302 	for (i = 0; i < index.values_num; i++)
1303 	{
1304 		maintenance = (zbx_dc_maintenance_t *)index.values[i];
1305 		zabbix_log(LOG_LEVEL_TRACE, "maintenanceid:" ZBX_FS_UI64 " type:%u tag_evaltype:%u active_since:%d"
1306 				" active_until:%d", maintenance->maintenanceid, maintenance->type,
1307 				maintenance->tags_evaltype, maintenance->active_since, maintenance->active_until);
1308 		zabbix_log(LOG_LEVEL_TRACE, "  state:%u running_since:%d running_until:%d",
1309 				maintenance->state, maintenance->running_since, maintenance->running_until);
1310 
1311 		DCdump_maintenance_groups(maintenance);
1312 		DCdump_maintenance_hosts(maintenance);
1313 		DCdump_maintenance_tags(maintenance);
1314 		DCdump_maintenance_periods(maintenance);
1315 	}
1316 
1317 	zbx_vector_ptr_destroy(&index);
1318 
1319 	zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
1320 }
1321 
DCdump_configuration(void)1322 void	DCdump_configuration(void)
1323 {
1324 	DCdump_config();
1325 	DCdump_hosts();
1326 	DCdump_host_tags();
1327 	DCdump_proxies();
1328 	DCdump_ipmihosts();
1329 	DCdump_host_inventories();
1330 	DCdump_htmpls();
1331 	DCdump_kvs_paths();
1332 	DCdump_gmacros();
1333 	DCdump_hmacros();
1334 	DCdump_interfaces();
1335 	DCdump_items();
1336 	DCdump_interface_snmpitems();
1337 	DCdump_template_items();
1338 	DCdump_master_items();
1339 	DCdump_prototype_items();
1340 	DCdump_triggers();
1341 	DCdump_trigdeps();
1342 	DCdump_functions();
1343 	DCdump_expressions();
1344 	DCdump_actions();
1345 	DCdump_correlations();
1346 	DCdump_host_groups();
1347 	DCdump_host_group_index();
1348 	DCdump_maintenances();
1349 }
1350