b2105ae68121a54d472b638ffa63befe4684f258
[gnucomo.git] / src / database / create.sql
1 --*************************************************************************
2 --  (c) Copyright 2002, De Winter Information Solutions
3 -- This is free software; you can redistribute it and/or modify it under the
4 -- terms of the GNU General Public License, see the file COPYING.
5 --*************************************************************************/
6 --
7 -- Gnucomo database creation script.
8 --
9 --
10 -- This SQL script creates the initial tables for the Gnucomo database.
11 -- Before running this script with 'psql -f', you should have your
12 -- DBA create the database and give access permissions.
13 --
14 --  $Log: create.sql,v $
15 --  Revision 1.9  2003-02-13 08:46:54  arjen
16 --  Added log, notification and parameter counters to the 'object' table.
17 --  Counting these things at the time a user interface needs them is
18 --  too slow. Other programs, like gcm_daemon en gcm_input should prepare
19 --  these counters for quick retrieval.
20 --
21 --  Revision 1.8  2003/02/08 07:36:41  arjen
22 --  Added new table to the database : log_adv_daemon
23 --
24 --  Revision 1.7  2003/02/05 09:29:08  arjen
25 --  Bug fix: action.statuscode was in upper case.
26 --
27 --  Revision 1.6  2003/01/20 07:29:48  arjen
28 --  Added new tables to the database: parameter_class and parameter_notification
29 --
30 --  Revision 1.5  2003/01/18 08:46:48  arjen
31 --  Added new records to the 'type_of_issue' table.
32 --  Changed semantics of actionid 9 in the 'action' table.
33 --
34 --
35
36 CREATE SEQUENCE "action_actionid_seq";
37
38 CREATE TABLE "action"
39 (
40         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
41         "actionname" text,
42         "statuscode" character varying(3),
43         "description" text
44 );
45
46
47 COPY "action" FROM stdin;
48 1       Entry in the system     new     This indicates that a notification has been entered into the system.
49 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
50 3       Remarks added   pen     Remarks have been added to the notification.
51 4       Priority changed manually       pen     The priority of the notification has been changed by the user.
52 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.
53 6       Action taken    pen     An action has been taken.
54 7       Assignment to user      pen     The notification has been assigned to an user.
55 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.
56 9       Investigation completed pen     Investigation has been done. Information is available to fix the problem.
57 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.
58 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.
59 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.
60 13      Action verified cls     A check has been done and the results were approved. The notification has been closed.
61 15      SMS sent        opn     An SMS has been sent.
62 14      E-mail sent     opn     An e-mail has been sent.
63 16      Fax sent        opn     An fax has been sent.
64 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
65 18      Notification closed     cls     The notification has been closed.
66 19      Notification reopend    opn     The notification has been reopend.
67 \.
68
69 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
70
71 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
72
73 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
74
75 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
76
77 SELECT setval ('"action_actionid_seq"', 19, true);
78
79 --
80 --
81
82 CREATE SEQUENCE "action_user_actionstepid_seq";
83
84 CREATE TABLE "action_user"
85 (
86         "actionstepid" bigint DEFAULT
87             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
88         "actionid" bigint,
89         "username" text,
90         "notificationid" bigint,
91         "timestamp" timestamp with time zone,
92         "statuscode" character varying(3),
93         "remarks" text
94 );
95
96 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
97
98 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
99
100 CREATE INDEX anu_username ON action_user USING btree (username);
101
102 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
103
104 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
105
106 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
107
108 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
109
110 --
111 --
112
113 CREATE TABLE "db_value"
114 (
115         "setting" text,
116         "setting_value" text
117 );
118
119
120 COPY "db_value" FROM stdin;
121 db_version      28
122 gcm_daemon_version      1
123 log_processing  0
124 last_notification       0
125 \.
126
127 --
128 --
129
130 CREATE TABLE "history"
131 (
132    paramid            bigint,
133    modified           timestamp,
134    change_nature      text,       --  CREATED, MODIFIED or REMOVED
135    changed_property   text,
136    new_value          text,
137    remark             text
138
139 );
140
141 --
142 --
143
144 CREATE SEQUENCE "log_logid_seq";
145
146 CREATE TABLE "log"
147 (
148         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
149         "objectid" bigint,
150         "original_filename" text,
151         "servicecode" text,
152         "object_timestamp" timestamp with time zone,
153         "timestamp" timestamp with time zone,
154         "rawdata" text,
155         "processed" boolean DEFAULT false,
156         "recognized" boolean DEFAULT false
157 );
158
159 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
160
161 CREATE INDEX log_objectid ON log USING btree (objectid);
162
163 CREATE INDEX log_original_filename ON log USING btree (original_filename);
164
165 CREATE INDEX log_servicecode ON log USING btree (servicecode);
166
167 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
168
169 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
170
171 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
172
173 CREATE INDEX log_processed ON log USING btree (processed);
174
175 SELECT setval ('"log_logid_seq"', 1, false);
176
177
178 --
179 --
180
181 CREATE SEQUENCE "log_advid_seq";
182
183
184 CREATE TABLE "log_adv"
185 (
186         "log_advid" bigint DEFAULT
187               nextval('"log_advid_seq"'::text) NOT NULL,
188         "logid" bigint NOT NULL,
189         "detailed_table"    text
190 );
191
192
193 CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
194
195 CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
196
197 SELECT setval ('"log_advid_seq"', 1, false);
198
199 CREATE TABLE log_adv_kernel_network
200 (
201        device_in         text,
202        device_out        text,
203        hw_address        text, 
204        source_ip         INET,
205        destination_ip    INET,
206        packet_length     bigint, 
207        tos_bit           text, 
208        prec_bit          text,
209        ttl               int,
210        header_id         bigint,
211        source_port       int, 
212        destination_port  int,
213        body_length       int,
214        protocol          text, 
215        body_len          int,
216        window            text,
217        urgp              int,
218        syn               boolean DEFAULT false,
219        type              int,
220        code              int,
221        sequence_number   int,
222        res               text,
223        rst               boolean,
224        df                boolean
225 ) INHERITS (log_adv);
226
227 CREATE TABLE log_adv_daemon
228 (
229        service TEXT,
230        event TEXT
231 ) INHERITS (log_adv);
232
233 CREATE INDEX log_adv_daemon_service ON log_adv_daemon (service);
234
235 /*
236 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
237 CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
238 -- Initial date: September 18th 2002
239 -- Update: November 13th 2002
240 -- Author: Brenno J.S.A.A.F. de Winter
241 -- Abstract: This routine sets a flag
242 DECLARE
243    var_value    VARCHAR;
244    var_setting  VARCHAR;
245
246 BEGIN
247
248     UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
249     RETURN NULL;
250 END;
251  ' LANGUAGE 'plpgsql';
252
253
254 CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
255 */
256 --
257 --
258
259 CREATE TABLE "log_notification"
260 (
261         "notificationid" bigint,
262         "logid" bigint
263 );
264
265 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
266
267 CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
268
269 CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
270
271 --
272 --
273
274 CREATE SEQUENCE "notification_notificationid_seq";
275
276 CREATE TABLE "notification"
277 (
278         "notificationid" bigint DEFAULT
279             nextval('"notification_notificationid_seq"'::text) NOT NULL,
280         "objectid" bigint,
281         "type_of_issueid" bigint,
282         "timestamp" timestamp with time zone,
283         "statuscode" character varying(3),
284         "priority" integer,
285         "escalation_count_timestamp" timestamp with time zone,
286         "repeat_notification_timestamp" timestamp with time zone,
287         "securitylevel_view" integer,
288         "securitylevel_add" integer,
289         "securitylevel_close" integer
290 );
291
292 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
293
294 CREATE INDEX not_objectid ON notification USING btree (objectid);
295
296 CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
297
298 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
299
300 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
301
302 CREATE INDEX not_priority ON notification USING btree (priority);
303
304 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
305
306 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
307
308 SELECT setval ('"notification_notificationid_seq"', 1, false);
309
310 --
311 --
312
313 CREATE SEQUENCE "object_objectid_seq";
314
315 CREATE TABLE "object"
316 (
317         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
318         "objectname" text,
319         "objectcode" text,
320         "scp_enabled" boolean,
321         "scp_inet" inet,
322         "mail_enabled" boolean,
323         "mail_from" text,
324         "sms_enabled" boolean,
325         "sms_number" text,
326         "fax_enabled" boolean,
327         "fax_number" text,
328         "object_description" text,
329         "object_owner" text,
330         "physical_location" text,
331         "timezone" text,
332         "remark" text,
333         "os"     text,
334         "os_version"   text,
335         "log_count"    bigint,
336         "notification_count"   bigint,
337         "parameter_count"      bigint
338 );
339
340 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
341
342 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
343
344 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
345
346 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
347
348 CREATE INDEX os ON object (os);
349
350 CREATE INDEX os_version ON object (os, os_version);
351
352 SELECT setval ('"object_objectid_seq"', 1, false);
353
354 --
355 --
356
357 CREATE TABLE "object_issue"
358 (
359         "objectid" bigint,
360         "type_of_issueid" bigint,
361         "default_priority" integer,
362         "escalation" boolean,
363         "escalation_time" time without time zone,
364         "max_priority" integer,
365         "adjust_setting" text
366 );
367
368 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
369
370 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
371
372 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
373
374 --
375 --
376
377 CREATE TABLE "object_priority"
378 (
379         "objectid" bigint,
380         "priorityid" integer,
381         "send_mail" boolean,
382         "send_sms" boolean,
383         "send_fax" boolean,
384         "repeat_notification" boolean,
385         "interval_for_repeat" time without time zone
386 );
387
388 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
389
390 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
391
392 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
393
394 --
395 --
396
397 CREATE TABLE "object_service"
398 (
399         "objectid" bigint,
400         "servicecode" text,
401         "expected_interval" bigint,
402         "last_entry" timestamp with time zone,
403         "default_priority" integer,
404         "maximum_priority" integer,
405         "accepted" boolean
406 );
407
408 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
409
410 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
411
412 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
413
414 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
415
416 --
417 --
418
419 CREATE TABLE "object_user"
420 (
421         "objectid" bigint,
422         "username" text,
423         "security_level" integer
424 );
425
426 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
427
428 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
429
430 CREATE INDEX ous_username ON object_user USING btree (username);
431
432 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
433
434 --
435 --
436
437 CREATE SEQUENCE "paramid_seq";
438
439 CREATE TABLE "parameter"
440 (
441         "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
442         "objectid" bigint,
443         "name" text,
444         "class" text,
445         "description" text,
446
447         primary key (paramid)
448 );
449
450 CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
451
452 SELECT setval ('"paramid_seq"', 1, true);
453
454 --
455 --
456
457 CREATE TABLE "parameter_class"
458 (
459    "name"             text,     --  Name of the class: see parameter.class
460    "property_name"    text,
461    "description"      text,
462    "property_type"    text,     --  STATIC or DYNAMIC
463    "min"              float,    --  Default minimum value
464    "max"              float,    --  Default maximum value
465    "notify"           boolean,  --  Notify if something changes ?
466
467    primary key (name, property_name)
468 );
469
470 INSERT INTO parameter_class (name, property_name, description, property_type, notify)
471   VALUES ('package', 'version', 'The installed version of the package', 'STATIC', 't');
472
473 --
474 --
475
476 CREATE TABLE "parameter_notification"
477 (
478    "notificationid" bigint,
479    "paramid"        bigint,
480
481    primary key (notificationid, paramid)
482 );
483
484 --
485 --
486
487 CREATE TABLE "priority"
488 (
489         "priority" integer,
490         "send_mail" boolean,
491         "send_sms" boolean,
492         "send_fax" boolean,
493         "repeat_notification" boolean,
494         "interval_for_repeat" time without time zone
495 );
496
497
498 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
499
500 --
501 --
502
503 CREATE TABLE "property"
504 (
505    paramid bigint,
506    name    text,
507    value   text,
508    type    text,   --   STATIC or DYNAMIC
509    min     float,
510    max     float,
511
512    primary key (paramid, name)
513 );
514
515 --
516 --
517
518 CREATE TABLE "service"
519 (
520         "servicecode" text,
521         "servicename" text,
522         "default_priority" integer,
523         "max_priority" integer
524 );
525
526 COPY "service" FROM stdin;
527 httpd   httpd   1       5
528 imap    imap    1       5
529 imapd   imapd   1       5
530 kernel  kernel  1       5
531 sshd    sshd    1       5
532 su      su      1       5
533 syslogd syslogd 1       5
534 \.
535
536 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
537
538 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
539
540 --
541
542 CREATE TABLE "status"
543 (
544         "statuscode" character varying(3),
545         "statusname" text,
546         "open_notification" boolean,
547         "description" text
548 );
549
550
551 COPY "status" FROM stdin;
552 new     new entry       t       Just detected, but nothing has been done yet
553 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
554 pen     pending t       The notification is currently being worked on.
555 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
556 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
557 cls     closed  f       The notification has been closed
558 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
559 \.
560
561 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
562
563 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
564
565 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
566
567 --
568 --
569
570 CREATE TABLE supported_os
571 (
572     os_name text,
573     remarks text
574 );
575
576 CREATE UNIQUE INDEX spp_os ON supported_os (os_name);
577
578 --
579 --
580
581 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
582
583 CREATE TABLE "type_of_issue"
584 (
585         "type_of_issueid" bigint DEFAULT
586            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
587         "name" text,
588         "suggested_priority" text,
589         "description" text,
590         "active" boolean,
591         automated_check       boolean,
592         alert_level           int,
593         last_run              timestamp,
594         recheck_interval      timestamp
595 );
596
597
598 COPY "type_of_issue" FROM stdin;
599 1       manual entry    4       A manual entry of a notification        t
600 2       parameter created       3       A new parameter was created     t
601 3       property modified       3       The STATIC property of a parameter was modified t
602 4       parameter removed       3       A parameter was removed t
603 \.
604
605 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
606
607 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
608
609 CREATE INDEX toi_active ON type_of_issue USING btree (active);
610
611 SELECT setval ('"type_of_issue_type_of_issue_seq"', 4, true);
612
613 --
614 --
615
616 CREATE TABLE "usr"
617 (
618         "username" text NOT NULL,
619         "active_sessionid" bigint,
620         "account_active" boolean,
621         "security_level" integer
622 );
623
624 CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
625
626 CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
627
628 CREATE INDEX usr_account_active ON usr USING btree (account_active);
629
630 CREATE INDEX usr_security_level ON usr USING btree (security_level);
631