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_DBCONFIG_H
21 #define ZABBIX_DBCONFIG_H
22 
23 #ifndef ZBX_DBCONFIG_IMPL
24 #	error This header must be used by configuration cache implementation
25 #endif
26 
27 typedef struct
28 {
29 	zbx_uint64_t		triggerid;
30 	const char		*description;
31 	const char		*expression;
32 	const char		*recovery_expression;
33 	const char		*error;
34 	const char		*correlation_tag;
35 	int			lastchange;
36 	int			nextcheck;		/* time of next trigger recalculation,    */
37 							/* valid for triggers with time functions */
38 	unsigned char		topoindex;
39 	unsigned char		priority;
40 	unsigned char		type;
41 	unsigned char		value;
42 	unsigned char		state;
43 	unsigned char		locked;
44 	unsigned char		status;
45 	unsigned char		functional;		/* see TRIGGER_FUNCTIONAL_* defines      */
46 	unsigned char		recovery_mode;		/* see TRIGGER_RECOVERY_MODE_* defines   */
47 	unsigned char		correlation_mode;	/* see ZBX_TRIGGER_CORRELATION_* defines */
48 	unsigned char		timer;			/* see ZBX_TRIGGER_TIMER_* defines       */
49 
50 	zbx_vector_ptr_t	tags;
51 }
52 ZBX_DC_TRIGGER;
53 
54 typedef struct zbx_dc_trigger_deplist
55 {
56 	zbx_uint64_t		triggerid;
57 	int			refcount;
58 	ZBX_DC_TRIGGER		*trigger;
59 	zbx_vector_ptr_t	dependencies;
60 }
61 ZBX_DC_TRIGGER_DEPLIST;
62 
63 typedef struct
64 {
65 	zbx_uint64_t	functionid;
66 	zbx_uint64_t	triggerid;
67 	zbx_uint64_t	itemid;
68 	const char	*function;
69 	const char	*parameter;
70 	unsigned char	timer;
71 }
72 ZBX_DC_FUNCTION;
73 
74 typedef struct
75 {
76 	zbx_uint64_t		itemid;
77 	zbx_uint64_t		hostid;
78 	zbx_uint64_t		interfaceid;
79 	zbx_uint64_t		lastlogsize;
80 	zbx_uint64_t		valuemapid;
81 	const char		*key;
82 	const char		*port;
83 	const char		*error;
84 	const char		*delay;
85 	ZBX_DC_TRIGGER		**triggers;
86 	int			nextcheck;
87 	int			lastclock;
88 	int			mtime;
89 	int			data_expected_from;
90 	int			history_sec;
91 	unsigned char		history;
92 	unsigned char		type;
93 	unsigned char		value_type;
94 	unsigned char		poller_type;
95 	unsigned char		state;
96 	unsigned char		db_state;
97 	unsigned char		inventory_link;
98 	unsigned char		location;
99 	unsigned char		flags;
100 	unsigned char		status;
101 	unsigned char		queue_priority;
102 	unsigned char		schedulable;
103 	unsigned char		update_triggers;
104 }
105 ZBX_DC_ITEM;
106 
107 typedef struct
108 {
109 	zbx_uint64_t	hostid;
110 	const char	*key;
111 	ZBX_DC_ITEM	*item_ptr;
112 }
113 ZBX_DC_ITEM_HK;
114 
115 typedef struct
116 {
117 	zbx_uint64_t	itemid;
118 	const char	*units;
119 	unsigned char	trends;
120 	int		trends_sec;
121 }
122 ZBX_DC_NUMITEM;
123 
124 typedef struct
125 {
126 	zbx_uint64_t	itemid;
127 	const char	*snmp_oid;
128 	const char	*snmp_community;
129 	const char	*snmpv3_securityname;
130 	const char	*snmpv3_authpassphrase;
131 	const char	*snmpv3_privpassphrase;
132 	const char	*snmpv3_contextname;
133 	unsigned char	snmpv3_securitylevel;
134 	unsigned char	snmpv3_authprotocol;
135 	unsigned char	snmpv3_privprotocol;
136 	unsigned char	snmp_oid_type;
137 }
138 ZBX_DC_SNMPITEM;
139 
140 typedef struct
141 {
142 	zbx_uint64_t	itemid;
143 	const char	*ipmi_sensor;
144 }
145 ZBX_DC_IPMIITEM;
146 
147 typedef struct
148 {
149 	zbx_uint64_t	itemid;
150 	const char	*trapper_hosts;
151 }
152 ZBX_DC_TRAPITEM;
153 
154 typedef struct
155 {
156 	zbx_uint64_t	itemid;
157 	zbx_uint64_t	master_itemid;
158 	zbx_uint64_t	last_master_itemid;
159 }
160 ZBX_DC_DEPENDENTITEM;
161 
162 typedef struct
163 {
164 	zbx_uint64_t	itemid;
165 	const char	*logtimefmt;
166 }
167 ZBX_DC_LOGITEM;
168 
169 typedef struct
170 {
171 	zbx_uint64_t	itemid;
172 	const char	*params;
173 	const char	*username;
174 	const char	*password;
175 }
176 ZBX_DC_DBITEM;
177 
178 typedef struct
179 {
180 	zbx_uint64_t	itemid;
181 	const char	*username;
182 	const char	*publickey;
183 	const char	*privatekey;
184 	const char	*password;
185 	const char	*params;
186 	unsigned char	authtype;
187 }
188 ZBX_DC_SSHITEM;
189 
190 typedef struct
191 {
192 	zbx_uint64_t	itemid;
193 	const char	*username;
194 	const char	*password;
195 	const char	*params;
196 }
197 ZBX_DC_TELNETITEM;
198 
199 typedef struct
200 {
201 	zbx_uint64_t	itemid;
202 	const char	*username;
203 	const char	*password;
204 }
205 ZBX_DC_SIMPLEITEM;
206 
207 typedef struct
208 {
209 	zbx_uint64_t	itemid;
210 	const char	*username;
211 	const char	*password;
212 	const char	*jmx_endpoint;
213 }
214 ZBX_DC_JMXITEM;
215 
216 typedef struct
217 {
218 	zbx_uint64_t	itemid;
219 	const char	*params;
220 }
221 ZBX_DC_CALCITEM;
222 
223 typedef struct
224 {
225 	zbx_uint64_t		itemid;
226 	zbx_vector_uint64_t	dep_itemids;
227 }
228 ZBX_DC_MASTERITEM;
229 
230 typedef struct
231 {
232 	zbx_uint64_t		itemid;
233 	zbx_vector_ptr_t	preproc_ops;
234 }
235 ZBX_DC_PREPROCITEM;
236 
237 typedef struct
238 {
239 	zbx_uint64_t	itemid;
240 	const char	*timeout;
241 	const char	*url;
242 	const char	*query_fields;
243 	const char	*status_codes;
244 	const char	*http_proxy;
245 	const char	*headers;
246 	const char	*username;
247 	const char	*ssl_cert_file;
248 	const char	*ssl_key_file;
249 	const char	*ssl_key_password;
250 	const char	*password;
251 	const char	*posts;
252 	const char	*trapper_hosts;
253 	unsigned char	authtype;
254 	unsigned char	follow_redirects;
255 	unsigned char	post_type;
256 	unsigned char	retrieve_mode;
257 	unsigned char	request_method;
258 	unsigned char	output_format;
259 	unsigned char	verify_peer;
260 	unsigned char	verify_host;
261 	unsigned char	allow_traps;
262 }
263 ZBX_DC_HTTPITEM;
264 
265 typedef zbx_item_history_value_t	ZBX_DC_DELTAITEM;
266 
267 #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
268 typedef struct
269 {
270 	const char	*tls_psk_identity;	/* pre-shared key identity           */
271 	const char	*tls_psk;		/* pre-shared key value (hex-string) */
272 	unsigned int	refcount;		/* reference count                   */
273 }
274 ZBX_DC_PSK;
275 #endif
276 
277 typedef struct
278 {
279 	zbx_uint64_t	hostid;
280 	zbx_uint64_t	proxy_hostid;
281 	zbx_uint64_t	items_active_normal;		/* On enabled hosts these two fields store number of enabled */
282 	zbx_uint64_t	items_active_notsupported;	/* and supported items and enabled and not supported items.  */
283 	zbx_uint64_t	items_disabled;			/* On "hosts" corresponding to proxies this and two fields   */
284 							/* above store cumulative statistics for all hosts monitored */
285 							/* by a particular proxy. */
286 							/* NOTE: On disabled hosts all items are counted as disabled. */
287 	zbx_uint64_t	maintenanceid;
288 
289 	const char	*host;
290 	const char	*name;
291 	int		maintenance_from;
292 	int		data_expected_from;
293 	int		errors_from;
294 	int		disable_until;
295 	int		snmp_errors_from;
296 	int		snmp_disable_until;
297 	int		ipmi_errors_from;
298 	int		ipmi_disable_until;
299 	int		jmx_errors_from;
300 	int		jmx_disable_until;
301 
302 	/* item statistics per interface type */
303 	int		items_num;
304 	int		snmp_items_num;
305 	int		ipmi_items_num;
306 	int		jmx_items_num;
307 
308 	/* timestamp of last availability status (available/error) field change on any interface */
309 	int		availability_ts;
310 
311 	unsigned char	maintenance_status;
312 	unsigned char	maintenance_type;
313 	unsigned char	available;
314 	unsigned char	snmp_available;
315 	unsigned char	ipmi_available;
316 	unsigned char	jmx_available;
317 	unsigned char	status;
318 
319 	/* flag to reset host availability to unknown */
320 	unsigned char	reset_availability;
321 
322 	/* flag to force update for all items */
323 	unsigned char	update_items;
324 
325 	/* 'tls_connect' and 'tls_accept' must be respected even if encryption support is not compiled in */
326 	unsigned char	tls_connect;
327 	unsigned char	tls_accept;
328 #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
329 	const char	*tls_issuer;
330 	const char	*tls_subject;
331 	ZBX_DC_PSK	*tls_dc_psk;
332 #endif
333 	const char	*error;
334 	const char	*snmp_error;
335 	const char	*ipmi_error;
336 	const char	*jmx_error;
337 
338 	zbx_vector_ptr_t	interfaces_v;	/* for quick finding of all host interfaces in */
339 						/* 'config->interfaces' hashset */
340 }
341 ZBX_DC_HOST;
342 
343 typedef struct
344 {
345 	zbx_uint64_t	hostid;
346 	unsigned char	inventory_mode;
347 	const char	*values[HOST_INVENTORY_FIELD_COUNT];
348 }
349 ZBX_DC_HOST_INVENTORY;
350 
351 typedef struct
352 {
353 	const char	*host;
354 	ZBX_DC_HOST	*host_ptr;
355 }
356 ZBX_DC_HOST_H;
357 
358 typedef struct
359 {
360 	zbx_uint64_t	hostid;
361 	zbx_uint64_t	hosts_monitored;	/* number of enabled hosts assigned to proxy */
362 	zbx_uint64_t	hosts_not_monitored;	/* number of disabled hosts assigned to proxy */
363 	double		required_performance;
364 	int		proxy_config_nextcheck;
365 	int		proxy_data_nextcheck;
366 	int		proxy_tasks_nextcheck;
367 	int		nextcheck;
368 	int		lastaccess;
369 	int		last_cfg_error_time;	/* time when passive proxy misconfiguration error was seen */
370 						/* or 0 if no error */
371 	int		version;
372 	unsigned char	location;
373 	unsigned char	auto_compress;
374 	const char	*proxy_address;
375 	int		last_version_error_time;
376 }
377 ZBX_DC_PROXY;
378 
379 typedef struct
380 {
381 	zbx_uint64_t	hostid;
382 	const char	*ipmi_username;
383 	const char	*ipmi_password;
384 	signed char	ipmi_authtype;
385 	unsigned char	ipmi_privilege;
386 }
387 ZBX_DC_IPMIHOST;
388 
389 typedef struct
390 {
391 	zbx_uint64_t		hostid;
392 	zbx_vector_uint64_t	templateids;
393 }
394 ZBX_DC_HTMPL;
395 
396 typedef struct
397 {
398 	zbx_uint64_t	globalmacroid;
399 	const char	*macro;
400 	const char	*context;
401 	const char	*value;
402 }
403 ZBX_DC_GMACRO;
404 
405 typedef struct
406 {
407 	const char		*macro;
408 	zbx_vector_ptr_t	gmacros;
409 }
410 ZBX_DC_GMACRO_M;
411 
412 typedef struct
413 {
414 	zbx_uint64_t	hostmacroid;
415 	zbx_uint64_t	hostid;
416 	const char	*macro;
417 	const char	*context;
418 	const char	*value;
419 }
420 ZBX_DC_HMACRO;
421 
422 typedef struct
423 {
424 	zbx_uint64_t		hostid;
425 	const char		*macro;
426 	zbx_vector_ptr_t	hmacros;
427 }
428 ZBX_DC_HMACRO_HM;
429 
430 typedef struct
431 {
432 	zbx_uint64_t	interfaceid;
433 	zbx_uint64_t	hostid;
434 	const char	*ip;
435 	const char	*dns;
436 	const char	*port;
437 	unsigned char	type;
438 	unsigned char	main;
439 	unsigned char	useip;
440 	unsigned char	bulk;
441 	unsigned char	max_snmp_succeed;
442 	unsigned char	min_snmp_fail;
443 }
444 ZBX_DC_INTERFACE;
445 
446 typedef struct
447 {
448 	zbx_uint64_t		hostid;
449 	ZBX_DC_INTERFACE	*interface_ptr;
450 	unsigned char		type;
451 }
452 ZBX_DC_INTERFACE_HT;
453 
454 typedef struct
455 {
456 	const char		*addr;
457 	zbx_vector_uint64_t	interfaceids;
458 }
459 ZBX_DC_INTERFACE_ADDR;
460 
461 typedef struct
462 {
463 	zbx_uint64_t		interfaceid;
464 	zbx_vector_uint64_t	itemids;
465 }
466 ZBX_DC_INTERFACE_ITEM;
467 
468 typedef struct
469 {
470 	const char		*name;
471 	zbx_vector_uint64_t	expressionids;
472 }
473 ZBX_DC_REGEXP;
474 
475 typedef struct
476 {
477 	zbx_uint64_t	expressionid;
478 	const char	*expression;
479 	const char	*regexp;
480 	char		delimiter;
481 	unsigned char	type;
482 	unsigned char	case_sensitive;
483 }
484 ZBX_DC_EXPRESSION;
485 
486 typedef struct
487 {
488 	const char	*severity_name[TRIGGER_SEVERITY_COUNT];
489 	zbx_uint64_t	discovery_groupid;
490 	int		default_inventory_mode;
491 	int		refresh_unsupported;
492 	unsigned char	snmptrap_logging;
493 	/* housekeeping related configuration data */
494 	zbx_config_hk_t	hk;
495 }
496 ZBX_DC_CONFIG_TABLE;
497 
498 typedef struct
499 {
500 	zbx_uint64_t	hosts_monitored;		/* total number of enabled hosts */
501 	zbx_uint64_t	hosts_not_monitored;		/* total number of disabled hosts */
502 	zbx_uint64_t	items_active_normal;		/* total number of enabled and supported items */
503 	zbx_uint64_t	items_active_notsupported;	/* total number of enabled and not supported items */
504 	zbx_uint64_t	items_disabled;			/* total number of disabled items */
505 							/* (all items of disabled host are counted as disabled) */
506 	zbx_uint64_t	triggers_enabled_ok;		/* total number of enabled triggers with value OK */
507 	zbx_uint64_t	triggers_enabled_problem;	/* total number of enabled triggers with value PROBLEM */
508 	zbx_uint64_t	triggers_disabled;		/* total number of disabled triggers */
509 							/* (if at least one item or host involved in trigger is */
510 							/* disabled then trigger is counted as disabled) */
511 	double		required_performance;		/* required performance of server (values per second) */
512 	time_t		last_update;
513 }
514 ZBX_DC_STATUS;
515 
516 typedef struct
517 {
518 	zbx_uint64_t	conditionid;
519 	zbx_uint64_t	actionid;
520 	unsigned char	conditiontype;
521 	unsigned char	op;
522 	const char	*value;
523 	const char	*value2;
524 }
525 zbx_dc_action_condition_t;
526 
527 typedef struct
528 {
529 	zbx_uint64_t		actionid;
530 	const char		*formula;
531 	unsigned char		eventsource;
532 	unsigned char		evaltype;
533 	unsigned char		opflags;
534 	zbx_vector_ptr_t	conditions;
535 }
536 zbx_dc_action_t;
537 
538 typedef struct
539 {
540 	zbx_uint64_t	triggertagid;
541 	zbx_uint64_t	triggerid;
542 	const char	*tag;
543 	const char	*value;
544 }
545 zbx_dc_trigger_tag_t;
546 
547 typedef struct
548 {
549 	const char	*tag;
550 }
551 zbx_dc_corr_condition_tag_t;
552 
553 typedef struct
554 {
555 	const char	*tag;
556 	const char	*value;
557 	unsigned char	op;
558 }
559 zbx_dc_corr_condition_tag_value_t;
560 
561 typedef struct
562 {
563 	zbx_uint64_t	groupid;
564 	unsigned char	op;
565 }
566 zbx_dc_corr_condition_group_t;
567 
568 typedef struct
569 {
570 	const char	*oldtag;
571 	const char	*newtag;
572 }
573 zbx_dc_corr_condition_tag_pair_t;
574 
575 typedef union
576 {
577 	zbx_dc_corr_condition_tag_t		tag;
578 	zbx_dc_corr_condition_tag_value_t	tag_value;
579 	zbx_dc_corr_condition_group_t		group;
580 	zbx_dc_corr_condition_tag_pair_t	tag_pair;
581 }
582 zbx_dc_corr_condition_data_t;
583 
584 typedef struct
585 {
586 	zbx_uint64_t			corr_conditionid;
587 	zbx_uint64_t			correlationid;
588 	int				type;
589 
590 	zbx_dc_corr_condition_data_t	data;
591 }
592 zbx_dc_corr_condition_t;
593 
594 typedef struct
595 {
596 	zbx_uint64_t	corr_operationid;
597 	zbx_uint64_t	correlationid;
598 	unsigned char	type;
599 }
600 zbx_dc_corr_operation_t;
601 
602 typedef struct
603 {
604 	zbx_uint64_t		correlationid;
605 	const char		*name;
606 	const char		*formula;
607 	unsigned char		evaltype;
608 
609 	zbx_vector_ptr_t	conditions;
610 	zbx_vector_ptr_t	operations;
611 }
612 zbx_dc_correlation_t;
613 
614 #define ZBX_DC_HOSTGROUP_FLAGS_NONE		0
615 #define ZBX_DC_HOSTGROUP_FLAGS_NESTED_GROUPIDS	1
616 
617 typedef struct
618 {
619 	zbx_uint64_t		groupid;
620 	const char		*name;
621 
622 	zbx_vector_uint64_t	nested_groupids;
623 	zbx_hashset_t		hostids;
624 	unsigned char		flags;
625 }
626 zbx_dc_hostgroup_t;
627 
628 typedef struct
629 {
630 	zbx_uint64_t	item_preprocid;
631 	zbx_uint64_t	itemid;
632 	int		step;
633 	unsigned char	type;
634 	const char	*params;
635 }
636 zbx_dc_preproc_op_t;
637 
638 typedef struct
639 {
640 	zbx_uint64_t		maintenanceid;
641 	unsigned char		type;
642 	unsigned char		tags_evaltype;
643 	unsigned char		state;
644 	int			active_since;
645 	int			active_until;
646 	int			running_since;
647 	int			running_until;
648 	zbx_vector_uint64_t	groupids;
649 	zbx_vector_uint64_t	hostids;
650 	zbx_vector_ptr_t	tags;
651 	zbx_vector_ptr_t	periods;
652 }
653 zbx_dc_maintenance_t;
654 
655 typedef struct
656 {
657 	zbx_uint64_t	maintenancetagid;
658 	zbx_uint64_t	maintenanceid;
659 	unsigned char	op;		/* condition operator */
660 	const char	*tag;
661 	const char	*value;
662 }
663 zbx_dc_maintenance_tag_t;
664 
665 typedef struct
666 {
667 	zbx_uint64_t	timeperiodid;
668 	zbx_uint64_t	maintenanceid;
669 	unsigned char	type;
670 	int		every;
671 	int		month;
672 	int		dayofweek;
673 	int		day;
674 	int		start_time;
675 	int		period;
676 	int		start_date;
677 }
678 zbx_dc_maintenance_period_t;
679 
680 typedef struct
681 {
682 	zbx_uint64_t	triggerid;
683 	int		nextcheck;
684 }
685 zbx_dc_timer_trigger_t;
686 
687 typedef struct
688 {
689 	/* timestamp of the last host availability diff sent to sever, used only by proxies */
690 	int			availability_diff_ts;
691 	int			proxy_lastaccess_ts;
692 	int			sync_ts;
693 	int			item_sync_ts;
694 
695 	unsigned int		internal_actions;		/* number of enabled internal actions */
696 
697 	/* maintenance processing management */
698 	unsigned char		maintenance_update;		/* flag to trigger maintenance update by timers  */
699 	zbx_uint64_t		*maintenance_update_flags;	/* Array of flags to manage timer maintenance updates.*/
700 								/* Each array member contains 0/1 flag for 64 timers  */
701 								/* indicating if the timer must process maintenance.  */
702 
703 	char			*session_token;
704 
705 	zbx_hashset_t		items;
706 	zbx_hashset_t		items_hk;		/* hostid, key */
707 	zbx_hashset_t		numitems;
708 	zbx_hashset_t		snmpitems;
709 	zbx_hashset_t		ipmiitems;
710 	zbx_hashset_t		trapitems;
711 	zbx_hashset_t		dependentitems;
712 	zbx_hashset_t		logitems;
713 	zbx_hashset_t		dbitems;
714 	zbx_hashset_t		sshitems;
715 	zbx_hashset_t		telnetitems;
716 	zbx_hashset_t		simpleitems;
717 	zbx_hashset_t		jmxitems;
718 	zbx_hashset_t		calcitems;
719 	zbx_hashset_t		masteritems;
720 	zbx_hashset_t		preprocitems;
721 	zbx_hashset_t		httpitems;
722 	zbx_hashset_t		functions;
723 	zbx_hashset_t		triggers;
724 	zbx_hashset_t		trigdeps;
725 	zbx_hashset_t		hosts;
726 	zbx_hashset_t		hosts_h;		/* for searching hosts by 'host' name */
727 	zbx_hashset_t		hosts_p;		/* for searching proxies by 'host' name */
728 	zbx_hashset_t		proxies;
729 	zbx_hashset_t		host_inventories;
730 	zbx_hashset_t		host_inventories_auto;	/* for caching of automatically populated host inventories */
731 	zbx_hashset_t		ipmihosts;
732 	zbx_hashset_t		htmpls;
733 	zbx_hashset_t		gmacros;
734 	zbx_hashset_t		gmacros_m;		/* macro */
735 	zbx_hashset_t		hmacros;
736 	zbx_hashset_t		hmacros_hm;		/* hostid, macro */
737 	zbx_hashset_t		interfaces;
738 	zbx_hashset_t		interfaces_ht;		/* hostid, type */
739 	zbx_hashset_t		interface_snmpaddrs;	/* addr, interfaceids for SNMP interfaces */
740 	zbx_hashset_t		interface_snmpitems;	/* interfaceid, itemids for SNMP trap items */
741 	zbx_hashset_t		regexps;
742 	zbx_hashset_t		expressions;
743 	zbx_hashset_t		actions;
744 	zbx_hashset_t		action_conditions;
745 	zbx_hashset_t		trigger_tags;
746 	zbx_hashset_t		correlations;
747 	zbx_hashset_t		corr_conditions;
748 	zbx_hashset_t		corr_operations;
749 	zbx_hashset_t		hostgroups;
750 	zbx_vector_ptr_t	hostgroups_name; 	/* host groups sorted by name */
751 	zbx_hashset_t		preprocops;
752 	zbx_hashset_t		maintenances;
753 	zbx_hashset_t		maintenance_periods;
754 	zbx_hashset_t		maintenance_tags;
755 #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
756 	zbx_hashset_t		psks;			/* for keeping PSK-identity and PSK pairs and for searching */
757 							/* by PSK identity */
758 #endif
759 	zbx_hashset_t		data_sessions;
760 	zbx_binary_heap_t	queues[ZBX_POLLER_TYPE_COUNT];
761 	zbx_binary_heap_t	pqueue;
762 	zbx_binary_heap_t	timer_queue;
763 	zbx_vector_uint64_t	locked_lld_ruleids;	/* for keeping track of lld rules being processed */
764 	ZBX_DC_CONFIG_TABLE	*config;
765 	ZBX_DC_STATUS		*status;
766 	zbx_hashset_t		strpool;
767 }
768 ZBX_DC_CONFIG;
769 
770 extern int	sync_in_progress;
771 extern ZBX_DC_CONFIG	*config;
772 extern zbx_rwlock_t	config_lock;
773 
774 #define	RDLOCK_CACHE	if (0 == sync_in_progress) zbx_rwlock_rdlock(config_lock)
775 #define	WRLOCK_CACHE	if (0 == sync_in_progress) zbx_rwlock_wrlock(config_lock)
776 #define	UNLOCK_CACHE	if (0 == sync_in_progress) zbx_rwlock_unlock(config_lock)
777 
778 #define ZBX_IPMI_DEFAULT_AUTHTYPE	-1
779 #define ZBX_IPMI_DEFAULT_PRIVILEGE	2
780 
781 /* validator function optionally used to validate macro values when expanding user macros */
782 
783 /******************************************************************************
784  *                                                                            *
785  * Function: zbx_macro_value_validator_func_t                                 *
786  *                                                                            *
787  * Purpose: validate macro value when expanding user macros                   *
788  *                                                                            *
789  * Parameters: value   - [IN] the macro value                                 *
790  *                                                                            *
791  * Return value: SUCCEED - the value is valid                                 *
792  *               FAIL    - otherwise                                          *
793  *                                                                            *
794  ******************************************************************************/
795 typedef int (*zbx_macro_value_validator_func_t)(const char *value);
796 
797 char	*zbx_dc_expand_user_macros(const char *text, zbx_uint64_t *hostids, int hostids_num,
798 		zbx_macro_value_validator_func_t validator_func);
799 
800 void	zbx_dc_get_hostids_by_functionids(const zbx_uint64_t *functionids, int functionids_num,
801 		zbx_vector_uint64_t *hostids);
802 
803 void	DCdump_configuration(void);
804 
805 /* utility functions */
806 void	*DCfind_id(zbx_hashset_t *hashset, zbx_uint64_t id, size_t size, int *found);
807 
808 /* string pool */
809 void	zbx_strpool_release(const char *str);
810 int	DCstrpool_replace(int found, const char **curr, const char *new_str);
811 
812 /* host groups */
813 void	dc_get_nested_hostgroupids(zbx_uint64_t groupid, zbx_vector_uint64_t *nested_groupids);
814 void	dc_hostgroup_cache_nested_groupids(zbx_dc_hostgroup_t *parent_group);
815 
816 /* synchronization */
817 typedef struct zbx_dbsync zbx_dbsync_t;
818 
819 void	DCsync_maintenances(zbx_dbsync_t *sync);
820 void	DCsync_maintenance_tags(zbx_dbsync_t *sync);
821 void	DCsync_maintenance_periods(zbx_dbsync_t *sync);
822 void	DCsync_maintenance_groups(zbx_dbsync_t *sync);
823 void	DCsync_maintenance_hosts(zbx_dbsync_t *sync);
824 
825 /* maintenance support */
826 
827 /* number of slots to store maintenance update flags */
828 #define ZBX_MAINTENANCE_UPDATE_FLAGS_NUM()	\
829 		((CONFIG_TIMER_FORKS + sizeof(uint64_t) * 8 - 1) / (sizeof(uint64_t) * 8))
830 
831 
832 #endif
833