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