1CREATE TABLE users (
2	userid                   bigint                                    NOT NULL,
3	alias                    varchar(100)    DEFAULT ''                NOT NULL,
4	name                     varchar(100)    DEFAULT ''                NOT NULL,
5	surname                  varchar(100)    DEFAULT ''                NOT NULL,
6	passwd                   varchar(32)     DEFAULT ''                NOT NULL,
7	url                      varchar(255)    DEFAULT ''                NOT NULL,
8	autologin                integer         DEFAULT '0'               NOT NULL,
9	autologout               varchar(32)     DEFAULT '15m'             NOT NULL,
10	lang                     varchar(5)      DEFAULT 'en_GB'           NOT NULL,
11	refresh                  varchar(32)     DEFAULT '30s'             NOT NULL,
12	type                     integer         DEFAULT '1'               NOT NULL,
13	theme                    varchar(128)    DEFAULT 'default'         NOT NULL,
14	attempt_failed           integer         DEFAULT 0                 NOT NULL,
15	attempt_ip               varchar(39)     DEFAULT ''                NOT NULL,
16	attempt_clock            integer         DEFAULT 0                 NOT NULL,
17	rows_per_page            integer         DEFAULT 50                NOT NULL,
18	PRIMARY KEY (userid)
19);
20CREATE UNIQUE INDEX users_1 ON users (alias);
21CREATE TABLE maintenances (
22	maintenanceid            bigint                                    NOT NULL,
23	name                     varchar(128)    DEFAULT ''                NOT NULL,
24	maintenance_type         integer         DEFAULT '0'               NOT NULL,
25	description              text            DEFAULT ''                NOT NULL,
26	active_since             integer         DEFAULT '0'               NOT NULL,
27	active_till              integer         DEFAULT '0'               NOT NULL,
28	tags_evaltype            integer         DEFAULT '0'               NOT NULL,
29	PRIMARY KEY (maintenanceid)
30);
31CREATE INDEX maintenances_1 ON maintenances (active_since,active_till);
32CREATE UNIQUE INDEX maintenances_2 ON maintenances (name);
33CREATE TABLE hosts (
34	hostid                   bigint                                    NOT NULL,
35	proxy_hostid             bigint                                    NULL REFERENCES hosts (hostid),
36	host                     varchar(128)    DEFAULT ''                NOT NULL,
37	status                   integer         DEFAULT '0'               NOT NULL,
38	disable_until            integer         DEFAULT '0'               NOT NULL,
39	error                    varchar(2048)   DEFAULT ''                NOT NULL,
40	available                integer         DEFAULT '0'               NOT NULL,
41	errors_from              integer         DEFAULT '0'               NOT NULL,
42	lastaccess               integer         DEFAULT '0'               NOT NULL,
43	ipmi_authtype            integer         DEFAULT '-1'              NOT NULL,
44	ipmi_privilege           integer         DEFAULT '2'               NOT NULL,
45	ipmi_username            varchar(16)     DEFAULT ''                NOT NULL,
46	ipmi_password            varchar(20)     DEFAULT ''                NOT NULL,
47	ipmi_disable_until       integer         DEFAULT '0'               NOT NULL,
48	ipmi_available           integer         DEFAULT '0'               NOT NULL,
49	snmp_disable_until       integer         DEFAULT '0'               NOT NULL,
50	snmp_available           integer         DEFAULT '0'               NOT NULL,
51	maintenanceid            bigint                                    NULL REFERENCES maintenances (maintenanceid),
52	maintenance_status       integer         DEFAULT '0'               NOT NULL,
53	maintenance_type         integer         DEFAULT '0'               NOT NULL,
54	maintenance_from         integer         DEFAULT '0'               NOT NULL,
55	ipmi_errors_from         integer         DEFAULT '0'               NOT NULL,
56	snmp_errors_from         integer         DEFAULT '0'               NOT NULL,
57	ipmi_error               varchar(2048)   DEFAULT ''                NOT NULL,
58	snmp_error               varchar(2048)   DEFAULT ''                NOT NULL,
59	jmx_disable_until        integer         DEFAULT '0'               NOT NULL,
60	jmx_available            integer         DEFAULT '0'               NOT NULL,
61	jmx_errors_from          integer         DEFAULT '0'               NOT NULL,
62	jmx_error                varchar(2048)   DEFAULT ''                NOT NULL,
63	name                     varchar(128)    DEFAULT ''                NOT NULL,
64	flags                    integer         DEFAULT '0'               NOT NULL,
65	templateid               bigint                                    NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
66	description              text            DEFAULT ''                NOT NULL,
67	tls_connect              integer         DEFAULT '1'               NOT NULL,
68	tls_accept               integer         DEFAULT '1'               NOT NULL,
69	tls_issuer               varchar(1024)   DEFAULT ''                NOT NULL,
70	tls_subject              varchar(1024)   DEFAULT ''                NOT NULL,
71	tls_psk_identity         varchar(128)    DEFAULT ''                NOT NULL,
72	tls_psk                  varchar(512)    DEFAULT ''                NOT NULL,
73	proxy_address            varchar(255)    DEFAULT ''                NOT NULL,
74	auto_compress            integer         DEFAULT '1'               NOT NULL,
75	PRIMARY KEY (hostid)
76);
77CREATE INDEX hosts_1 ON hosts (host);
78CREATE INDEX hosts_2 ON hosts (status);
79CREATE INDEX hosts_3 ON hosts (proxy_hostid);
80CREATE INDEX hosts_4 ON hosts (name);
81CREATE INDEX hosts_5 ON hosts (maintenanceid);
82CREATE TABLE hstgrp (
83	groupid                  bigint                                    NOT NULL,
84	name                     varchar(255)    DEFAULT ''                NOT NULL,
85	internal                 integer         DEFAULT '0'               NOT NULL,
86	flags                    integer         DEFAULT '0'               NOT NULL,
87	PRIMARY KEY (groupid)
88);
89CREATE INDEX hstgrp_1 ON hstgrp (name);
90CREATE TABLE group_prototype (
91	group_prototypeid        bigint                                    NOT NULL,
92	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
93	name                     varchar(255)    DEFAULT ''                NOT NULL,
94	groupid                  bigint                                    NULL REFERENCES hstgrp (groupid),
95	templateid               bigint                                    NULL REFERENCES group_prototype (group_prototypeid) ON DELETE CASCADE,
96	PRIMARY KEY (group_prototypeid)
97);
98CREATE INDEX group_prototype_1 ON group_prototype (hostid);
99CREATE TABLE group_discovery (
100	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
101	parent_group_prototypeid bigint                                    NOT NULL REFERENCES group_prototype (group_prototypeid),
102	name                     varchar(64)     DEFAULT ''                NOT NULL,
103	lastcheck                integer         DEFAULT '0'               NOT NULL,
104	ts_delete                integer         DEFAULT '0'               NOT NULL,
105	PRIMARY KEY (groupid)
106);
107CREATE TABLE screens (
108	screenid                 bigint                                    NOT NULL,
109	name                     varchar(255)                              NOT NULL,
110	hsize                    integer         DEFAULT '1'               NOT NULL,
111	vsize                    integer         DEFAULT '1'               NOT NULL,
112	templateid               bigint                                    NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
113	userid                   bigint                                    NULL REFERENCES users (userid),
114	private                  integer         DEFAULT '1'               NOT NULL,
115	PRIMARY KEY (screenid)
116);
117CREATE INDEX screens_1 ON screens (templateid);
118CREATE TABLE screens_items (
119	screenitemid             bigint                                    NOT NULL,
120	screenid                 bigint                                    NOT NULL REFERENCES screens (screenid) ON DELETE CASCADE,
121	resourcetype             integer         DEFAULT '0'               NOT NULL,
122	resourceid               bigint          DEFAULT '0'               NOT NULL,
123	width                    integer         DEFAULT '320'             NOT NULL,
124	height                   integer         DEFAULT '200'             NOT NULL,
125	x                        integer         DEFAULT '0'               NOT NULL,
126	y                        integer         DEFAULT '0'               NOT NULL,
127	colspan                  integer         DEFAULT '1'               NOT NULL,
128	rowspan                  integer         DEFAULT '1'               NOT NULL,
129	elements                 integer         DEFAULT '25'              NOT NULL,
130	valign                   integer         DEFAULT '0'               NOT NULL,
131	halign                   integer         DEFAULT '0'               NOT NULL,
132	style                    integer         DEFAULT '0'               NOT NULL,
133	url                      varchar(255)    DEFAULT ''                NOT NULL,
134	dynamic                  integer         DEFAULT '0'               NOT NULL,
135	sort_triggers            integer         DEFAULT '0'               NOT NULL,
136	application              varchar(255)    DEFAULT ''                NOT NULL,
137	max_columns              integer         DEFAULT '3'               NOT NULL,
138	PRIMARY KEY (screenitemid)
139);
140CREATE INDEX screens_items_1 ON screens_items (screenid);
141CREATE TABLE screen_user (
142	screenuserid             bigint                                    NOT NULL,
143	screenid                 bigint                                    NOT NULL REFERENCES screens (screenid) ON DELETE CASCADE,
144	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
145	permission               integer         DEFAULT '2'               NOT NULL,
146	PRIMARY KEY (screenuserid)
147);
148CREATE UNIQUE INDEX screen_user_1 ON screen_user (screenid,userid);
149CREATE TABLE screen_usrgrp (
150	screenusrgrpid           bigint                                    NOT NULL,
151	screenid                 bigint                                    NOT NULL REFERENCES screens (screenid) ON DELETE CASCADE,
152	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
153	permission               integer         DEFAULT '2'               NOT NULL,
154	PRIMARY KEY (screenusrgrpid)
155);
156CREATE UNIQUE INDEX screen_usrgrp_1 ON screen_usrgrp (screenid,usrgrpid);
157CREATE TABLE slideshows (
158	slideshowid              bigint                                    NOT NULL,
159	name                     varchar(255)    DEFAULT ''                NOT NULL,
160	delay                    varchar(32)     DEFAULT '30s'             NOT NULL,
161	userid                   bigint                                    NOT NULL REFERENCES users (userid),
162	private                  integer         DEFAULT '1'               NOT NULL,
163	PRIMARY KEY (slideshowid)
164);
165CREATE UNIQUE INDEX slideshows_1 ON slideshows (name);
166CREATE TABLE slideshow_user (
167	slideshowuserid          bigint                                    NOT NULL,
168	slideshowid              bigint                                    NOT NULL REFERENCES slideshows (slideshowid) ON DELETE CASCADE,
169	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
170	permission               integer         DEFAULT '2'               NOT NULL,
171	PRIMARY KEY (slideshowuserid)
172);
173CREATE UNIQUE INDEX slideshow_user_1 ON slideshow_user (slideshowid,userid);
174CREATE TABLE slideshow_usrgrp (
175	slideshowusrgrpid        bigint                                    NOT NULL,
176	slideshowid              bigint                                    NOT NULL REFERENCES slideshows (slideshowid) ON DELETE CASCADE,
177	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
178	permission               integer         DEFAULT '2'               NOT NULL,
179	PRIMARY KEY (slideshowusrgrpid)
180);
181CREATE UNIQUE INDEX slideshow_usrgrp_1 ON slideshow_usrgrp (slideshowid,usrgrpid);
182CREATE TABLE slides (
183	slideid                  bigint                                    NOT NULL,
184	slideshowid              bigint                                    NOT NULL REFERENCES slideshows (slideshowid) ON DELETE CASCADE,
185	screenid                 bigint                                    NOT NULL REFERENCES screens (screenid) ON DELETE CASCADE,
186	step                     integer         DEFAULT '0'               NOT NULL,
187	delay                    varchar(32)     DEFAULT '0'               NOT NULL,
188	PRIMARY KEY (slideid)
189);
190CREATE INDEX slides_1 ON slides (slideshowid);
191CREATE INDEX slides_2 ON slides (screenid);
192CREATE TABLE drules (
193	druleid                  bigint                                    NOT NULL,
194	proxy_hostid             bigint                                    NULL REFERENCES hosts (hostid),
195	name                     varchar(255)    DEFAULT ''                NOT NULL,
196	iprange                  varchar(2048)   DEFAULT ''                NOT NULL,
197	delay                    varchar(255)    DEFAULT '1h'              NOT NULL,
198	nextcheck                integer         DEFAULT '0'               NOT NULL,
199	status                   integer         DEFAULT '0'               NOT NULL,
200	PRIMARY KEY (druleid)
201);
202CREATE INDEX drules_1 ON drules (proxy_hostid);
203CREATE UNIQUE INDEX drules_2 ON drules (name);
204CREATE TABLE dchecks (
205	dcheckid                 bigint                                    NOT NULL,
206	druleid                  bigint                                    NOT NULL REFERENCES drules (druleid) ON DELETE CASCADE,
207	type                     integer         DEFAULT '0'               NOT NULL,
208	key_                     varchar(512)    DEFAULT ''                NOT NULL,
209	snmp_community           varchar(255)    DEFAULT ''                NOT NULL,
210	ports                    varchar(255)    DEFAULT '0'               NOT NULL,
211	snmpv3_securityname      varchar(64)     DEFAULT ''                NOT NULL,
212	snmpv3_securitylevel     integer         DEFAULT '0'               NOT NULL,
213	snmpv3_authpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
214	snmpv3_privpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
215	uniq                     integer         DEFAULT '0'               NOT NULL,
216	snmpv3_authprotocol      integer         DEFAULT '0'               NOT NULL,
217	snmpv3_privprotocol      integer         DEFAULT '0'               NOT NULL,
218	snmpv3_contextname       varchar(255)    DEFAULT ''                NOT NULL,
219	PRIMARY KEY (dcheckid)
220);
221CREATE INDEX dchecks_1 ON dchecks (druleid);
222CREATE TABLE applications (
223	applicationid            bigint                                    NOT NULL,
224	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
225	name                     varchar(255)    DEFAULT ''                NOT NULL,
226	flags                    integer         DEFAULT '0'               NOT NULL,
227	PRIMARY KEY (applicationid)
228);
229CREATE UNIQUE INDEX applications_2 ON applications (hostid,name);
230CREATE TABLE httptest (
231	httptestid               bigint                                    NOT NULL,
232	name                     varchar(64)     DEFAULT ''                NOT NULL,
233	applicationid            bigint                                    NULL REFERENCES applications (applicationid),
234	nextcheck                integer         DEFAULT '0'               NOT NULL,
235	delay                    varchar(255)    DEFAULT '1m'              NOT NULL,
236	status                   integer         DEFAULT '0'               NOT NULL,
237	agent                    varchar(255)    DEFAULT 'Zabbix'          NOT NULL,
238	authentication           integer         DEFAULT '0'               NOT NULL,
239	http_user                varchar(64)     DEFAULT ''                NOT NULL,
240	http_password            varchar(64)     DEFAULT ''                NOT NULL,
241	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
242	templateid               bigint                                    NULL REFERENCES httptest (httptestid) ON DELETE CASCADE,
243	http_proxy               varchar(255)    DEFAULT ''                NOT NULL,
244	retries                  integer         DEFAULT '1'               NOT NULL,
245	ssl_cert_file            varchar(255)    DEFAULT ''                NOT NULL,
246	ssl_key_file             varchar(255)    DEFAULT ''                NOT NULL,
247	ssl_key_password         varchar(64)     DEFAULT ''                NOT NULL,
248	verify_peer              integer         DEFAULT '0'               NOT NULL,
249	verify_host              integer         DEFAULT '0'               NOT NULL,
250	PRIMARY KEY (httptestid)
251);
252CREATE INDEX httptest_1 ON httptest (applicationid);
253CREATE UNIQUE INDEX httptest_2 ON httptest (hostid,name);
254CREATE INDEX httptest_3 ON httptest (status);
255CREATE INDEX httptest_4 ON httptest (templateid);
256CREATE TABLE httpstep (
257	httpstepid               bigint                                    NOT NULL,
258	httptestid               bigint                                    NOT NULL REFERENCES httptest (httptestid) ON DELETE CASCADE,
259	name                     varchar(64)     DEFAULT ''                NOT NULL,
260	no                       integer         DEFAULT '0'               NOT NULL,
261	url                      varchar(2048)   DEFAULT ''                NOT NULL,
262	timeout                  varchar(255)    DEFAULT '15s'             NOT NULL,
263	posts                    text            DEFAULT ''                NOT NULL,
264	required                 varchar(255)    DEFAULT ''                NOT NULL,
265	status_codes             varchar(255)    DEFAULT ''                NOT NULL,
266	follow_redirects         integer         DEFAULT '1'               NOT NULL,
267	retrieve_mode            integer         DEFAULT '0'               NOT NULL,
268	post_type                integer         DEFAULT '0'               NOT NULL,
269	PRIMARY KEY (httpstepid)
270);
271CREATE INDEX httpstep_1 ON httpstep (httptestid);
272CREATE TABLE interface (
273	interfaceid              bigint                                    NOT NULL,
274	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
275	main                     integer         DEFAULT '0'               NOT NULL,
276	type                     integer         DEFAULT '0'               NOT NULL,
277	useip                    integer         DEFAULT '1'               NOT NULL,
278	ip                       varchar(64)     DEFAULT '127.0.0.1'       NOT NULL,
279	dns                      varchar(255)    DEFAULT ''                NOT NULL,
280	port                     varchar(64)     DEFAULT '10050'           NOT NULL,
281	bulk                     integer         DEFAULT '1'               NOT NULL,
282	PRIMARY KEY (interfaceid)
283);
284CREATE INDEX interface_1 ON interface (hostid,type);
285CREATE INDEX interface_2 ON interface (ip,dns);
286CREATE TABLE valuemaps (
287	valuemapid               bigint                                    NOT NULL,
288	name                     varchar(64)     DEFAULT ''                NOT NULL,
289	PRIMARY KEY (valuemapid)
290);
291CREATE UNIQUE INDEX valuemaps_1 ON valuemaps (name);
292CREATE TABLE items (
293	itemid                   bigint                                    NOT NULL,
294	type                     integer         DEFAULT '0'               NOT NULL,
295	snmp_community           varchar(64)     DEFAULT ''                NOT NULL,
296	snmp_oid                 varchar(512)    DEFAULT ''                NOT NULL,
297	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
298	name                     varchar(255)    DEFAULT ''                NOT NULL,
299	key_                     varchar(255)    DEFAULT ''                NOT NULL,
300	delay                    varchar(1024)   DEFAULT '0'               NOT NULL,
301	history                  varchar(255)    DEFAULT '90d'             NOT NULL,
302	trends                   varchar(255)    DEFAULT '365d'            NOT NULL,
303	status                   integer         DEFAULT '0'               NOT NULL,
304	value_type               integer         DEFAULT '0'               NOT NULL,
305	trapper_hosts            varchar(255)    DEFAULT ''                NOT NULL,
306	units                    varchar(255)    DEFAULT ''                NOT NULL,
307	snmpv3_securityname      varchar(64)     DEFAULT ''                NOT NULL,
308	snmpv3_securitylevel     integer         DEFAULT '0'               NOT NULL,
309	snmpv3_authpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
310	snmpv3_privpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
311	formula                  varchar(255)    DEFAULT ''                NOT NULL,
312	error                    varchar(2048)   DEFAULT ''                NOT NULL,
313	lastlogsize              bigint          DEFAULT '0'               NOT NULL,
314	logtimefmt               varchar(64)     DEFAULT ''                NOT NULL,
315	templateid               bigint                                    NULL REFERENCES items (itemid) ON DELETE CASCADE,
316	valuemapid               bigint                                    NULL REFERENCES valuemaps (valuemapid),
317	params                   text            DEFAULT ''                NOT NULL,
318	ipmi_sensor              varchar(128)    DEFAULT ''                NOT NULL,
319	authtype                 integer         DEFAULT '0'               NOT NULL,
320	username                 varchar(64)     DEFAULT ''                NOT NULL,
321	password                 varchar(64)     DEFAULT ''                NOT NULL,
322	publickey                varchar(64)     DEFAULT ''                NOT NULL,
323	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
324	mtime                    integer         DEFAULT '0'               NOT NULL,
325	flags                    integer         DEFAULT '0'               NOT NULL,
326	interfaceid              bigint                                    NULL REFERENCES interface (interfaceid),
327	port                     varchar(64)     DEFAULT ''                NOT NULL,
328	description              text            DEFAULT ''                NOT NULL,
329	inventory_link           integer         DEFAULT '0'               NOT NULL,
330	lifetime                 varchar(255)    DEFAULT '30d'             NOT NULL,
331	snmpv3_authprotocol      integer         DEFAULT '0'               NOT NULL,
332	snmpv3_privprotocol      integer         DEFAULT '0'               NOT NULL,
333	state                    integer         DEFAULT '0'               NOT NULL,
334	snmpv3_contextname       varchar(255)    DEFAULT ''                NOT NULL,
335	evaltype                 integer         DEFAULT '0'               NOT NULL,
336	jmx_endpoint             varchar(255)    DEFAULT ''                NOT NULL,
337	master_itemid            bigint                                    NULL REFERENCES items (itemid) ON DELETE CASCADE,
338	timeout                  varchar(255)    DEFAULT '3s'              NOT NULL,
339	url                      varchar(2048)   DEFAULT ''                NOT NULL,
340	query_fields             varchar(2048)   DEFAULT ''                NOT NULL,
341	posts                    text            DEFAULT ''                NOT NULL,
342	status_codes             varchar(255)    DEFAULT '200'             NOT NULL,
343	follow_redirects         integer         DEFAULT '1'               NOT NULL,
344	post_type                integer         DEFAULT '0'               NOT NULL,
345	http_proxy               varchar(255)    DEFAULT ''                NOT NULL,
346	headers                  text            DEFAULT ''                NOT NULL,
347	retrieve_mode            integer         DEFAULT '0'               NOT NULL,
348	request_method           integer         DEFAULT '0'               NOT NULL,
349	output_format            integer         DEFAULT '0'               NOT NULL,
350	ssl_cert_file            varchar(255)    DEFAULT ''                NOT NULL,
351	ssl_key_file             varchar(255)    DEFAULT ''                NOT NULL,
352	ssl_key_password         varchar(64)     DEFAULT ''                NOT NULL,
353	verify_peer              integer         DEFAULT '0'               NOT NULL,
354	verify_host              integer         DEFAULT '0'               NOT NULL,
355	allow_traps              integer         DEFAULT '0'               NOT NULL,
356	PRIMARY KEY (itemid)
357);
358CREATE UNIQUE INDEX items_1 ON items (hostid,key_);
359CREATE INDEX items_3 ON items (status);
360CREATE INDEX items_4 ON items (templateid);
361CREATE INDEX items_5 ON items (valuemapid);
362CREATE INDEX items_6 ON items (interfaceid);
363CREATE INDEX items_7 ON items (master_itemid);
364CREATE TABLE httpstepitem (
365	httpstepitemid           bigint                                    NOT NULL,
366	httpstepid               bigint                                    NOT NULL REFERENCES httpstep (httpstepid) ON DELETE CASCADE,
367	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
368	type                     integer         DEFAULT '0'               NOT NULL,
369	PRIMARY KEY (httpstepitemid)
370);
371CREATE UNIQUE INDEX httpstepitem_1 ON httpstepitem (httpstepid,itemid);
372CREATE INDEX httpstepitem_2 ON httpstepitem (itemid);
373CREATE TABLE httptestitem (
374	httptestitemid           bigint                                    NOT NULL,
375	httptestid               bigint                                    NOT NULL REFERENCES httptest (httptestid) ON DELETE CASCADE,
376	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
377	type                     integer         DEFAULT '0'               NOT NULL,
378	PRIMARY KEY (httptestitemid)
379);
380CREATE UNIQUE INDEX httptestitem_1 ON httptestitem (httptestid,itemid);
381CREATE INDEX httptestitem_2 ON httptestitem (itemid);
382CREATE TABLE media_type (
383	mediatypeid              bigint                                    NOT NULL,
384	type                     integer         DEFAULT '0'               NOT NULL,
385	description              varchar(100)    DEFAULT ''                NOT NULL,
386	smtp_server              varchar(255)    DEFAULT ''                NOT NULL,
387	smtp_helo                varchar(255)    DEFAULT ''                NOT NULL,
388	smtp_email               varchar(255)    DEFAULT ''                NOT NULL,
389	exec_path                varchar(255)    DEFAULT ''                NOT NULL,
390	gsm_modem                varchar(255)    DEFAULT ''                NOT NULL,
391	username                 varchar(255)    DEFAULT ''                NOT NULL,
392	passwd                   varchar(255)    DEFAULT ''                NOT NULL,
393	status                   integer         DEFAULT '0'               NOT NULL,
394	smtp_port                integer         DEFAULT '25'              NOT NULL,
395	smtp_security            integer         DEFAULT '0'               NOT NULL,
396	smtp_verify_peer         integer         DEFAULT '0'               NOT NULL,
397	smtp_verify_host         integer         DEFAULT '0'               NOT NULL,
398	smtp_authentication      integer         DEFAULT '0'               NOT NULL,
399	exec_params              varchar(255)    DEFAULT ''                NOT NULL,
400	maxsessions              integer         DEFAULT '1'               NOT NULL,
401	maxattempts              integer         DEFAULT '3'               NOT NULL,
402	attempt_interval         varchar(32)     DEFAULT '10s'             NOT NULL,
403	PRIMARY KEY (mediatypeid)
404);
405CREATE UNIQUE INDEX media_type_1 ON media_type (description);
406CREATE TABLE usrgrp (
407	usrgrpid                 bigint                                    NOT NULL,
408	name                     varchar(64)     DEFAULT ''                NOT NULL,
409	gui_access               integer         DEFAULT '0'               NOT NULL,
410	users_status             integer         DEFAULT '0'               NOT NULL,
411	debug_mode               integer         DEFAULT '0'               NOT NULL,
412	PRIMARY KEY (usrgrpid)
413);
414CREATE UNIQUE INDEX usrgrp_1 ON usrgrp (name);
415CREATE TABLE users_groups (
416	id                       bigint                                    NOT NULL,
417	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
418	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
419	PRIMARY KEY (id)
420);
421CREATE UNIQUE INDEX users_groups_1 ON users_groups (usrgrpid,userid);
422CREATE INDEX users_groups_2 ON users_groups (userid);
423CREATE TABLE scripts (
424	scriptid                 bigint                                    NOT NULL,
425	name                     varchar(255)    DEFAULT ''                NOT NULL,
426	command                  varchar(255)    DEFAULT ''                NOT NULL,
427	host_access              integer         DEFAULT '2'               NOT NULL,
428	usrgrpid                 bigint                                    NULL REFERENCES usrgrp (usrgrpid),
429	groupid                  bigint                                    NULL REFERENCES hstgrp (groupid),
430	description              text            DEFAULT ''                NOT NULL,
431	confirmation             varchar(255)    DEFAULT ''                NOT NULL,
432	type                     integer         DEFAULT '0'               NOT NULL,
433	execute_on               integer         DEFAULT '2'               NOT NULL,
434	PRIMARY KEY (scriptid)
435);
436CREATE INDEX scripts_1 ON scripts (usrgrpid);
437CREATE INDEX scripts_2 ON scripts (groupid);
438CREATE UNIQUE INDEX scripts_3 ON scripts (name);
439CREATE TABLE actions (
440	actionid                 bigint                                    NOT NULL,
441	name                     varchar(255)    DEFAULT ''                NOT NULL,
442	eventsource              integer         DEFAULT '0'               NOT NULL,
443	evaltype                 integer         DEFAULT '0'               NOT NULL,
444	status                   integer         DEFAULT '0'               NOT NULL,
445	esc_period               varchar(255)    DEFAULT '1h'              NOT NULL,
446	def_shortdata            varchar(255)    DEFAULT ''                NOT NULL,
447	def_longdata             text            DEFAULT ''                NOT NULL,
448	r_shortdata              varchar(255)    DEFAULT ''                NOT NULL,
449	r_longdata               text            DEFAULT ''                NOT NULL,
450	formula                  varchar(255)    DEFAULT ''                NOT NULL,
451	pause_suppressed         integer         DEFAULT '1'               NOT NULL,
452	ack_shortdata            varchar(255)    DEFAULT ''                NOT NULL,
453	ack_longdata             text            DEFAULT ''                NOT NULL,
454	PRIMARY KEY (actionid)
455);
456CREATE INDEX actions_1 ON actions (eventsource,status);
457CREATE UNIQUE INDEX actions_2 ON actions (name);
458CREATE TABLE operations (
459	operationid              bigint                                    NOT NULL,
460	actionid                 bigint                                    NOT NULL REFERENCES actions (actionid) ON DELETE CASCADE,
461	operationtype            integer         DEFAULT '0'               NOT NULL,
462	esc_period               varchar(255)    DEFAULT '0'               NOT NULL,
463	esc_step_from            integer         DEFAULT '1'               NOT NULL,
464	esc_step_to              integer         DEFAULT '1'               NOT NULL,
465	evaltype                 integer         DEFAULT '0'               NOT NULL,
466	recovery                 integer         DEFAULT '0'               NOT NULL,
467	PRIMARY KEY (operationid)
468);
469CREATE INDEX operations_1 ON operations (actionid);
470CREATE TABLE opmessage (
471	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
472	default_msg              integer         DEFAULT '0'               NOT NULL,
473	subject                  varchar(255)    DEFAULT ''                NOT NULL,
474	message                  text            DEFAULT ''                NOT NULL,
475	mediatypeid              bigint                                    NULL REFERENCES media_type (mediatypeid),
476	PRIMARY KEY (operationid)
477);
478CREATE INDEX opmessage_1 ON opmessage (mediatypeid);
479CREATE TABLE opmessage_grp (
480	opmessage_grpid          bigint                                    NOT NULL,
481	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
482	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid),
483	PRIMARY KEY (opmessage_grpid)
484);
485CREATE UNIQUE INDEX opmessage_grp_1 ON opmessage_grp (operationid,usrgrpid);
486CREATE INDEX opmessage_grp_2 ON opmessage_grp (usrgrpid);
487CREATE TABLE opmessage_usr (
488	opmessage_usrid          bigint                                    NOT NULL,
489	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
490	userid                   bigint                                    NOT NULL REFERENCES users (userid),
491	PRIMARY KEY (opmessage_usrid)
492);
493CREATE UNIQUE INDEX opmessage_usr_1 ON opmessage_usr (operationid,userid);
494CREATE INDEX opmessage_usr_2 ON opmessage_usr (userid);
495CREATE TABLE opcommand (
496	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
497	type                     integer         DEFAULT '0'               NOT NULL,
498	scriptid                 bigint                                    NULL REFERENCES scripts (scriptid),
499	execute_on               integer         DEFAULT '0'               NOT NULL,
500	port                     varchar(64)     DEFAULT ''                NOT NULL,
501	authtype                 integer         DEFAULT '0'               NOT NULL,
502	username                 varchar(64)     DEFAULT ''                NOT NULL,
503	password                 varchar(64)     DEFAULT ''                NOT NULL,
504	publickey                varchar(64)     DEFAULT ''                NOT NULL,
505	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
506	command                  text            DEFAULT ''                NOT NULL,
507	PRIMARY KEY (operationid)
508);
509CREATE INDEX opcommand_1 ON opcommand (scriptid);
510CREATE TABLE opcommand_hst (
511	opcommand_hstid          bigint                                    NOT NULL,
512	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
513	hostid                   bigint                                    NULL REFERENCES hosts (hostid),
514	PRIMARY KEY (opcommand_hstid)
515);
516CREATE INDEX opcommand_hst_1 ON opcommand_hst (operationid);
517CREATE INDEX opcommand_hst_2 ON opcommand_hst (hostid);
518CREATE TABLE opcommand_grp (
519	opcommand_grpid          bigint                                    NOT NULL,
520	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
521	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid),
522	PRIMARY KEY (opcommand_grpid)
523);
524CREATE INDEX opcommand_grp_1 ON opcommand_grp (operationid);
525CREATE INDEX opcommand_grp_2 ON opcommand_grp (groupid);
526CREATE TABLE opgroup (
527	opgroupid                bigint                                    NOT NULL,
528	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
529	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid),
530	PRIMARY KEY (opgroupid)
531);
532CREATE UNIQUE INDEX opgroup_1 ON opgroup (operationid,groupid);
533CREATE INDEX opgroup_2 ON opgroup (groupid);
534CREATE TABLE optemplate (
535	optemplateid             bigint                                    NOT NULL,
536	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
537	templateid               bigint                                    NOT NULL REFERENCES hosts (hostid),
538	PRIMARY KEY (optemplateid)
539);
540CREATE UNIQUE INDEX optemplate_1 ON optemplate (operationid,templateid);
541CREATE INDEX optemplate_2 ON optemplate (templateid);
542CREATE TABLE opconditions (
543	opconditionid            bigint                                    NOT NULL,
544	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
545	conditiontype            integer         DEFAULT '0'               NOT NULL,
546	operator                 integer         DEFAULT '0'               NOT NULL,
547	value                    varchar(255)    DEFAULT ''                NOT NULL,
548	PRIMARY KEY (opconditionid)
549);
550CREATE INDEX opconditions_1 ON opconditions (operationid);
551CREATE TABLE conditions (
552	conditionid              bigint                                    NOT NULL,
553	actionid                 bigint                                    NOT NULL REFERENCES actions (actionid) ON DELETE CASCADE,
554	conditiontype            integer         DEFAULT '0'               NOT NULL,
555	operator                 integer         DEFAULT '0'               NOT NULL,
556	value                    varchar(255)    DEFAULT ''                NOT NULL,
557	value2                   varchar(255)    DEFAULT ''                NOT NULL,
558	PRIMARY KEY (conditionid)
559);
560CREATE INDEX conditions_1 ON conditions (actionid);
561CREATE TABLE config (
562	configid                 bigint                                    NOT NULL,
563	refresh_unsupported      varchar(32)     DEFAULT '10m'             NOT NULL,
564	work_period              varchar(255)    DEFAULT '1-5,09:00-18:00' NOT NULL,
565	alert_usrgrpid           bigint                                    NULL REFERENCES usrgrp (usrgrpid),
566	default_theme            varchar(128)    DEFAULT 'blue-theme'      NOT NULL,
567	authentication_type      integer         DEFAULT '0'               NOT NULL,
568	ldap_host                varchar(255)    DEFAULT ''                NOT NULL,
569	ldap_port                integer         DEFAULT 389               NOT NULL,
570	ldap_base_dn             varchar(255)    DEFAULT ''                NOT NULL,
571	ldap_bind_dn             varchar(255)    DEFAULT ''                NOT NULL,
572	ldap_bind_password       varchar(128)    DEFAULT ''                NOT NULL,
573	ldap_search_attribute    varchar(128)    DEFAULT ''                NOT NULL,
574	dropdown_first_entry     integer         DEFAULT '1'               NOT NULL,
575	dropdown_first_remember  integer         DEFAULT '1'               NOT NULL,
576	discovery_groupid        bigint                                    NOT NULL REFERENCES hstgrp (groupid),
577	max_in_table             integer         DEFAULT '50'              NOT NULL,
578	search_limit             integer         DEFAULT '1000'            NOT NULL,
579	severity_color_0         varchar(6)      DEFAULT '97AAB3'          NOT NULL,
580	severity_color_1         varchar(6)      DEFAULT '7499FF'          NOT NULL,
581	severity_color_2         varchar(6)      DEFAULT 'FFC859'          NOT NULL,
582	severity_color_3         varchar(6)      DEFAULT 'FFA059'          NOT NULL,
583	severity_color_4         varchar(6)      DEFAULT 'E97659'          NOT NULL,
584	severity_color_5         varchar(6)      DEFAULT 'E45959'          NOT NULL,
585	severity_name_0          varchar(32)     DEFAULT 'Not classified'  NOT NULL,
586	severity_name_1          varchar(32)     DEFAULT 'Information'     NOT NULL,
587	severity_name_2          varchar(32)     DEFAULT 'Warning'         NOT NULL,
588	severity_name_3          varchar(32)     DEFAULT 'Average'         NOT NULL,
589	severity_name_4          varchar(32)     DEFAULT 'High'            NOT NULL,
590	severity_name_5          varchar(32)     DEFAULT 'Disaster'        NOT NULL,
591	ok_period                varchar(32)     DEFAULT '5m'              NOT NULL,
592	blink_period             varchar(32)     DEFAULT '2m'              NOT NULL,
593	problem_unack_color      varchar(6)      DEFAULT 'CC0000'          NOT NULL,
594	problem_ack_color        varchar(6)      DEFAULT 'CC0000'          NOT NULL,
595	ok_unack_color           varchar(6)      DEFAULT '009900'          NOT NULL,
596	ok_ack_color             varchar(6)      DEFAULT '009900'          NOT NULL,
597	problem_unack_style      integer         DEFAULT '1'               NOT NULL,
598	problem_ack_style        integer         DEFAULT '1'               NOT NULL,
599	ok_unack_style           integer         DEFAULT '1'               NOT NULL,
600	ok_ack_style             integer         DEFAULT '1'               NOT NULL,
601	snmptrap_logging         integer         DEFAULT '1'               NOT NULL,
602	server_check_interval    integer         DEFAULT '10'              NOT NULL,
603	hk_events_mode           integer         DEFAULT '1'               NOT NULL,
604	hk_events_trigger        varchar(32)     DEFAULT '365d'            NOT NULL,
605	hk_events_internal       varchar(32)     DEFAULT '1d'              NOT NULL,
606	hk_events_discovery      varchar(32)     DEFAULT '1d'              NOT NULL,
607	hk_events_autoreg        varchar(32)     DEFAULT '1d'              NOT NULL,
608	hk_services_mode         integer         DEFAULT '1'               NOT NULL,
609	hk_services              varchar(32)     DEFAULT '365d'            NOT NULL,
610	hk_audit_mode            integer         DEFAULT '1'               NOT NULL,
611	hk_audit                 varchar(32)     DEFAULT '365d'            NOT NULL,
612	hk_sessions_mode         integer         DEFAULT '1'               NOT NULL,
613	hk_sessions              varchar(32)     DEFAULT '365d'            NOT NULL,
614	hk_history_mode          integer         DEFAULT '1'               NOT NULL,
615	hk_history_global        integer         DEFAULT '0'               NOT NULL,
616	hk_history               varchar(32)     DEFAULT '90d'             NOT NULL,
617	hk_trends_mode           integer         DEFAULT '1'               NOT NULL,
618	hk_trends_global         integer         DEFAULT '0'               NOT NULL,
619	hk_trends                varchar(32)     DEFAULT '365d'            NOT NULL,
620	default_inventory_mode   integer         DEFAULT '-1'              NOT NULL,
621	custom_color             integer         DEFAULT '0'               NOT NULL,
622	http_auth_enabled        integer         DEFAULT '0'               NOT NULL,
623	http_login_form          integer         DEFAULT '0'               NOT NULL,
624	http_strip_domains       varchar(2048)   DEFAULT ''                NOT NULL,
625	http_case_sensitive      integer         DEFAULT '1'               NOT NULL,
626	ldap_configured          integer         DEFAULT '0'               NOT NULL,
627	ldap_case_sensitive      integer         DEFAULT '1'               NOT NULL,
628	PRIMARY KEY (configid)
629);
630CREATE INDEX config_1 ON config (alert_usrgrpid);
631CREATE INDEX config_2 ON config (discovery_groupid);
632CREATE TABLE triggers (
633	triggerid                bigint                                    NOT NULL,
634	expression               varchar(2048)   DEFAULT ''                NOT NULL,
635	description              varchar(255)    DEFAULT ''                NOT NULL,
636	url                      varchar(255)    DEFAULT ''                NOT NULL,
637	status                   integer         DEFAULT '0'               NOT NULL,
638	value                    integer         DEFAULT '0'               NOT NULL,
639	priority                 integer         DEFAULT '0'               NOT NULL,
640	lastchange               integer         DEFAULT '0'               NOT NULL,
641	comments                 text            DEFAULT ''                NOT NULL,
642	error                    varchar(2048)   DEFAULT ''                NOT NULL,
643	templateid               bigint                                    NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
644	type                     integer         DEFAULT '0'               NOT NULL,
645	state                    integer         DEFAULT '0'               NOT NULL,
646	flags                    integer         DEFAULT '0'               NOT NULL,
647	recovery_mode            integer         DEFAULT '0'               NOT NULL,
648	recovery_expression      varchar(2048)   DEFAULT ''                NOT NULL,
649	correlation_mode         integer         DEFAULT '0'               NOT NULL,
650	correlation_tag          varchar(255)    DEFAULT ''                NOT NULL,
651	manual_close             integer         DEFAULT '0'               NOT NULL,
652	PRIMARY KEY (triggerid)
653);
654CREATE INDEX triggers_1 ON triggers (status);
655CREATE INDEX triggers_2 ON triggers (value,lastchange);
656CREATE INDEX triggers_3 ON triggers (templateid);
657CREATE TABLE trigger_depends (
658	triggerdepid             bigint                                    NOT NULL,
659	triggerid_down           bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
660	triggerid_up             bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
661	PRIMARY KEY (triggerdepid)
662);
663CREATE UNIQUE INDEX trigger_depends_1 ON trigger_depends (triggerid_down,triggerid_up);
664CREATE INDEX trigger_depends_2 ON trigger_depends (triggerid_up);
665CREATE TABLE functions (
666	functionid               bigint                                    NOT NULL,
667	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
668	triggerid                bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
669	name                     varchar(12)     DEFAULT ''                NOT NULL,
670	parameter                varchar(255)    DEFAULT '0'               NOT NULL,
671	PRIMARY KEY (functionid)
672);
673CREATE INDEX functions_1 ON functions (triggerid);
674CREATE INDEX functions_2 ON functions (itemid,name,parameter);
675CREATE TABLE graphs (
676	graphid                  bigint                                    NOT NULL,
677	name                     varchar(128)    DEFAULT ''                NOT NULL,
678	width                    integer         DEFAULT '900'             NOT NULL,
679	height                   integer         DEFAULT '200'             NOT NULL,
680	yaxismin                 double(16,4)    DEFAULT '0'               NOT NULL,
681	yaxismax                 double(16,4)    DEFAULT '100'             NOT NULL,
682	templateid               bigint                                    NULL REFERENCES graphs (graphid) ON DELETE CASCADE,
683	show_work_period         integer         DEFAULT '1'               NOT NULL,
684	show_triggers            integer         DEFAULT '1'               NOT NULL,
685	graphtype                integer         DEFAULT '0'               NOT NULL,
686	show_legend              integer         DEFAULT '1'               NOT NULL,
687	show_3d                  integer         DEFAULT '0'               NOT NULL,
688	percent_left             double(16,4)    DEFAULT '0'               NOT NULL,
689	percent_right            double(16,4)    DEFAULT '0'               NOT NULL,
690	ymin_type                integer         DEFAULT '0'               NOT NULL,
691	ymax_type                integer         DEFAULT '0'               NOT NULL,
692	ymin_itemid              bigint                                    NULL REFERENCES items (itemid),
693	ymax_itemid              bigint                                    NULL REFERENCES items (itemid),
694	flags                    integer         DEFAULT '0'               NOT NULL,
695	PRIMARY KEY (graphid)
696);
697CREATE INDEX graphs_1 ON graphs (name);
698CREATE INDEX graphs_2 ON graphs (templateid);
699CREATE INDEX graphs_3 ON graphs (ymin_itemid);
700CREATE INDEX graphs_4 ON graphs (ymax_itemid);
701CREATE TABLE graphs_items (
702	gitemid                  bigint                                    NOT NULL,
703	graphid                  bigint                                    NOT NULL REFERENCES graphs (graphid) ON DELETE CASCADE,
704	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
705	drawtype                 integer         DEFAULT '0'               NOT NULL,
706	sortorder                integer         DEFAULT '0'               NOT NULL,
707	color                    varchar(6)      DEFAULT '009600'          NOT NULL,
708	yaxisside                integer         DEFAULT '0'               NOT NULL,
709	calc_fnc                 integer         DEFAULT '2'               NOT NULL,
710	type                     integer         DEFAULT '0'               NOT NULL,
711	PRIMARY KEY (gitemid)
712);
713CREATE INDEX graphs_items_1 ON graphs_items (itemid);
714CREATE INDEX graphs_items_2 ON graphs_items (graphid);
715CREATE TABLE graph_theme (
716	graphthemeid             bigint                                    NOT NULL,
717	theme                    varchar(64)     DEFAULT ''                NOT NULL,
718	backgroundcolor          varchar(6)      DEFAULT ''                NOT NULL,
719	graphcolor               varchar(6)      DEFAULT ''                NOT NULL,
720	gridcolor                varchar(6)      DEFAULT ''                NOT NULL,
721	maingridcolor            varchar(6)      DEFAULT ''                NOT NULL,
722	gridbordercolor          varchar(6)      DEFAULT ''                NOT NULL,
723	textcolor                varchar(6)      DEFAULT ''                NOT NULL,
724	highlightcolor           varchar(6)      DEFAULT ''                NOT NULL,
725	leftpercentilecolor      varchar(6)      DEFAULT ''                NOT NULL,
726	rightpercentilecolor     varchar(6)      DEFAULT ''                NOT NULL,
727	nonworktimecolor         varchar(6)      DEFAULT ''                NOT NULL,
728	colorpalette             varchar(255)    DEFAULT ''                NOT NULL,
729	PRIMARY KEY (graphthemeid)
730);
731CREATE UNIQUE INDEX graph_theme_1 ON graph_theme (theme);
732CREATE TABLE globalmacro (
733	globalmacroid            bigint                                    NOT NULL,
734	macro                    varchar(255)    DEFAULT ''                NOT NULL,
735	value                    varchar(255)    DEFAULT ''                NOT NULL,
736	PRIMARY KEY (globalmacroid)
737);
738CREATE UNIQUE INDEX globalmacro_1 ON globalmacro (macro);
739CREATE TABLE hostmacro (
740	hostmacroid              bigint                                    NOT NULL,
741	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
742	macro                    varchar(255)    DEFAULT ''                NOT NULL,
743	value                    varchar(255)    DEFAULT ''                NOT NULL,
744	PRIMARY KEY (hostmacroid)
745);
746CREATE UNIQUE INDEX hostmacro_1 ON hostmacro (hostid,macro);
747CREATE TABLE hosts_groups (
748	hostgroupid              bigint                                    NOT NULL,
749	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
750	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
751	PRIMARY KEY (hostgroupid)
752);
753CREATE UNIQUE INDEX hosts_groups_1 ON hosts_groups (hostid,groupid);
754CREATE INDEX hosts_groups_2 ON hosts_groups (groupid);
755CREATE TABLE hosts_templates (
756	hosttemplateid           bigint                                    NOT NULL,
757	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
758	templateid               bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
759	PRIMARY KEY (hosttemplateid)
760);
761CREATE UNIQUE INDEX hosts_templates_1 ON hosts_templates (hostid,templateid);
762CREATE INDEX hosts_templates_2 ON hosts_templates (templateid);
763CREATE TABLE items_applications (
764	itemappid                bigint                                    NOT NULL,
765	applicationid            bigint                                    NOT NULL REFERENCES applications (applicationid) ON DELETE CASCADE,
766	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
767	PRIMARY KEY (itemappid)
768);
769CREATE UNIQUE INDEX items_applications_1 ON items_applications (applicationid,itemid);
770CREATE INDEX items_applications_2 ON items_applications (itemid);
771CREATE TABLE mappings (
772	mappingid                bigint                                    NOT NULL,
773	valuemapid               bigint                                    NOT NULL REFERENCES valuemaps (valuemapid) ON DELETE CASCADE,
774	value                    varchar(64)     DEFAULT ''                NOT NULL,
775	newvalue                 varchar(64)     DEFAULT ''                NOT NULL,
776	PRIMARY KEY (mappingid)
777);
778CREATE INDEX mappings_1 ON mappings (valuemapid);
779CREATE TABLE media (
780	mediaid                  bigint                                    NOT NULL,
781	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
782	mediatypeid              bigint                                    NOT NULL REFERENCES media_type (mediatypeid) ON DELETE CASCADE,
783	sendto                   varchar(1024)   DEFAULT ''                NOT NULL,
784	active                   integer         DEFAULT '0'               NOT NULL,
785	severity                 integer         DEFAULT '63'              NOT NULL,
786	period                   varchar(1024)   DEFAULT '1-7,00:00-24:00' NOT NULL,
787	PRIMARY KEY (mediaid)
788);
789CREATE INDEX media_1 ON media (userid);
790CREATE INDEX media_2 ON media (mediatypeid);
791CREATE TABLE rights (
792	rightid                  bigint                                    NOT NULL,
793	groupid                  bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
794	permission               integer         DEFAULT '0'               NOT NULL,
795	id                       bigint                                    NOT NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
796	PRIMARY KEY (rightid)
797);
798CREATE INDEX rights_1 ON rights (groupid);
799CREATE INDEX rights_2 ON rights (id);
800CREATE TABLE services (
801	serviceid                bigint                                    NOT NULL,
802	name                     varchar(128)    DEFAULT ''                NOT NULL,
803	status                   integer         DEFAULT '0'               NOT NULL,
804	algorithm                integer         DEFAULT '0'               NOT NULL,
805	triggerid                bigint                                    NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
806	showsla                  integer         DEFAULT '0'               NOT NULL,
807	goodsla                  double(16,4)    DEFAULT '99.9'            NOT NULL,
808	sortorder                integer         DEFAULT '0'               NOT NULL,
809	PRIMARY KEY (serviceid)
810);
811CREATE INDEX services_1 ON services (triggerid);
812CREATE TABLE services_links (
813	linkid                   bigint                                    NOT NULL,
814	serviceupid              bigint                                    NOT NULL REFERENCES services (serviceid) ON DELETE CASCADE,
815	servicedownid            bigint                                    NOT NULL REFERENCES services (serviceid) ON DELETE CASCADE,
816	soft                     integer         DEFAULT '0'               NOT NULL,
817	PRIMARY KEY (linkid)
818);
819CREATE INDEX services_links_1 ON services_links (servicedownid);
820CREATE UNIQUE INDEX services_links_2 ON services_links (serviceupid,servicedownid);
821CREATE TABLE services_times (
822	timeid                   bigint                                    NOT NULL,
823	serviceid                bigint                                    NOT NULL REFERENCES services (serviceid) ON DELETE CASCADE,
824	type                     integer         DEFAULT '0'               NOT NULL,
825	ts_from                  integer         DEFAULT '0'               NOT NULL,
826	ts_to                    integer         DEFAULT '0'               NOT NULL,
827	note                     varchar(255)    DEFAULT ''                NOT NULL,
828	PRIMARY KEY (timeid)
829);
830CREATE INDEX services_times_1 ON services_times (serviceid,type,ts_from,ts_to);
831CREATE TABLE icon_map (
832	iconmapid                bigint                                    NOT NULL,
833	name                     varchar(64)     DEFAULT ''                NOT NULL,
834	default_iconid           bigint                                    NOT NULL REFERENCES images (imageid),
835	PRIMARY KEY (iconmapid)
836);
837CREATE UNIQUE INDEX icon_map_1 ON icon_map (name);
838CREATE INDEX icon_map_2 ON icon_map (default_iconid);
839CREATE TABLE icon_mapping (
840	iconmappingid            bigint                                    NOT NULL,
841	iconmapid                bigint                                    NOT NULL REFERENCES icon_map (iconmapid) ON DELETE CASCADE,
842	iconid                   bigint                                    NOT NULL REFERENCES images (imageid),
843	inventory_link           integer         DEFAULT '0'               NOT NULL,
844	expression               varchar(64)     DEFAULT ''                NOT NULL,
845	sortorder                integer         DEFAULT '0'               NOT NULL,
846	PRIMARY KEY (iconmappingid)
847);
848CREATE INDEX icon_mapping_1 ON icon_mapping (iconmapid);
849CREATE INDEX icon_mapping_2 ON icon_mapping (iconid);
850CREATE TABLE sysmaps (
851	sysmapid                 bigint                                    NOT NULL,
852	name                     varchar(128)    DEFAULT ''                NOT NULL,
853	width                    integer         DEFAULT '600'             NOT NULL,
854	height                   integer         DEFAULT '400'             NOT NULL,
855	backgroundid             bigint                                    NULL REFERENCES images (imageid),
856	label_type               integer         DEFAULT '2'               NOT NULL,
857	label_location           integer         DEFAULT '0'               NOT NULL,
858	highlight                integer         DEFAULT '1'               NOT NULL,
859	expandproblem            integer         DEFAULT '1'               NOT NULL,
860	markelements             integer         DEFAULT '0'               NOT NULL,
861	show_unack               integer         DEFAULT '0'               NOT NULL,
862	grid_size                integer         DEFAULT '50'              NOT NULL,
863	grid_show                integer         DEFAULT '1'               NOT NULL,
864	grid_align               integer         DEFAULT '1'               NOT NULL,
865	label_format             integer         DEFAULT '0'               NOT NULL,
866	label_type_host          integer         DEFAULT '2'               NOT NULL,
867	label_type_hostgroup     integer         DEFAULT '2'               NOT NULL,
868	label_type_trigger       integer         DEFAULT '2'               NOT NULL,
869	label_type_map           integer         DEFAULT '2'               NOT NULL,
870	label_type_image         integer         DEFAULT '2'               NOT NULL,
871	label_string_host        varchar(255)    DEFAULT ''                NOT NULL,
872	label_string_hostgroup   varchar(255)    DEFAULT ''                NOT NULL,
873	label_string_trigger     varchar(255)    DEFAULT ''                NOT NULL,
874	label_string_map         varchar(255)    DEFAULT ''                NOT NULL,
875	label_string_image       varchar(255)    DEFAULT ''                NOT NULL,
876	iconmapid                bigint                                    NULL REFERENCES icon_map (iconmapid),
877	expand_macros            integer         DEFAULT '0'               NOT NULL,
878	severity_min             integer         DEFAULT '0'               NOT NULL,
879	userid                   bigint                                    NOT NULL REFERENCES users (userid),
880	private                  integer         DEFAULT '1'               NOT NULL,
881	show_suppressed          integer         DEFAULT '0'               NOT NULL,
882	PRIMARY KEY (sysmapid)
883);
884CREATE UNIQUE INDEX sysmaps_1 ON sysmaps (name);
885CREATE INDEX sysmaps_2 ON sysmaps (backgroundid);
886CREATE INDEX sysmaps_3 ON sysmaps (iconmapid);
887CREATE TABLE sysmaps_elements (
888	selementid               bigint                                    NOT NULL,
889	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
890	elementid                bigint          DEFAULT '0'               NOT NULL,
891	elementtype              integer         DEFAULT '0'               NOT NULL,
892	iconid_off               bigint                                    NULL REFERENCES images (imageid),
893	iconid_on                bigint                                    NULL REFERENCES images (imageid),
894	label                    varchar(2048)   DEFAULT ''                NOT NULL,
895	label_location           integer         DEFAULT '-1'              NOT NULL,
896	x                        integer         DEFAULT '0'               NOT NULL,
897	y                        integer         DEFAULT '0'               NOT NULL,
898	iconid_disabled          bigint                                    NULL REFERENCES images (imageid),
899	iconid_maintenance       bigint                                    NULL REFERENCES images (imageid),
900	elementsubtype           integer         DEFAULT '0'               NOT NULL,
901	areatype                 integer         DEFAULT '0'               NOT NULL,
902	width                    integer         DEFAULT '200'             NOT NULL,
903	height                   integer         DEFAULT '200'             NOT NULL,
904	viewtype                 integer         DEFAULT '0'               NOT NULL,
905	use_iconmap              integer         DEFAULT '1'               NOT NULL,
906	application              varchar(255)    DEFAULT ''                NOT NULL,
907	PRIMARY KEY (selementid)
908);
909CREATE INDEX sysmaps_elements_1 ON sysmaps_elements (sysmapid);
910CREATE INDEX sysmaps_elements_2 ON sysmaps_elements (iconid_off);
911CREATE INDEX sysmaps_elements_3 ON sysmaps_elements (iconid_on);
912CREATE INDEX sysmaps_elements_4 ON sysmaps_elements (iconid_disabled);
913CREATE INDEX sysmaps_elements_5 ON sysmaps_elements (iconid_maintenance);
914CREATE TABLE sysmaps_links (
915	linkid                   bigint                                    NOT NULL,
916	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
917	selementid1              bigint                                    NOT NULL REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE,
918	selementid2              bigint                                    NOT NULL REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE,
919	drawtype                 integer         DEFAULT '0'               NOT NULL,
920	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
921	label                    varchar(2048)   DEFAULT ''                NOT NULL,
922	PRIMARY KEY (linkid)
923);
924CREATE INDEX sysmaps_links_1 ON sysmaps_links (sysmapid);
925CREATE INDEX sysmaps_links_2 ON sysmaps_links (selementid1);
926CREATE INDEX sysmaps_links_3 ON sysmaps_links (selementid2);
927CREATE TABLE sysmaps_link_triggers (
928	linktriggerid            bigint                                    NOT NULL,
929	linkid                   bigint                                    NOT NULL REFERENCES sysmaps_links (linkid) ON DELETE CASCADE,
930	triggerid                bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
931	drawtype                 integer         DEFAULT '0'               NOT NULL,
932	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
933	PRIMARY KEY (linktriggerid)
934);
935CREATE UNIQUE INDEX sysmaps_link_triggers_1 ON sysmaps_link_triggers (linkid,triggerid);
936CREATE INDEX sysmaps_link_triggers_2 ON sysmaps_link_triggers (triggerid);
937CREATE TABLE sysmap_element_url (
938	sysmapelementurlid       bigint                                    NOT NULL,
939	selementid               bigint                                    NOT NULL REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE,
940	name                     varchar(255)                              NOT NULL,
941	url                      varchar(255)    DEFAULT ''                NOT NULL,
942	PRIMARY KEY (sysmapelementurlid)
943);
944CREATE UNIQUE INDEX sysmap_element_url_1 ON sysmap_element_url (selementid,name);
945CREATE TABLE sysmap_url (
946	sysmapurlid              bigint                                    NOT NULL,
947	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
948	name                     varchar(255)                              NOT NULL,
949	url                      varchar(255)    DEFAULT ''                NOT NULL,
950	elementtype              integer         DEFAULT '0'               NOT NULL,
951	PRIMARY KEY (sysmapurlid)
952);
953CREATE UNIQUE INDEX sysmap_url_1 ON sysmap_url (sysmapid,name);
954CREATE TABLE sysmap_user (
955	sysmapuserid             bigint                                    NOT NULL,
956	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
957	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
958	permission               integer         DEFAULT '2'               NOT NULL,
959	PRIMARY KEY (sysmapuserid)
960);
961CREATE UNIQUE INDEX sysmap_user_1 ON sysmap_user (sysmapid,userid);
962CREATE TABLE sysmap_usrgrp (
963	sysmapusrgrpid           bigint                                    NOT NULL,
964	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
965	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
966	permission               integer         DEFAULT '2'               NOT NULL,
967	PRIMARY KEY (sysmapusrgrpid)
968);
969CREATE UNIQUE INDEX sysmap_usrgrp_1 ON sysmap_usrgrp (sysmapid,usrgrpid);
970CREATE TABLE maintenances_hosts (
971	maintenance_hostid       bigint                                    NOT NULL,
972	maintenanceid            bigint                                    NOT NULL REFERENCES maintenances (maintenanceid) ON DELETE CASCADE,
973	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
974	PRIMARY KEY (maintenance_hostid)
975);
976CREATE UNIQUE INDEX maintenances_hosts_1 ON maintenances_hosts (maintenanceid,hostid);
977CREATE INDEX maintenances_hosts_2 ON maintenances_hosts (hostid);
978CREATE TABLE maintenances_groups (
979	maintenance_groupid      bigint                                    NOT NULL,
980	maintenanceid            bigint                                    NOT NULL REFERENCES maintenances (maintenanceid) ON DELETE CASCADE,
981	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
982	PRIMARY KEY (maintenance_groupid)
983);
984CREATE UNIQUE INDEX maintenances_groups_1 ON maintenances_groups (maintenanceid,groupid);
985CREATE INDEX maintenances_groups_2 ON maintenances_groups (groupid);
986CREATE TABLE timeperiods (
987	timeperiodid             bigint                                    NOT NULL,
988	timeperiod_type          integer         DEFAULT '0'               NOT NULL,
989	every                    integer         DEFAULT '1'               NOT NULL,
990	month                    integer         DEFAULT '0'               NOT NULL,
991	dayofweek                integer         DEFAULT '0'               NOT NULL,
992	day                      integer         DEFAULT '0'               NOT NULL,
993	start_time               integer         DEFAULT '0'               NOT NULL,
994	period                   integer         DEFAULT '0'               NOT NULL,
995	start_date               integer         DEFAULT '0'               NOT NULL,
996	PRIMARY KEY (timeperiodid)
997);
998CREATE TABLE maintenances_windows (
999	maintenance_timeperiodid bigint                                    NOT NULL,
1000	maintenanceid            bigint                                    NOT NULL REFERENCES maintenances (maintenanceid) ON DELETE CASCADE,
1001	timeperiodid             bigint                                    NOT NULL REFERENCES timeperiods (timeperiodid) ON DELETE CASCADE,
1002	PRIMARY KEY (maintenance_timeperiodid)
1003);
1004CREATE UNIQUE INDEX maintenances_windows_1 ON maintenances_windows (maintenanceid,timeperiodid);
1005CREATE INDEX maintenances_windows_2 ON maintenances_windows (timeperiodid);
1006CREATE TABLE regexps (
1007	regexpid                 bigint                                    NOT NULL,
1008	name                     varchar(128)    DEFAULT ''                NOT NULL,
1009	test_string              text            DEFAULT ''                NOT NULL,
1010	PRIMARY KEY (regexpid)
1011);
1012CREATE UNIQUE INDEX regexps_1 ON regexps (name);
1013CREATE TABLE expressions (
1014	expressionid             bigint                                    NOT NULL,
1015	regexpid                 bigint                                    NOT NULL REFERENCES regexps (regexpid) ON DELETE CASCADE,
1016	expression               varchar(255)    DEFAULT ''                NOT NULL,
1017	expression_type          integer         DEFAULT '0'               NOT NULL,
1018	exp_delimiter            varchar(1)      DEFAULT ''                NOT NULL,
1019	case_sensitive           integer         DEFAULT '0'               NOT NULL,
1020	PRIMARY KEY (expressionid)
1021);
1022CREATE INDEX expressions_1 ON expressions (regexpid);
1023CREATE TABLE ids (
1024	table_name               varchar(64)     DEFAULT ''                NOT NULL,
1025	field_name               varchar(64)     DEFAULT ''                NOT NULL,
1026	nextid                   bigint                                    NOT NULL,
1027	PRIMARY KEY (table_name,field_name)
1028);
1029CREATE TABLE alerts (
1030	alertid                  bigint                                    NOT NULL,
1031	actionid                 bigint                                    NOT NULL REFERENCES actions (actionid) ON DELETE CASCADE,
1032	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1033	userid                   bigint                                    NULL REFERENCES users (userid) ON DELETE CASCADE,
1034	clock                    integer         DEFAULT '0'               NOT NULL,
1035	mediatypeid              bigint                                    NULL REFERENCES media_type (mediatypeid) ON DELETE CASCADE,
1036	sendto                   varchar(1024)   DEFAULT ''                NOT NULL,
1037	subject                  varchar(255)    DEFAULT ''                NOT NULL,
1038	message                  text            DEFAULT ''                NOT NULL,
1039	status                   integer         DEFAULT '0'               NOT NULL,
1040	retries                  integer         DEFAULT '0'               NOT NULL,
1041	error                    varchar(2048)   DEFAULT ''                NOT NULL,
1042	esc_step                 integer         DEFAULT '0'               NOT NULL,
1043	alerttype                integer         DEFAULT '0'               NOT NULL,
1044	p_eventid                bigint                                    NULL REFERENCES events (eventid) ON DELETE CASCADE,
1045	acknowledgeid            bigint                                    NULL REFERENCES acknowledges (acknowledgeid) ON DELETE CASCADE,
1046	PRIMARY KEY (alertid)
1047);
1048CREATE INDEX alerts_1 ON alerts (actionid);
1049CREATE INDEX alerts_2 ON alerts (clock);
1050CREATE INDEX alerts_3 ON alerts (eventid);
1051CREATE INDEX alerts_4 ON alerts (status);
1052CREATE INDEX alerts_5 ON alerts (mediatypeid);
1053CREATE INDEX alerts_6 ON alerts (userid);
1054CREATE INDEX alerts_7 ON alerts (p_eventid);
1055CREATE TABLE history (
1056	itemid                   bigint                                    NOT NULL,
1057	clock                    integer         DEFAULT '0'               NOT NULL,
1058	value                    double(16,4)    DEFAULT '0.0000'          NOT NULL,
1059	ns                       integer         DEFAULT '0'               NOT NULL
1060);
1061CREATE INDEX history_1 ON history (itemid,clock);
1062CREATE TABLE history_uint (
1063	itemid                   bigint                                    NOT NULL,
1064	clock                    integer         DEFAULT '0'               NOT NULL,
1065	value                    bigint          DEFAULT '0'               NOT NULL,
1066	ns                       integer         DEFAULT '0'               NOT NULL
1067);
1068CREATE INDEX history_uint_1 ON history_uint (itemid,clock);
1069CREATE TABLE history_str (
1070	itemid                   bigint                                    NOT NULL,
1071	clock                    integer         DEFAULT '0'               NOT NULL,
1072	value                    varchar(255)    DEFAULT ''                NOT NULL,
1073	ns                       integer         DEFAULT '0'               NOT NULL
1074);
1075CREATE INDEX history_str_1 ON history_str (itemid,clock);
1076CREATE TABLE history_log (
1077	itemid                   bigint                                    NOT NULL,
1078	clock                    integer         DEFAULT '0'               NOT NULL,
1079	timestamp                integer         DEFAULT '0'               NOT NULL,
1080	source                   varchar(64)     DEFAULT ''                NOT NULL,
1081	severity                 integer         DEFAULT '0'               NOT NULL,
1082	value                    text            DEFAULT ''                NOT NULL,
1083	logeventid               integer         DEFAULT '0'               NOT NULL,
1084	ns                       integer         DEFAULT '0'               NOT NULL
1085);
1086CREATE INDEX history_log_1 ON history_log (itemid,clock);
1087CREATE TABLE history_text (
1088	itemid                   bigint                                    NOT NULL,
1089	clock                    integer         DEFAULT '0'               NOT NULL,
1090	value                    text            DEFAULT ''                NOT NULL,
1091	ns                       integer         DEFAULT '0'               NOT NULL
1092);
1093CREATE INDEX history_text_1 ON history_text (itemid,clock);
1094CREATE TABLE proxy_history (
1095	id                       integer                                   NOT NULL PRIMARY KEY AUTOINCREMENT,
1096	itemid                   bigint                                    NOT NULL,
1097	clock                    integer         DEFAULT '0'               NOT NULL,
1098	timestamp                integer         DEFAULT '0'               NOT NULL,
1099	source                   varchar(64)     DEFAULT ''                NOT NULL,
1100	severity                 integer         DEFAULT '0'               NOT NULL,
1101	value                    text            DEFAULT ''                NOT NULL,
1102	logeventid               integer         DEFAULT '0'               NOT NULL,
1103	ns                       integer         DEFAULT '0'               NOT NULL,
1104	state                    integer         DEFAULT '0'               NOT NULL,
1105	lastlogsize              bigint          DEFAULT '0'               NOT NULL,
1106	mtime                    integer         DEFAULT '0'               NOT NULL,
1107	flags                    integer         DEFAULT '0'               NOT NULL
1108);
1109CREATE INDEX proxy_history_1 ON proxy_history (clock);
1110CREATE TABLE proxy_dhistory (
1111	id                       integer                                   NOT NULL PRIMARY KEY AUTOINCREMENT,
1112	clock                    integer         DEFAULT '0'               NOT NULL,
1113	druleid                  bigint                                    NOT NULL,
1114	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1115	port                     integer         DEFAULT '0'               NOT NULL,
1116	value                    varchar(255)    DEFAULT ''                NOT NULL,
1117	status                   integer         DEFAULT '0'               NOT NULL,
1118	dcheckid                 bigint                                    NULL,
1119	dns                      varchar(255)    DEFAULT ''                NOT NULL
1120);
1121CREATE INDEX proxy_dhistory_1 ON proxy_dhistory (clock);
1122CREATE TABLE events (
1123	eventid                  bigint                                    NOT NULL,
1124	source                   integer         DEFAULT '0'               NOT NULL,
1125	object                   integer         DEFAULT '0'               NOT NULL,
1126	objectid                 bigint          DEFAULT '0'               NOT NULL,
1127	clock                    integer         DEFAULT '0'               NOT NULL,
1128	value                    integer         DEFAULT '0'               NOT NULL,
1129	acknowledged             integer         DEFAULT '0'               NOT NULL,
1130	ns                       integer         DEFAULT '0'               NOT NULL,
1131	name                     varchar(2048)   DEFAULT ''                NOT NULL,
1132	severity                 integer         DEFAULT '0'               NOT NULL,
1133	PRIMARY KEY (eventid)
1134);
1135CREATE INDEX events_1 ON events (source,object,objectid,clock);
1136CREATE INDEX events_2 ON events (source,object,clock);
1137CREATE TABLE trends (
1138	itemid                   bigint                                    NOT NULL,
1139	clock                    integer         DEFAULT '0'               NOT NULL,
1140	num                      integer         DEFAULT '0'               NOT NULL,
1141	value_min                double(16,4)    DEFAULT '0.0000'          NOT NULL,
1142	value_avg                double(16,4)    DEFAULT '0.0000'          NOT NULL,
1143	value_max                double(16,4)    DEFAULT '0.0000'          NOT NULL,
1144	PRIMARY KEY (itemid,clock)
1145);
1146CREATE TABLE trends_uint (
1147	itemid                   bigint                                    NOT NULL,
1148	clock                    integer         DEFAULT '0'               NOT NULL,
1149	num                      integer         DEFAULT '0'               NOT NULL,
1150	value_min                bigint          DEFAULT '0'               NOT NULL,
1151	value_avg                bigint          DEFAULT '0'               NOT NULL,
1152	value_max                bigint          DEFAULT '0'               NOT NULL,
1153	PRIMARY KEY (itemid,clock)
1154);
1155CREATE TABLE acknowledges (
1156	acknowledgeid            bigint                                    NOT NULL,
1157	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
1158	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1159	clock                    integer         DEFAULT '0'               NOT NULL,
1160	message                  varchar(255)    DEFAULT ''                NOT NULL,
1161	action                   integer         DEFAULT '0'               NOT NULL,
1162	old_severity             integer         DEFAULT '0'               NOT NULL,
1163	new_severity             integer         DEFAULT '0'               NOT NULL,
1164	PRIMARY KEY (acknowledgeid)
1165);
1166CREATE INDEX acknowledges_1 ON acknowledges (userid);
1167CREATE INDEX acknowledges_2 ON acknowledges (eventid);
1168CREATE INDEX acknowledges_3 ON acknowledges (clock);
1169CREATE TABLE auditlog (
1170	auditid                  bigint                                    NOT NULL,
1171	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
1172	clock                    integer         DEFAULT '0'               NOT NULL,
1173	action                   integer         DEFAULT '0'               NOT NULL,
1174	resourcetype             integer         DEFAULT '0'               NOT NULL,
1175	details                  varchar(128)    DEFAULT '0'               NOT NULL,
1176	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1177	resourceid               bigint          DEFAULT '0'               NOT NULL,
1178	resourcename             varchar(255)    DEFAULT ''                NOT NULL,
1179	PRIMARY KEY (auditid)
1180);
1181CREATE INDEX auditlog_1 ON auditlog (userid,clock);
1182CREATE INDEX auditlog_2 ON auditlog (clock);
1183CREATE TABLE auditlog_details (
1184	auditdetailid            bigint                                    NOT NULL,
1185	auditid                  bigint                                    NOT NULL REFERENCES auditlog (auditid) ON DELETE CASCADE,
1186	table_name               varchar(64)     DEFAULT ''                NOT NULL,
1187	field_name               varchar(64)     DEFAULT ''                NOT NULL,
1188	oldvalue                 text            DEFAULT ''                NOT NULL,
1189	newvalue                 text            DEFAULT ''                NOT NULL,
1190	PRIMARY KEY (auditdetailid)
1191);
1192CREATE INDEX auditlog_details_1 ON auditlog_details (auditid);
1193CREATE TABLE service_alarms (
1194	servicealarmid           bigint                                    NOT NULL,
1195	serviceid                bigint                                    NOT NULL REFERENCES services (serviceid) ON DELETE CASCADE,
1196	clock                    integer         DEFAULT '0'               NOT NULL,
1197	value                    integer         DEFAULT '0'               NOT NULL,
1198	PRIMARY KEY (servicealarmid)
1199);
1200CREATE INDEX service_alarms_1 ON service_alarms (serviceid,clock);
1201CREATE INDEX service_alarms_2 ON service_alarms (clock);
1202CREATE TABLE autoreg_host (
1203	autoreg_hostid           bigint                                    NOT NULL,
1204	proxy_hostid             bigint                                    NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
1205	host                     varchar(64)     DEFAULT ''                NOT NULL,
1206	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1207	listen_port              integer         DEFAULT '0'               NOT NULL,
1208	listen_dns               varchar(255)    DEFAULT ''                NOT NULL,
1209	host_metadata            varchar(255)    DEFAULT ''                NOT NULL,
1210	PRIMARY KEY (autoreg_hostid)
1211);
1212CREATE INDEX autoreg_host_1 ON autoreg_host (host);
1213CREATE INDEX autoreg_host_2 ON autoreg_host (proxy_hostid);
1214CREATE TABLE proxy_autoreg_host (
1215	id                       integer                                   NOT NULL PRIMARY KEY AUTOINCREMENT,
1216	clock                    integer         DEFAULT '0'               NOT NULL,
1217	host                     varchar(64)     DEFAULT ''                NOT NULL,
1218	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1219	listen_port              integer         DEFAULT '0'               NOT NULL,
1220	listen_dns               varchar(255)    DEFAULT ''                NOT NULL,
1221	host_metadata            varchar(255)    DEFAULT ''                NOT NULL
1222);
1223CREATE INDEX proxy_autoreg_host_1 ON proxy_autoreg_host (clock);
1224CREATE TABLE dhosts (
1225	dhostid                  bigint                                    NOT NULL,
1226	druleid                  bigint                                    NOT NULL REFERENCES drules (druleid) ON DELETE CASCADE,
1227	status                   integer         DEFAULT '0'               NOT NULL,
1228	lastup                   integer         DEFAULT '0'               NOT NULL,
1229	lastdown                 integer         DEFAULT '0'               NOT NULL,
1230	PRIMARY KEY (dhostid)
1231);
1232CREATE INDEX dhosts_1 ON dhosts (druleid);
1233CREATE TABLE dservices (
1234	dserviceid               bigint                                    NOT NULL,
1235	dhostid                  bigint                                    NOT NULL REFERENCES dhosts (dhostid) ON DELETE CASCADE,
1236	value                    varchar(255)    DEFAULT ''                NOT NULL,
1237	port                     integer         DEFAULT '0'               NOT NULL,
1238	status                   integer         DEFAULT '0'               NOT NULL,
1239	lastup                   integer         DEFAULT '0'               NOT NULL,
1240	lastdown                 integer         DEFAULT '0'               NOT NULL,
1241	dcheckid                 bigint                                    NOT NULL REFERENCES dchecks (dcheckid) ON DELETE CASCADE,
1242	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1243	dns                      varchar(255)    DEFAULT ''                NOT NULL,
1244	PRIMARY KEY (dserviceid)
1245);
1246CREATE UNIQUE INDEX dservices_1 ON dservices (dcheckid,ip,port);
1247CREATE INDEX dservices_2 ON dservices (dhostid);
1248CREATE TABLE escalations (
1249	escalationid             bigint                                    NOT NULL,
1250	actionid                 bigint                                    NOT NULL,
1251	triggerid                bigint                                    NULL,
1252	eventid                  bigint                                    NULL,
1253	r_eventid                bigint                                    NULL,
1254	nextcheck                integer         DEFAULT '0'               NOT NULL,
1255	esc_step                 integer         DEFAULT '0'               NOT NULL,
1256	status                   integer         DEFAULT '0'               NOT NULL,
1257	itemid                   bigint                                    NULL,
1258	acknowledgeid            bigint                                    NULL,
1259	PRIMARY KEY (escalationid)
1260);
1261CREATE UNIQUE INDEX escalations_1 ON escalations (triggerid,itemid,escalationid);
1262CREATE INDEX escalations_2 ON escalations (eventid);
1263CREATE INDEX escalations_3 ON escalations (nextcheck);
1264CREATE TABLE globalvars (
1265	globalvarid              bigint                                    NOT NULL,
1266	snmp_lastsize            bigint          DEFAULT '0'               NOT NULL,
1267	PRIMARY KEY (globalvarid)
1268);
1269CREATE TABLE graph_discovery (
1270	graphid                  bigint                                    NOT NULL REFERENCES graphs (graphid) ON DELETE CASCADE,
1271	parent_graphid           bigint                                    NOT NULL REFERENCES graphs (graphid),
1272	PRIMARY KEY (graphid)
1273);
1274CREATE INDEX graph_discovery_1 ON graph_discovery (parent_graphid);
1275CREATE TABLE host_inventory (
1276	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
1277	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1278	type                     varchar(64)     DEFAULT ''                NOT NULL,
1279	type_full                varchar(64)     DEFAULT ''                NOT NULL,
1280	name                     varchar(64)     DEFAULT ''                NOT NULL,
1281	alias                    varchar(64)     DEFAULT ''                NOT NULL,
1282	os                       varchar(64)     DEFAULT ''                NOT NULL,
1283	os_full                  varchar(255)    DEFAULT ''                NOT NULL,
1284	os_short                 varchar(64)     DEFAULT ''                NOT NULL,
1285	serialno_a               varchar(64)     DEFAULT ''                NOT NULL,
1286	serialno_b               varchar(64)     DEFAULT ''                NOT NULL,
1287	tag                      varchar(64)     DEFAULT ''                NOT NULL,
1288	asset_tag                varchar(64)     DEFAULT ''                NOT NULL,
1289	macaddress_a             varchar(64)     DEFAULT ''                NOT NULL,
1290	macaddress_b             varchar(64)     DEFAULT ''                NOT NULL,
1291	hardware                 varchar(255)    DEFAULT ''                NOT NULL,
1292	hardware_full            text            DEFAULT ''                NOT NULL,
1293	software                 varchar(255)    DEFAULT ''                NOT NULL,
1294	software_full            text            DEFAULT ''                NOT NULL,
1295	software_app_a           varchar(64)     DEFAULT ''                NOT NULL,
1296	software_app_b           varchar(64)     DEFAULT ''                NOT NULL,
1297	software_app_c           varchar(64)     DEFAULT ''                NOT NULL,
1298	software_app_d           varchar(64)     DEFAULT ''                NOT NULL,
1299	software_app_e           varchar(64)     DEFAULT ''                NOT NULL,
1300	contact                  text            DEFAULT ''                NOT NULL,
1301	location                 text            DEFAULT ''                NOT NULL,
1302	location_lat             varchar(16)     DEFAULT ''                NOT NULL,
1303	location_lon             varchar(16)     DEFAULT ''                NOT NULL,
1304	notes                    text            DEFAULT ''                NOT NULL,
1305	chassis                  varchar(64)     DEFAULT ''                NOT NULL,
1306	model                    varchar(64)     DEFAULT ''                NOT NULL,
1307	hw_arch                  varchar(32)     DEFAULT ''                NOT NULL,
1308	vendor                   varchar(64)     DEFAULT ''                NOT NULL,
1309	contract_number          varchar(64)     DEFAULT ''                NOT NULL,
1310	installer_name           varchar(64)     DEFAULT ''                NOT NULL,
1311	deployment_status        varchar(64)     DEFAULT ''                NOT NULL,
1312	url_a                    varchar(255)    DEFAULT ''                NOT NULL,
1313	url_b                    varchar(255)    DEFAULT ''                NOT NULL,
1314	url_c                    varchar(255)    DEFAULT ''                NOT NULL,
1315	host_networks            text            DEFAULT ''                NOT NULL,
1316	host_netmask             varchar(39)     DEFAULT ''                NOT NULL,
1317	host_router              varchar(39)     DEFAULT ''                NOT NULL,
1318	oob_ip                   varchar(39)     DEFAULT ''                NOT NULL,
1319	oob_netmask              varchar(39)     DEFAULT ''                NOT NULL,
1320	oob_router               varchar(39)     DEFAULT ''                NOT NULL,
1321	date_hw_purchase         varchar(64)     DEFAULT ''                NOT NULL,
1322	date_hw_install          varchar(64)     DEFAULT ''                NOT NULL,
1323	date_hw_expiry           varchar(64)     DEFAULT ''                NOT NULL,
1324	date_hw_decomm           varchar(64)     DEFAULT ''                NOT NULL,
1325	site_address_a           varchar(128)    DEFAULT ''                NOT NULL,
1326	site_address_b           varchar(128)    DEFAULT ''                NOT NULL,
1327	site_address_c           varchar(128)    DEFAULT ''                NOT NULL,
1328	site_city                varchar(128)    DEFAULT ''                NOT NULL,
1329	site_state               varchar(64)     DEFAULT ''                NOT NULL,
1330	site_country             varchar(64)     DEFAULT ''                NOT NULL,
1331	site_zip                 varchar(64)     DEFAULT ''                NOT NULL,
1332	site_rack                varchar(128)    DEFAULT ''                NOT NULL,
1333	site_notes               text            DEFAULT ''                NOT NULL,
1334	poc_1_name               varchar(128)    DEFAULT ''                NOT NULL,
1335	poc_1_email              varchar(128)    DEFAULT ''                NOT NULL,
1336	poc_1_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1337	poc_1_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1338	poc_1_cell               varchar(64)     DEFAULT ''                NOT NULL,
1339	poc_1_screen             varchar(64)     DEFAULT ''                NOT NULL,
1340	poc_1_notes              text            DEFAULT ''                NOT NULL,
1341	poc_2_name               varchar(128)    DEFAULT ''                NOT NULL,
1342	poc_2_email              varchar(128)    DEFAULT ''                NOT NULL,
1343	poc_2_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1344	poc_2_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1345	poc_2_cell               varchar(64)     DEFAULT ''                NOT NULL,
1346	poc_2_screen             varchar(64)     DEFAULT ''                NOT NULL,
1347	poc_2_notes              text            DEFAULT ''                NOT NULL,
1348	PRIMARY KEY (hostid)
1349);
1350CREATE TABLE housekeeper (
1351	housekeeperid            bigint                                    NOT NULL,
1352	tablename                varchar(64)     DEFAULT ''                NOT NULL,
1353	field                    varchar(64)     DEFAULT ''                NOT NULL,
1354	value                    bigint                                    NOT NULL,
1355	PRIMARY KEY (housekeeperid)
1356);
1357CREATE TABLE images (
1358	imageid                  bigint                                    NOT NULL,
1359	imagetype                integer         DEFAULT '0'               NOT NULL,
1360	name                     varchar(64)     DEFAULT '0'               NOT NULL,
1361	image                    longblob        DEFAULT ''                NOT NULL,
1362	PRIMARY KEY (imageid)
1363);
1364CREATE UNIQUE INDEX images_1 ON images (name);
1365CREATE TABLE item_discovery (
1366	itemdiscoveryid          bigint                                    NOT NULL,
1367	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1368	parent_itemid            bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1369	key_                     varchar(255)    DEFAULT ''                NOT NULL,
1370	lastcheck                integer         DEFAULT '0'               NOT NULL,
1371	ts_delete                integer         DEFAULT '0'               NOT NULL,
1372	PRIMARY KEY (itemdiscoveryid)
1373);
1374CREATE UNIQUE INDEX item_discovery_1 ON item_discovery (itemid,parent_itemid);
1375CREATE INDEX item_discovery_2 ON item_discovery (parent_itemid);
1376CREATE TABLE host_discovery (
1377	hostid                   bigint                                    NOT NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
1378	parent_hostid            bigint                                    NULL REFERENCES hosts (hostid),
1379	parent_itemid            bigint                                    NULL REFERENCES items (itemid),
1380	host                     varchar(64)     DEFAULT ''                NOT NULL,
1381	lastcheck                integer         DEFAULT '0'               NOT NULL,
1382	ts_delete                integer         DEFAULT '0'               NOT NULL,
1383	PRIMARY KEY (hostid)
1384);
1385CREATE TABLE interface_discovery (
1386	interfaceid              bigint                                    NOT NULL REFERENCES interface (interfaceid) ON DELETE CASCADE,
1387	parent_interfaceid       bigint                                    NOT NULL REFERENCES interface (interfaceid) ON DELETE CASCADE,
1388	PRIMARY KEY (interfaceid)
1389);
1390CREATE TABLE profiles (
1391	profileid                bigint                                    NOT NULL,
1392	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
1393	idx                      varchar(96)     DEFAULT ''                NOT NULL,
1394	idx2                     bigint          DEFAULT '0'               NOT NULL,
1395	value_id                 bigint          DEFAULT '0'               NOT NULL,
1396	value_int                integer         DEFAULT '0'               NOT NULL,
1397	value_str                varchar(255)    DEFAULT ''                NOT NULL,
1398	source                   varchar(96)     DEFAULT ''                NOT NULL,
1399	type                     integer         DEFAULT '0'               NOT NULL,
1400	PRIMARY KEY (profileid)
1401);
1402CREATE INDEX profiles_1 ON profiles (userid,idx,idx2);
1403CREATE INDEX profiles_2 ON profiles (userid,profileid);
1404CREATE TABLE sessions (
1405	sessionid                varchar(32)     DEFAULT ''                NOT NULL,
1406	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
1407	lastaccess               integer         DEFAULT '0'               NOT NULL,
1408	status                   integer         DEFAULT '0'               NOT NULL,
1409	PRIMARY KEY (sessionid)
1410);
1411CREATE INDEX sessions_1 ON sessions (userid,status,lastaccess);
1412CREATE TABLE trigger_discovery (
1413	triggerid                bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
1414	parent_triggerid         bigint                                    NOT NULL REFERENCES triggers (triggerid),
1415	PRIMARY KEY (triggerid)
1416);
1417CREATE INDEX trigger_discovery_1 ON trigger_discovery (parent_triggerid);
1418CREATE TABLE application_template (
1419	application_templateid   bigint                                    NOT NULL,
1420	applicationid            bigint                                    NOT NULL REFERENCES applications (applicationid) ON DELETE CASCADE,
1421	templateid               bigint                                    NOT NULL REFERENCES applications (applicationid) ON DELETE CASCADE,
1422	PRIMARY KEY (application_templateid)
1423);
1424CREATE UNIQUE INDEX application_template_1 ON application_template (applicationid,templateid);
1425CREATE INDEX application_template_2 ON application_template (templateid);
1426CREATE TABLE item_condition (
1427	item_conditionid         bigint                                    NOT NULL,
1428	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1429	operator                 integer         DEFAULT '8'               NOT NULL,
1430	macro                    varchar(64)     DEFAULT ''                NOT NULL,
1431	value                    varchar(255)    DEFAULT ''                NOT NULL,
1432	PRIMARY KEY (item_conditionid)
1433);
1434CREATE INDEX item_condition_1 ON item_condition (itemid);
1435CREATE TABLE application_prototype (
1436	application_prototypeid  bigint                                    NOT NULL,
1437	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1438	templateid               bigint                                    NULL REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE,
1439	name                     varchar(255)    DEFAULT ''                NOT NULL,
1440	PRIMARY KEY (application_prototypeid)
1441);
1442CREATE INDEX application_prototype_1 ON application_prototype (itemid);
1443CREATE INDEX application_prototype_2 ON application_prototype (templateid);
1444CREATE TABLE item_application_prototype (
1445	item_application_prototypeid bigint                                    NOT NULL,
1446	application_prototypeid  bigint                                    NOT NULL REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE,
1447	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1448	PRIMARY KEY (item_application_prototypeid)
1449);
1450CREATE UNIQUE INDEX item_application_prototype_1 ON item_application_prototype (application_prototypeid,itemid);
1451CREATE INDEX item_application_prototype_2 ON item_application_prototype (itemid);
1452CREATE TABLE application_discovery (
1453	application_discoveryid  bigint                                    NOT NULL,
1454	applicationid            bigint                                    NOT NULL REFERENCES applications (applicationid) ON DELETE CASCADE,
1455	application_prototypeid  bigint                                    NOT NULL REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE,
1456	name                     varchar(255)    DEFAULT ''                NOT NULL,
1457	lastcheck                integer         DEFAULT '0'               NOT NULL,
1458	ts_delete                integer         DEFAULT '0'               NOT NULL,
1459	PRIMARY KEY (application_discoveryid)
1460);
1461CREATE INDEX application_discovery_1 ON application_discovery (applicationid);
1462CREATE INDEX application_discovery_2 ON application_discovery (application_prototypeid);
1463CREATE TABLE opinventory (
1464	operationid              bigint                                    NOT NULL REFERENCES operations (operationid) ON DELETE CASCADE,
1465	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1466	PRIMARY KEY (operationid)
1467);
1468CREATE TABLE trigger_tag (
1469	triggertagid             bigint                                    NOT NULL,
1470	triggerid                bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
1471	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1472	value                    varchar(255)    DEFAULT ''                NOT NULL,
1473	PRIMARY KEY (triggertagid)
1474);
1475CREATE INDEX trigger_tag_1 ON trigger_tag (triggerid);
1476CREATE TABLE event_tag (
1477	eventtagid               bigint                                    NOT NULL,
1478	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1479	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1480	value                    varchar(255)    DEFAULT ''                NOT NULL,
1481	PRIMARY KEY (eventtagid)
1482);
1483CREATE INDEX event_tag_1 ON event_tag (eventid);
1484CREATE TABLE problem (
1485	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1486	source                   integer         DEFAULT '0'               NOT NULL,
1487	object                   integer         DEFAULT '0'               NOT NULL,
1488	objectid                 bigint          DEFAULT '0'               NOT NULL,
1489	clock                    integer         DEFAULT '0'               NOT NULL,
1490	ns                       integer         DEFAULT '0'               NOT NULL,
1491	r_eventid                bigint                                    NULL REFERENCES events (eventid) ON DELETE CASCADE,
1492	r_clock                  integer         DEFAULT '0'               NOT NULL,
1493	r_ns                     integer         DEFAULT '0'               NOT NULL,
1494	correlationid            bigint                                    NULL,
1495	userid                   bigint                                    NULL,
1496	name                     varchar(2048)   DEFAULT ''                NOT NULL,
1497	acknowledged             integer         DEFAULT '0'               NOT NULL,
1498	severity                 integer         DEFAULT '0'               NOT NULL,
1499	PRIMARY KEY (eventid)
1500);
1501CREATE INDEX problem_1 ON problem (source,object,objectid);
1502CREATE INDEX problem_2 ON problem (r_clock);
1503CREATE INDEX problem_3 ON problem (r_eventid);
1504CREATE TABLE problem_tag (
1505	problemtagid             bigint                                    NOT NULL,
1506	eventid                  bigint                                    NOT NULL REFERENCES problem (eventid) ON DELETE CASCADE,
1507	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1508	value                    varchar(255)    DEFAULT ''                NOT NULL,
1509	PRIMARY KEY (problemtagid)
1510);
1511CREATE INDEX problem_tag_1 ON problem_tag (eventid,tag,value);
1512CREATE TABLE tag_filter (
1513	tag_filterid             bigint                                    NOT NULL,
1514	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
1515	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
1516	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1517	value                    varchar(255)    DEFAULT ''                NOT NULL,
1518	PRIMARY KEY (tag_filterid)
1519);
1520CREATE TABLE event_recovery (
1521	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1522	r_eventid                bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1523	c_eventid                bigint                                    NULL REFERENCES events (eventid) ON DELETE CASCADE,
1524	correlationid            bigint                                    NULL,
1525	userid                   bigint                                    NULL,
1526	PRIMARY KEY (eventid)
1527);
1528CREATE INDEX event_recovery_1 ON event_recovery (r_eventid);
1529CREATE INDEX event_recovery_2 ON event_recovery (c_eventid);
1530CREATE TABLE correlation (
1531	correlationid            bigint                                    NOT NULL,
1532	name                     varchar(255)    DEFAULT ''                NOT NULL,
1533	description              text            DEFAULT ''                NOT NULL,
1534	evaltype                 integer         DEFAULT '0'               NOT NULL,
1535	status                   integer         DEFAULT '0'               NOT NULL,
1536	formula                  varchar(255)    DEFAULT ''                NOT NULL,
1537	PRIMARY KEY (correlationid)
1538);
1539CREATE INDEX correlation_1 ON correlation (status);
1540CREATE UNIQUE INDEX correlation_2 ON correlation (name);
1541CREATE TABLE corr_condition (
1542	corr_conditionid         bigint                                    NOT NULL,
1543	correlationid            bigint                                    NOT NULL REFERENCES correlation (correlationid) ON DELETE CASCADE,
1544	type                     integer         DEFAULT '0'               NOT NULL,
1545	PRIMARY KEY (corr_conditionid)
1546);
1547CREATE INDEX corr_condition_1 ON corr_condition (correlationid);
1548CREATE TABLE corr_condition_tag (
1549	corr_conditionid         bigint                                    NOT NULL REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE,
1550	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1551	PRIMARY KEY (corr_conditionid)
1552);
1553CREATE TABLE corr_condition_group (
1554	corr_conditionid         bigint                                    NOT NULL REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE,
1555	operator                 integer         DEFAULT '0'               NOT NULL,
1556	groupid                  bigint                                    NOT NULL REFERENCES hstgrp (groupid),
1557	PRIMARY KEY (corr_conditionid)
1558);
1559CREATE INDEX corr_condition_group_1 ON corr_condition_group (groupid);
1560CREATE TABLE corr_condition_tagpair (
1561	corr_conditionid         bigint                                    NOT NULL REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE,
1562	oldtag                   varchar(255)    DEFAULT ''                NOT NULL,
1563	newtag                   varchar(255)    DEFAULT ''                NOT NULL,
1564	PRIMARY KEY (corr_conditionid)
1565);
1566CREATE TABLE corr_condition_tagvalue (
1567	corr_conditionid         bigint                                    NOT NULL REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE,
1568	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1569	operator                 integer         DEFAULT '0'               NOT NULL,
1570	value                    varchar(255)    DEFAULT ''                NOT NULL,
1571	PRIMARY KEY (corr_conditionid)
1572);
1573CREATE TABLE corr_operation (
1574	corr_operationid         bigint                                    NOT NULL,
1575	correlationid            bigint                                    NOT NULL REFERENCES correlation (correlationid) ON DELETE CASCADE,
1576	type                     integer         DEFAULT '0'               NOT NULL,
1577	PRIMARY KEY (corr_operationid)
1578);
1579CREATE INDEX corr_operation_1 ON corr_operation (correlationid);
1580CREATE TABLE task (
1581	taskid                   bigint                                    NOT NULL,
1582	type                     integer                                   NOT NULL,
1583	status                   integer         DEFAULT '0'               NOT NULL,
1584	clock                    integer         DEFAULT '0'               NOT NULL,
1585	ttl                      integer         DEFAULT '0'               NOT NULL,
1586	proxy_hostid             bigint                                    NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
1587	PRIMARY KEY (taskid)
1588);
1589CREATE INDEX task_1 ON task (status,proxy_hostid);
1590CREATE TABLE task_close_problem (
1591	taskid                   bigint                                    NOT NULL REFERENCES task (taskid) ON DELETE CASCADE,
1592	acknowledgeid            bigint                                    NOT NULL,
1593	PRIMARY KEY (taskid)
1594);
1595CREATE TABLE item_preproc (
1596	item_preprocid           bigint                                    NOT NULL,
1597	itemid                   bigint                                    NOT NULL REFERENCES items (itemid) ON DELETE CASCADE,
1598	step                     integer         DEFAULT '0'               NOT NULL,
1599	type                     integer         DEFAULT '0'               NOT NULL,
1600	params                   varchar(255)    DEFAULT ''                NOT NULL,
1601	PRIMARY KEY (item_preprocid)
1602);
1603CREATE INDEX item_preproc_1 ON item_preproc (itemid,step);
1604CREATE TABLE task_remote_command (
1605	taskid                   bigint                                    NOT NULL REFERENCES task (taskid) ON DELETE CASCADE,
1606	command_type             integer         DEFAULT '0'               NOT NULL,
1607	execute_on               integer         DEFAULT '0'               NOT NULL,
1608	port                     integer         DEFAULT '0'               NOT NULL,
1609	authtype                 integer         DEFAULT '0'               NOT NULL,
1610	username                 varchar(64)     DEFAULT ''                NOT NULL,
1611	password                 varchar(64)     DEFAULT ''                NOT NULL,
1612	publickey                varchar(64)     DEFAULT ''                NOT NULL,
1613	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
1614	command                  text            DEFAULT ''                NOT NULL,
1615	alertid                  bigint                                    NULL,
1616	parent_taskid            bigint                                    NOT NULL,
1617	hostid                   bigint                                    NOT NULL,
1618	PRIMARY KEY (taskid)
1619);
1620CREATE TABLE task_remote_command_result (
1621	taskid                   bigint                                    NOT NULL REFERENCES task (taskid) ON DELETE CASCADE,
1622	status                   integer         DEFAULT '0'               NOT NULL,
1623	parent_taskid            bigint                                    NOT NULL,
1624	info                     text            DEFAULT ''                NOT NULL,
1625	PRIMARY KEY (taskid)
1626);
1627CREATE TABLE task_acknowledge (
1628	taskid                   bigint                                    NOT NULL REFERENCES task (taskid) ON DELETE CASCADE,
1629	acknowledgeid            bigint                                    NOT NULL,
1630	PRIMARY KEY (taskid)
1631);
1632CREATE TABLE sysmap_shape (
1633	sysmap_shapeid           bigint                                    NOT NULL,
1634	sysmapid                 bigint                                    NOT NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
1635	type                     integer         DEFAULT '0'               NOT NULL,
1636	x                        integer         DEFAULT '0'               NOT NULL,
1637	y                        integer         DEFAULT '0'               NOT NULL,
1638	width                    integer         DEFAULT '200'             NOT NULL,
1639	height                   integer         DEFAULT '200'             NOT NULL,
1640	text                     text            DEFAULT ''                NOT NULL,
1641	font                     integer         DEFAULT '9'               NOT NULL,
1642	font_size                integer         DEFAULT '11'              NOT NULL,
1643	font_color               varchar(6)      DEFAULT '000000'          NOT NULL,
1644	text_halign              integer         DEFAULT '0'               NOT NULL,
1645	text_valign              integer         DEFAULT '0'               NOT NULL,
1646	border_type              integer         DEFAULT '0'               NOT NULL,
1647	border_width             integer         DEFAULT '1'               NOT NULL,
1648	border_color             varchar(6)      DEFAULT '000000'          NOT NULL,
1649	background_color         varchar(6)      DEFAULT ''                NOT NULL,
1650	zindex                   integer         DEFAULT '0'               NOT NULL,
1651	PRIMARY KEY (sysmap_shapeid)
1652);
1653CREATE INDEX sysmap_shape_1 ON sysmap_shape (sysmapid);
1654CREATE TABLE sysmap_element_trigger (
1655	selement_triggerid       bigint                                    NOT NULL,
1656	selementid               bigint                                    NOT NULL REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE,
1657	triggerid                bigint                                    NOT NULL REFERENCES triggers (triggerid) ON DELETE CASCADE,
1658	PRIMARY KEY (selement_triggerid)
1659);
1660CREATE UNIQUE INDEX sysmap_element_trigger_1 ON sysmap_element_trigger (selementid,triggerid);
1661CREATE TABLE httptest_field (
1662	httptest_fieldid         bigint                                    NOT NULL,
1663	httptestid               bigint                                    NOT NULL REFERENCES httptest (httptestid) ON DELETE CASCADE,
1664	type                     integer         DEFAULT '0'               NOT NULL,
1665	name                     varchar(255)    DEFAULT ''                NOT NULL,
1666	value                    text            DEFAULT ''                NOT NULL,
1667	PRIMARY KEY (httptest_fieldid)
1668);
1669CREATE INDEX httptest_field_1 ON httptest_field (httptestid);
1670CREATE TABLE httpstep_field (
1671	httpstep_fieldid         bigint                                    NOT NULL,
1672	httpstepid               bigint                                    NOT NULL REFERENCES httpstep (httpstepid) ON DELETE CASCADE,
1673	type                     integer         DEFAULT '0'               NOT NULL,
1674	name                     varchar(255)    DEFAULT ''                NOT NULL,
1675	value                    text            DEFAULT ''                NOT NULL,
1676	PRIMARY KEY (httpstep_fieldid)
1677);
1678CREATE INDEX httpstep_field_1 ON httpstep_field (httpstepid);
1679CREATE TABLE dashboard (
1680	dashboardid              bigint                                    NOT NULL,
1681	name                     varchar(255)                              NOT NULL,
1682	userid                   bigint                                    NOT NULL REFERENCES users (userid),
1683	private                  integer         DEFAULT '1'               NOT NULL,
1684	PRIMARY KEY (dashboardid)
1685);
1686CREATE TABLE dashboard_user (
1687	dashboard_userid         bigint                                    NOT NULL,
1688	dashboardid              bigint                                    NOT NULL REFERENCES dashboard (dashboardid) ON DELETE CASCADE,
1689	userid                   bigint                                    NOT NULL REFERENCES users (userid) ON DELETE CASCADE,
1690	permission               integer         DEFAULT '2'               NOT NULL,
1691	PRIMARY KEY (dashboard_userid)
1692);
1693CREATE UNIQUE INDEX dashboard_user_1 ON dashboard_user (dashboardid,userid);
1694CREATE TABLE dashboard_usrgrp (
1695	dashboard_usrgrpid       bigint                                    NOT NULL,
1696	dashboardid              bigint                                    NOT NULL REFERENCES dashboard (dashboardid) ON DELETE CASCADE,
1697	usrgrpid                 bigint                                    NOT NULL REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE,
1698	permission               integer         DEFAULT '2'               NOT NULL,
1699	PRIMARY KEY (dashboard_usrgrpid)
1700);
1701CREATE UNIQUE INDEX dashboard_usrgrp_1 ON dashboard_usrgrp (dashboardid,usrgrpid);
1702CREATE TABLE widget (
1703	widgetid                 bigint                                    NOT NULL,
1704	dashboardid              bigint                                    NOT NULL REFERENCES dashboard (dashboardid) ON DELETE CASCADE,
1705	type                     varchar(255)    DEFAULT ''                NOT NULL,
1706	name                     varchar(255)    DEFAULT ''                NOT NULL,
1707	x                        integer         DEFAULT '0'               NOT NULL,
1708	y                        integer         DEFAULT '0'               NOT NULL,
1709	width                    integer         DEFAULT '1'               NOT NULL,
1710	height                   integer         DEFAULT '1'               NOT NULL,
1711	PRIMARY KEY (widgetid)
1712);
1713CREATE INDEX widget_1 ON widget (dashboardid);
1714CREATE TABLE widget_field (
1715	widget_fieldid           bigint                                    NOT NULL,
1716	widgetid                 bigint                                    NOT NULL REFERENCES widget (widgetid) ON DELETE CASCADE,
1717	type                     integer         DEFAULT '0'               NOT NULL,
1718	name                     varchar(255)    DEFAULT ''                NOT NULL,
1719	value_int                integer         DEFAULT '0'               NOT NULL,
1720	value_str                varchar(255)    DEFAULT ''                NOT NULL,
1721	value_groupid            bigint                                    NULL REFERENCES hstgrp (groupid) ON DELETE CASCADE,
1722	value_hostid             bigint                                    NULL REFERENCES hosts (hostid) ON DELETE CASCADE,
1723	value_itemid             bigint                                    NULL REFERENCES items (itemid) ON DELETE CASCADE,
1724	value_graphid            bigint                                    NULL REFERENCES graphs (graphid) ON DELETE CASCADE,
1725	value_sysmapid           bigint                                    NULL REFERENCES sysmaps (sysmapid) ON DELETE CASCADE,
1726	PRIMARY KEY (widget_fieldid)
1727);
1728CREATE INDEX widget_field_1 ON widget_field (widgetid);
1729CREATE INDEX widget_field_2 ON widget_field (value_groupid);
1730CREATE INDEX widget_field_3 ON widget_field (value_hostid);
1731CREATE INDEX widget_field_4 ON widget_field (value_itemid);
1732CREATE INDEX widget_field_5 ON widget_field (value_graphid);
1733CREATE INDEX widget_field_6 ON widget_field (value_sysmapid);
1734CREATE TABLE task_check_now (
1735	taskid                   bigint                                    NOT NULL REFERENCES task (taskid) ON DELETE CASCADE,
1736	itemid                   bigint                                    NOT NULL,
1737	PRIMARY KEY (taskid)
1738);
1739CREATE TABLE event_suppress (
1740	event_suppressid         bigint                                    NOT NULL,
1741	eventid                  bigint                                    NOT NULL REFERENCES events (eventid) ON DELETE CASCADE,
1742	maintenanceid            bigint                                    NULL REFERENCES maintenances (maintenanceid) ON DELETE CASCADE,
1743	suppress_until           integer         DEFAULT '0'               NOT NULL,
1744	PRIMARY KEY (event_suppressid)
1745);
1746CREATE UNIQUE INDEX event_suppress_1 ON event_suppress (eventid,maintenanceid);
1747CREATE INDEX event_suppress_2 ON event_suppress (suppress_until);
1748CREATE INDEX event_suppress_3 ON event_suppress (maintenanceid);
1749CREATE TABLE maintenance_tag (
1750	maintenancetagid         bigint                                    NOT NULL,
1751	maintenanceid            bigint                                    NOT NULL REFERENCES maintenances (maintenanceid) ON DELETE CASCADE,
1752	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1753	operator                 integer         DEFAULT '2'               NOT NULL,
1754	value                    varchar(255)    DEFAULT ''                NOT NULL,
1755	PRIMARY KEY (maintenancetagid)
1756);
1757CREATE INDEX maintenance_tag_1 ON maintenance_tag (maintenanceid);
1758CREATE TABLE dbversion (
1759	mandatory                integer         DEFAULT '0'               NOT NULL,
1760	optional                 integer         DEFAULT '0'               NOT NULL
1761);
1762INSERT INTO dbversion VALUES ('4000000','4000006');
1763