(1.0.D002) Create Database
[gnucomo.git] / src / database / create.sql
1 --
2 -- Gnucomo database creation script.
3 --
4 --
5 -- This SQL script creates the initial tables for the Gnucomo database.
6 -- Before running this script with 'psql -f', you should have your
7 -- DBA create the database and give access permissions.
8 --
9 --
10
11 CREATE SEQUENCE "action_actionid_seq";
12
13 CREATE TABLE "action"
14 (
15         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
16         "actionname" text,
17         "statuscode" character varying(3),
18         "description" text
19 );
20
21
22 COPY "action" FROM stdin;
23 1       Entry in the system     NEW     This indicates that a notification has been entered into the system.
24 2       Display to user OPN     The notification has been displayed to the user. It doesn't mean that the user actually read the notification, but he/she should be aware. For that reason we consider the notification to be OPEN
25 3       Remarks added   PEN     Remarks have been added to the notification.
26 4       Priority changed manually       PEN     The priority of the notification has been changed by the user.
27 5       Priority changed automatically  PEN     The priority of the notification has been changed by the system. This can be the result of an action by the user or an automatical escalation.
28 6       Action taken    PEN     An action has been taken.
29 7       Assignment to user      PEN     The notification has been assigned to an user.
30 8       More information or research needed.    INV     The notification is relevant and will be handled, however more information or research will be needed. For that reason the status has been altered to UNDER INVESTIGATION.
31 9       Make output reference   REF     The automated output from an object was sent to gnucomo. The input has been identified as a valid reference for the future. For that reason the status is now REFERENCE
32 10      Job output no longer valid      CLS     By making a newer job output a valid reference, this data has been obsoleted. Since it was a reference once the output isn't interesting anymore and thus the notification can be closed.
33 11      Action taken - please verify    CLS     An action has been taken and things should have been resolved. Before the notification can be closed a verification has to be done. The new status is now VERIFY.
34 12      Action not verified     PEN     A check has been done and the results were not good. New verification is needed. The status has been changed back to PEN.
35 13      Action verified CLS     A check has been done and the results were approved. The notification has been closed.
36 15      SMS sent        OPN     An SMS has been sent.
37 14      E-mail sent     OPN     An e-mail has been sent.
38 16      Fax sent        OPN     An fax has been sent.
39 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
40 18      Notification closed     CLS     The notification has been closed.
41 19      Notification reopend    OPN     The notification has been reopend.
42 \.
43
44 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
45
46 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
47
48 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
49
50 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
51
52 SELECT setval ('"action_actionid_seq"', 19, true);
53
54 --
55 --
56
57 CREATE SEQUENCE "action_user_actionstepid_seq";
58
59 CREATE TABLE "action_user"
60 (
61         "actionstepid" bigint DEFAULT
62             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
63         "actionid" bigint,
64         "username" text,
65         "notificationid" bigint,
66         "timestamp" timestamp with time zone,
67         "statuscode" character varying(3),
68         "remarks" text
69 );
70
71 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
72
73 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
74
75 CREATE INDEX anu_username ON action_user USING btree (username);
76
77 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
78
79 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
80
81 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
82
83 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
84
85 --
86 --
87
88 CREATE SEQUENCE "log_logid_seq";
89
90 CREATE TABLE "log"
91 (
92         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
93         "objectid" bigint,
94         "original_filename" text,
95         "servicecode" text,
96         "object_timestamp" timestamp with time zone,
97         "timestamp" timestamp with time zone,
98         "rawdata" text
99 );
100
101 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
102
103 CREATE INDEX log_objectid ON log USING btree (objectid);
104
105 CREATE INDEX log_original_filename ON log USING btree (original_filename);
106
107 CREATE INDEX log_servicecode ON log USING btree (servicecode);
108
109 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
110
111 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
112
113 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
114
115 SELECT setval ('"log_logid_seq"', 1, false);
116
117 --
118 --
119
120 CREATE TABLE "log_adv"
121 (
122         "logid" bigint,
123         "source_ip" inet,
124         "destination_ip" inet,
125         "mac_address" macaddr,
126         "packetlength" integer,
127         "protocol" text,
128         "source_port" integer,
129         "destination_port" integer,
130         "messageid" text,
131         "system_username" text,
132         "networkdevice" text
133 );
134
135 CREATE INDEX loa_logid ON log_adv USING btree (logid);
136
137 CREATE INDEX loa_source_ip ON log_adv USING btree (source_ip);
138
139 CREATE INDEX loa_destination_ip ON log_adv USING btree (destination_ip);
140
141 CREATE INDEX loa_mac_address ON log_adv USING btree (mac_address);
142
143 CREATE INDEX loa_packetlength ON log_adv USING btree (packetlength);
144
145 CREATE INDEX loa_protocol ON log_adv USING btree (protocol);
146
147 CREATE INDEX loa_source_port ON log_adv USING btree (source_port);
148
149 CREATE INDEX loa_destination_port ON log_adv USING btree (destination_port);
150
151 CREATE INDEX loa_messageid ON log_adv USING btree (messageid);
152
153 CREATE INDEX loa_system_username ON log_adv USING btree (system_username);
154
155 CREATE INDEX loa_networkdevice ON log_adv USING btree (networkdevice);
156
157 --
158 --
159
160 CREATE TABLE "log_notification"
161 (
162         "notificationid" bigint,
163         "logid" bigint
164 );
165
166 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
167
168 CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
169
170 CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
171
172 --
173 --
174
175 CREATE SEQUENCE "notification_notificationid_seq";
176
177 CREATE TABLE "notification"
178 (
179         "notificationid" bigint DEFAULT
180             nextval('"notification_notificationid_seq"'::text) NOT NULL,
181         "objectid" bigint,
182         "type_of_notificationid" bigint,
183         "timestamp" timestamp with time zone,
184         "statuscode" character varying(3),
185         "priority" integer,
186         "escalation_count_timestamp" timestamp with time zone,
187         "repeat_notification_timestamp" timestamp with time zone,
188         "securitylevel_view" integer,
189         "securitylevel_add" integer,
190         "securitylevel_close" integer
191 );
192
193 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
194
195 CREATE INDEX not_objectid ON notification USING btree (objectid);
196
197 CREATE INDEX not_type_of_notificationid ON notification USING btree (type_of_notificationid);
198
199 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
200
201 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
202
203 CREATE INDEX not_priority ON notification USING btree (priority);
204
205 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
206
207 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
208
209 SELECT setval ('"notification_notificationid_seq"', 1, false);
210
211 --
212 --
213
214 CREATE SEQUENCE "object_objectid_seq";
215
216 CREATE TABLE "object"
217 (
218         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
219         "objectname" text,
220         "objectcode" text,
221         "scp_enabled" boolean,
222         "scp_inet" inet,
223         "mail_enabled" boolean,
224         "mail_from" text,
225         "sms_enabled" boolean,
226         "sms_number" text,
227         "fax_enabled" boolean,
228         "fax_number" text,
229         "object_description" text,
230         "object_owner" text,
231         "physical_location" text,
232         "timezone" text,
233         "remark" text
234 );
235
236 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
237
238 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
239
240 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
241
242 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
243
244 SELECT setval ('"object_objectid_seq"', 1, false);
245
246 --
247 --
248
249 CREATE TABLE "object_issue"
250 (
251         "objectid" bigint,
252         "type_of_notificationid" bigint,
253         "default_priority" integer,
254         "escalation" boolean,
255         "escalation_time" time without time zone,
256         "max_priority" integer,
257         "adjust_setting" text
258 );
259
260 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_notificationid);
261
262 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
263
264 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_notificationid);
265
266 --
267 --
268
269 CREATE TABLE "object_priority"
270 (
271         "objectid" bigint,
272         "priorityid" integer,
273         "send_mail" boolean,
274         "send_sms" boolean,
275         "send_fax" boolean,
276         "repeat_notification" boolean,
277         "interval_for_repeat" time without time zone
278 );
279
280 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
281
282 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
283
284 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
285
286 --
287 --
288
289 CREATE TABLE "object_service"
290 (
291         "objectid" bigint,
292         "servicecode" text,
293         "expected_interval" bigint,
294         "last_entry" timestamp with time zone,
295         "default_priority" integer,
296         "maximum_priority" integer,
297         "accepted" boolean
298 );
299
300 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
301
302 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
303
304 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
305
306 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
307
308 --
309 --
310
311 CREATE TABLE "object_system_user"
312 (
313         "objectid" bigint,
314         "system_username" text,
315         "can_login" boolean,
316         "can_be_root" boolean
317 );
318
319 CREATE UNIQUE INDEX osu_pk ON object_system_user USING btree (objectid, system_username);
320
321 CREATE INDEX osu_objectid ON object_system_user USING btree (objectid);
322
323 CREATE INDEX osu_system_username ON object_system_user USING btree (system_username);
324
325 --
326 --
327
328 CREATE TABLE "object_user"
329 (
330         "objectid" bigint,
331         "username" text,
332         "security_level" integer
333 );
334
335 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
336
337 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
338
339 CREATE INDEX ous_username ON object_user USING btree (username);
340
341 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
342
343 --
344 --
345
346 CREATE TABLE "priority"
347 (
348         "priority" integer,
349         "send_mail" boolean,
350         "send_sms" boolean,
351         "send_fax" boolean,
352         "repeat_notification" boolean,
353         "interval_for_repeat" time without time zone
354 );
355
356
357 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
358
359 --
360 --
361
362 CREATE TABLE "service"
363 (
364         "servicecode" text,
365         "servicename" text,
366         "default_priority" integer,
367         "max_priority" integer
368 );
369
370 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
371
372 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
373
374 --
375 --
376
377 CREATE TABLE "status"
378 (
379         "statuscode" character varying(3),
380         "statusname" text,
381         "open_notification" boolean,
382         "description" text
383 );
384
385
386 COPY "status" FROM stdin;
387 new     new entry       t       Just detected, but nothing has been done yet
388 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
389 pen     pending t       The notification is currently being worked on.
390 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
391 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
392 cls     closed  f       The notification has been closed
393 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
394 \.
395
396 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
397
398 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
399
400 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
401
402 --
403 --
404
405 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
406
407 CREATE TABLE "type_of_issue"
408 (
409         "type_of_issueid" bigint DEFAULT
410            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
411         "name" text,
412         "suggested_priority" text,
413         "description" text,
414         "active" boolean
415 );
416
417
418 COPY "type_of_issue" FROM stdin;
419 1       manual entry    4       A manual entry of a notification        t
420 \.
421
422 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
423
424 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
425
426 CREATE INDEX toi_active ON type_of_issue USING btree (active);
427
428 SELECT setval ('"type_of_issue_type_of_issue_seq"', 1, true);
429
430 --
431 --
432
433 CREATE SEQUENCE "unprocessed_l_unprocessedid_seq";
434
435 CREATE TABLE "unprocessed_log"
436 (
437         "unprocessedid" bigint DEFAULT
438            nextval('"unprocessed_l_unprocessedid_seq"'::text) NOT NULL,
439         "objectid" bigint,
440         "servicecode" text
441 );
442
443 CREATE UNIQUE INDEX unprocessed_l_unprocessedid_key ON unprocessed_log USING btree (unprocessedid);
444
445 SELECT setval ('"unprocessed_l_unprocessedid_seq"', 1, false);
446
447 --
448 --
449
450 CREATE TABLE "user_gnucomo"
451 (
452         "username" text,
453         "password" text,
454         "active_sessionid" bigint,
455         "account_active" boolean,
456         "security_level" integer
457 );
458
459 CREATE UNIQUE INDEX usr_pk ON user_gnucomo USING btree (username);
460
461 CREATE INDEX usr_active_sessionid ON user_gnucomo USING btree (active_sessionid);
462
463