Changed the type of log_adv_daemon_email.delay and log_adv_daemon_email.xdelay
[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.18  2003-12-03 08:06:57  arjen
16 --  Changed the type of log_adv_daemon_email.delay and log_adv_daemon_email.xdelay
17 --  from time to interval. These delays can be more than 24 hours.
18 --
19 --  Revision 1.17  2003/09/02 12:49:47  arjen
20 --  BUGFIX: Secondary indices on log_notification were unique.
21 --  Additional information in the 'usr' table: 'display_name' and 'email'.
22 --  Added new issues and services.
23 --
24 --  Revision 1.16  2003/08/16 14:29:02  arjen
25 --  Fixed a few typos.
26 --
27 --  Revision 1.15  2003/08/05 07:43:24  arjen
28 --  Added index to the history table.
29 --
30 --  Revision 1.14  2003/07/09 07:14:59  arjen
31 --  New database tables: notification_check, notification_check_buffer,
32 --  notification_check_line and object_statistics.
33 --
34 --  Revision 1.13  2003/03/29 08:27:05  arjen
35 --  New columns in the table 'log_adv_daemon_email': size, pri, relay,
36 --  status_details and dsn.
37 --  Added several indices for the table 'log_adv_daemon_email'.
38 --
39 --  Revision 1.12  2003/02/21 08:38:38  arjen
40 --  Added new table to the database: log_adv_daemon_email.
41 --
42 --  Revision 1.11  2003/02/16 08:24:38  arjen
43 --  Added a new entry to the action table: Notification was displayed in the listing
44 --
45 --  Revision 1.10  2003/02/14 06:32:27  arjen
46 --  Setup the groups and database permissions. The three groups
47 --  are: view, ops and admin.
48 --  Added a new entry to the action table.
49 --
50 --  Revision 1.9  2003/02/13 08:46:54  arjen
51 --  Added log, notification and parameter counters to the 'object' table.
52 --  Counting these things at the time a user interface needs them is
53 --  too slow. Other programs, like gcm_daemon en gcm_input should prepare
54 --  these counters for quick retrieval.
55 --
56 --  Revision 1.8  2003/02/08 07:36:41  arjen
57 --  Added new table to the database : log_adv_daemon
58 --
59 --  Revision 1.7  2003/02/05 09:29:08  arjen
60 --  Bug fix: action.statuscode was in upper case.
61 --
62 --  Revision 1.6  2003/01/20 07:29:48  arjen
63 --  Added new tables to the database: parameter_class and parameter_notification
64 --
65 --  Revision 1.5  2003/01/18 08:46:48  arjen
66 --  Added new records to the 'type_of_issue' table.
67 --  Changed semantics of actionid 9 in the 'action' table.
68 --
69 --
70
71 CREATE SEQUENCE "action_actionid_seq";
72
73 CREATE TABLE "action"
74 (
75         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
76         "actionname" text,
77         "statuscode" character varying(3),
78         "description" text
79 );
80
81
82 COPY "action" FROM stdin;
83 1       Entry in the system     new     This indicates that a notification has been entered into the system.
84 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
85 3       Remarks added   pen     Remarks have been added to the notification.
86 4       Priority changed manually       pen     The priority of the notification has been changed by the user.
87 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.
88 6       Action taken    pen     An action has been taken.
89 7       Assignment to user      pen     The notification has been assigned to an user.
90 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.
91 9       Investigation completed pen     Investigation has been done. Information is available to fix the problem.
92 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.
93 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.
94 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.
95 13      Action verified cls     A check has been done and the results were approved. The notification has been closed.
96 15      SMS sent        opn     An SMS has been sent.
97 14      E-mail sent     opn     An e-mail has been sent.
98 16      Fax sent        opn     An fax has been sent.
99 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
100 18      Notification closed     cls     The notification has been closed.
101 19      Notification reopend    opn     The notification has been reopend.
102 20      Redisplayed to user     \N      The notification has been presented to a user. This is not the first time
103 21      Displayed in list       \N      The notification has been presented in a list with other notifications.
104 \.
105
106 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
107
108 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
109
110 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
111
112 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
113
114 SELECT setval ('"action_actionid_seq"', 21, true);
115
116 --
117 --
118
119 CREATE SEQUENCE "action_user_actionstepid_seq";
120
121 CREATE TABLE "action_user"
122 (
123         "actionstepid" bigint DEFAULT
124             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
125         "actionid" bigint,
126         "username" text,
127         "notificationid" bigint,
128         "timestamp" timestamp with time zone,
129         "statuscode" character varying(3),
130         "remarks" text
131 );
132
133 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
134
135 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
136
137 CREATE INDEX anu_username ON action_user USING btree (username);
138
139 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
140
141 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
142
143 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
144
145 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
146
147 --
148 --
149
150 CREATE TABLE "db_value"
151 (
152         "setting" text,
153         "setting_value" text
154 );
155
156
157 COPY "db_value" FROM stdin;
158 db_version      44
159 gcm_daemon_version      5
160 log_processing  0
161 last_notification       0
162 \.
163
164 --
165 --
166
167 CREATE TABLE "history"
168 (
169    paramid            bigint,
170    modified           timestamp,
171    change_nature      text,       --  CREATED, MODIFIED or REMOVED
172    changed_property   text,
173    new_value          text,
174    remark             text
175
176 );
177
178 CREATE INDEX history_pid_mod  ON history(paramid, modified);
179
180 --
181 --
182
183 CREATE SEQUENCE "log_logid_seq";
184
185 CREATE TABLE "log"
186 (
187         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
188         "objectid" bigint,
189         "original_filename" text,
190         "servicecode" text,
191         "object_timestamp" timestamp with time zone,
192         "timestamp" timestamp with time zone,
193         "rawdata" text,
194         "processed" boolean DEFAULT false,
195         "recognized" boolean DEFAULT false
196 );
197
198 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
199
200 CREATE INDEX log_objectid ON log USING btree (objectid);
201
202 CREATE INDEX log_original_filename ON log USING btree (original_filename);
203
204 CREATE INDEX log_servicecode ON log USING btree (servicecode);
205
206 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
207
208 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
209
210 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
211
212 CREATE INDEX log_processed ON log USING btree (processed);
213
214 SELECT setval ('"log_logid_seq"', 1, false);
215
216
217 --
218 --
219
220 CREATE SEQUENCE "log_advid_seq";
221
222
223 CREATE TABLE "log_adv"
224 (
225         "log_advid" bigint DEFAULT
226               nextval('"log_advid_seq"'::text) NOT NULL,
227         "logid" bigint NOT NULL,
228         "detailed_table"    text
229 );
230
231
232 CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
233
234 CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
235
236 SELECT setval ('"log_advid_seq"', 1, false);
237
238 CREATE TABLE log_adv_kernel_network
239 (
240        device_in         text,
241        device_out        text,
242        hw_address        text, 
243        source_ip         INET,
244        destination_ip    INET,
245        packet_length     bigint, 
246        tos_bit           text, 
247        prec_bit          text,
248        ttl               int,
249        header_id         bigint,
250        source_port       int, 
251        destination_port  int,
252        body_length       int,
253        protocol          text, 
254        body_len          int,
255        window            text,
256        urgp              int,
257        syn               boolean DEFAULT false,
258        type              int,
259        code              int,
260        sequence_number   int,
261        res               text,
262        rst               boolean,
263        df                boolean
264 ) INHERITS (log_adv);
265
266 CREATE TABLE log_adv_daemon
267 (
268        service TEXT,
269        event   TEXT
270 ) INHERITS (log_adv);
271
272 CREATE INDEX log_adv_daemon_service ON log_adv_daemon (service);
273
274 CREATE TABLE log_adv_daemon_email
275 (
276      source_ip            INET,
277      destination_ip       INET,
278      internal_messageid   TEXT, 
279      external_messageid   TEXT,
280      to_email             TEXT,
281      from_email           TEXT,
282      delay                interval,
283      xdelay               interval,
284      mailer               TEXT,
285      status               TEXT,
286      pid                  INT,
287      size                 INT,
288      pri                  INT,
289      relay                TEXT,
290      status_details       TEXT,
291      dsn                  TEXT
292 ) INHERITS (log_adv_daemon);
293
294 CREATE INDEX log_adv_daemon_email_s_ip ON log_adv_daemon_email (source_ip);
295 CREATE INDEX log_adv_daemon_email_d_ip ON log_adv_daemon_email (destination_ip);
296 CREATE INDEX log_adv_daemon_email_to   ON log_adv_daemon_email (to_email);
297 CREATE INDEX log_adv_daemon_email_from ON log_adv_daemon_email (from_email);
298 CREATE INDEX log_adv_email_status      ON log_adv_daemon_email (status);
299
300
301 /*
302 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
303 CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
304 -- Initial date: September 18th 2002
305 -- Update: November 13th 2002
306 -- Author: Brenno J.S.A.A.F. de Winter
307 -- Abstract: This routine sets a flag
308 DECLARE
309    var_value    VARCHAR;
310    var_setting  VARCHAR;
311
312 BEGIN
313
314     UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
315     RETURN NULL;
316 END;
317  ' LANGUAGE 'plpgsql';
318
319
320 CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
321 */
322 --
323 --
324
325 CREATE TABLE "log_notification"
326 (
327         "notificationid" bigint,
328         "logid" bigint
329 );
330
331 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
332
333 CREATE INDEX lon_notificationid ON log_notification USING btree (notificationid);
334
335 CREATE INDEX lon_logid ON log_notification USING btree (logid);
336
337 --
338 --
339
340 CREATE SEQUENCE "notification_notificationid_seq";
341
342 CREATE TABLE "notification"
343 (
344         "notificationid" bigint DEFAULT
345             nextval('"notification_notificationid_seq"'::text) NOT NULL,
346         "objectid" bigint,
347         "type_of_issueid" bigint,
348         "timestamp" timestamp with time zone,
349         "statuscode" character varying(3),
350         "priority" integer,
351         "escalation_count_timestamp" timestamp with time zone,
352         "repeat_notification_timestamp" timestamp with time zone,
353         "securitylevel_view" integer,
354         "securitylevel_add" integer,
355         "securitylevel_close" integer
356 );
357
358 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
359
360 CREATE INDEX not_objectid ON notification USING btree (objectid);
361
362 CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
363
364 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
365
366 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
367
368 CREATE INDEX not_priority ON notification USING btree (priority);
369
370 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
371
372 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
373
374 SELECT setval ('"notification_notificationid_seq"', 1, false);
375
376 --
377 --
378
379 CREATE SEQUENCE checkid_seq;
380     
381 CREATE TABLE notification_check
382 (
383      checkid                 bigint DEFAULT nextval('checkid_seq'::text) NOT NULL,
384      checkname               TEXT,
385      description             TEXT,
386      time_between_executions INTERVAL, 
387      last_execution          DATETIME,
388      execution_counter       BIGINT,
389      notificationcounter     BIGINT,
390      decreasinglist          BOOLEAN default false,
391      type_of_issueid         BIGINT
392 );
393
394 CREATE UNIQUE INDEX not_check_checkid ON notification_check (checkid);
395
396 CREATE UNIQUE INDEX not_check_checkname ON notification_check (checkname);
397
398 CREATE INDEX not_check_check_lastexec ON notification_check (last_execution);
399
400 --
401 --
402
403 CREATE TABLE notification_check_buffer
404 (
405     checkid     BIGINT,
406     sortorder   INTEGER,
407     pid         INTEGER,
408     logid       bigint
409 );
410
411 CREATE INDEX notcheckbuffer_checkid ON notification_check_buffer(checkid);
412      
413 CREATE INDEX notcheckbuffer_sort ON notification_check_buffer(sortorder);
414
415 CREATE INDEX notcheckbuffer_pid ON notification_check_buffer(pid);
416      
417 CREATE INDEX notcheckbuffer_logid ON notification_check_buffer(logid);
418
419 --
420 --
421
422 CREATE SEQUENCE checklineid_seq;
423      
424 CREATE TABLE notification_check_line
425 (
426     checklineid             BIGINT DEFAULT nextval('checklineid_seq'::text) NOT NULL,
427     checkid                 BIGINT,
428     sortorder               INTEGER,
429     last_logid              BIGINT default 0,
430     historicboundary        INTERVAL default '0',
431     use_logid               BOOLEAN default false,
432     sql_query               TEXT
433 );
434      
435 CREATE UNIQUE INDEX notcheckline_checklineid ON notification_check_line (checklineid);
436
437 CREATE INDEX notcheckline_checkid            ON notification_check_line (checkid);
438
439 CREATE INDEX notcheckline_sort               ON notification_check_line (sortorder);
440
441 CREATE INDEX notcheckline_check_sort         ON notification_check_line (checkid, sortorder);
442
443 --
444 --
445
446 CREATE SEQUENCE "object_objectid_seq";
447
448 CREATE TABLE "object"
449 (
450         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
451         "objectname" text,
452         "objectcode" text,
453         "scp_enabled" boolean,
454         "scp_inet" inet,
455         "mail_enabled" boolean,
456         "mail_from" text,
457         "sms_enabled" boolean,
458         "sms_number" text,
459         "fax_enabled" boolean,
460         "fax_number" text,
461         "object_description" text,
462         "object_owner" text,
463         "physical_location" text,
464         "timezone" text,
465         "remark" text,
466         "os"     text,
467         "os_version"   text,
468         "log_count"    bigint,
469         "notification_count"   bigint,
470         "parameter_count"      bigint
471 );
472
473 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
474
475 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
476
477 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
478
479 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
480
481 CREATE INDEX os ON object (os);
482
483 CREATE INDEX os_version ON object (os, os_version);
484
485 SELECT setval ('"object_objectid_seq"', 1, false);
486
487 --
488 --
489
490 CREATE TABLE "object_issue"
491 (
492         "objectid" bigint,
493         "type_of_issueid" bigint,
494         "default_priority" integer,
495         "escalation" boolean,
496         "escalation_time" time without time zone,
497         "max_priority" integer,
498         "adjust_setting" text
499 );
500
501 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
502
503 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
504
505 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
506
507 --
508 --
509
510 CREATE TABLE "object_priority"
511 (
512         "objectid" bigint,
513         "priorityid" integer,
514         "send_mail" boolean,
515         "send_sms" boolean,
516         "send_fax" boolean,
517         "repeat_notification" boolean,
518         "interval_for_repeat" time without time zone
519 );
520
521 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
522
523 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
524
525 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
526
527 --
528 --
529
530 CREATE TABLE "object_service"
531 (
532         "objectid" bigint,
533         "servicecode" text,
534         "expected_interval" bigint,
535         "last_entry" timestamp with time zone,
536         "default_priority" integer,
537         "maximum_priority" integer,
538         "accepted" boolean
539 );
540
541 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
542
543 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
544
545 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
546
547 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
548
549 --
550 --
551
552 CREATE TABLE object_statistics
553 (
554     objectid       bigint,
555     statname       text,
556     statvalue      double precision,
557
558     primary key (objectid, statname)
559 );
560
561 CREATE INDEX obj_stat_objid ON object_statistics USING btree (objectid);
562
563 --
564 --
565
566 CREATE TABLE "object_user"
567 (
568         "objectid" bigint,
569         "username" text,
570         "security_level" integer
571 );
572
573 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
574
575 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
576
577 CREATE INDEX ous_username ON object_user USING btree (username);
578
579 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
580
581 --
582 --
583
584 CREATE SEQUENCE "paramid_seq";
585
586 CREATE TABLE "parameter"
587 (
588         "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
589         "objectid" bigint,
590         "name" text,
591         "class" text,
592         "description" text,
593
594         primary key (paramid)
595 );
596
597 CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
598
599 SELECT setval ('"paramid_seq"', 1, true);
600
601 --
602 --
603
604 CREATE TABLE "parameter_class"
605 (
606    "name"             text,     --  Name of the class: see parameter.class
607    "property_name"    text,
608    "description"      text,
609    "property_type"    text,     --  STATIC or DYNAMIC
610    "min"              float,    --  Default minimum value
611    "max"              float,    --  Default maximum value
612    "notify"           boolean,  --  Notify if something changes ?
613
614    primary key (name, property_name)
615 );
616
617 INSERT INTO parameter_class (name, property_name, description, property_type, notify)
618   VALUES ('package', 'version', 'The installed version of the package', 'STATIC', 't');
619
620 --
621 --
622
623 CREATE TABLE "parameter_notification"
624 (
625    "notificationid" bigint,
626    "paramid"        bigint,
627
628    primary key (notificationid, paramid)
629 );
630
631 --
632 --
633
634 CREATE TABLE "priority"
635 (
636         "priority" integer,
637         "send_mail" boolean,
638         "send_sms" boolean,
639         "send_fax" boolean,
640         "repeat_notification" boolean,
641         "interval_for_repeat" time without time zone
642 );
643
644
645 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
646
647 --
648 --
649
650 CREATE TABLE "property"
651 (
652    paramid bigint,
653    name    text,
654    value   text,
655    type    text,   --   STATIC or DYNAMIC
656    min     float,
657    max     float,
658
659    primary key (paramid, name)
660 );
661
662 --
663 --
664
665 CREATE TABLE "service"
666 (
667         "servicecode" text,
668         "servicename" text,
669         "default_priority" integer,
670         "max_priority" integer
671 );
672
673 COPY "service" FROM stdin;
674 httpd   httpd   1       5
675 imap    imap    1       5
676 imapd   imapd   1       5
677 kernel  kernel  1       5
678 sshd    sshd    1       5
679 su      su      1       5
680 syslogd syslogd 1       5
681 CROND   Cron Daemon     1       5
682 gnucomo Gnucomo Daemon  1       5
683 sendmail        Mail Transport Agent    1       5
684 dhcpd   DHCP Daemon     1       5
685 rpc     NFS Services    1       5
686 named   DNS Services    1       5
687 xinetd  Internet Daemon 1       5
688 ipop    Post Office Protocol    1       5
689 mgetty  Serial port login and fax       1       5
690 login   User login      1       5
691 pam     Authentication modules  1       5
692 modprobe        Kernel modules  1       5
693 \.
694
695 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
696
697 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
698
699 --
700
701 CREATE TABLE "status"
702 (
703         "statuscode" character varying(3),
704         "statusname" text,
705         "open_notification" boolean,
706         "description" text
707 );
708
709
710 COPY "status" FROM stdin;
711 new     new entry       t       Just detected, but nothing has been done yet
712 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
713 pen     pending t       The notification is currently being worked on.
714 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
715 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
716 cls     closed  f       The notification has been closed
717 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
718 \.
719
720 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
721
722 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
723
724 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
725
726 --
727 --
728
729 CREATE TABLE supported_os
730 (
731     os_name text,
732     remarks text
733 );
734
735 CREATE UNIQUE INDEX spp_os ON supported_os (os_name);
736
737 --
738 --
739
740 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
741
742 CREATE TABLE "type_of_issue"
743 (
744         "type_of_issueid" bigint DEFAULT
745            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
746         "name" text,
747         "suggested_priority" text,
748         "description" text,
749         "active" boolean,
750         automated_check       boolean,
751         alert_level           int,
752         last_run              timestamp,
753         recheck_interval      timestamp
754 );
755
756
757 COPY "type_of_issue" FROM stdin;
758 1       manual entry    4       A manual entry of a notification        t
759 2       parameter created       3       A new parameter was created     t
760 3       property modified       3       The STATIC property of a parameter was modified t
761 4       parameter removed       3       A parameter was removed t
762 5       service unknown 5       Service in log entry is unknown t
763 6       service not used        5       Service in log entry is not used        t
764 \.
765
766 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
767
768 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
769
770 CREATE INDEX toi_active ON type_of_issue USING btree (active);
771
772 SELECT setval ('"type_of_issue_type_of_issue_seq"', 6, true);
773
774 --
775 --
776
777 CREATE TABLE "usr"
778 (
779         "username" text NOT NULL,
780         "active_sessionid" bigint,
781         "account_active" boolean,
782         "security_level" integer,
783         display_name     text,
784         email            text
785 );
786
787 CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
788
789 CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
790
791 CREATE INDEX usr_account_active ON usr USING btree (account_active);
792
793 CREATE INDEX usr_security_level ON usr USING btree (security_level);
794
795 --
796 --  Set up user groups and grant permissions in the proper places.
797
798 CREATE GROUP view;
799 CREATE GROUP ops;
800 CREATE GROUP admin;
801
802 GRANT SELECT ON action TO GROUP view, GROUP ops, GROUP admin;
803 GRANT SELECT ON action_user TO GROUP view, GROUP ops, GROUP admin;
804 GRANT SELECT ON db_value TO GROUP view, GROUP ops, GROUP admin;
805 GRANT SELECT ON history TO GROUP view, GROUP ops, GROUP admin;
806 GRANT SELECT ON log TO GROUP view, GROUP ops, GROUP admin;
807 GRANT SELECT ON log_adv TO GROUP view, GROUP ops, GROUP admin;
808 GRANT SELECT ON log_adv_daemon TO GROUP view, GROUP ops, GROUP admin;
809 GRANT SELECT ON log_adv_kernel_network TO GROUP view, GROUP ops, GROUP admin;
810 GRANT SELECT ON log_notification TO GROUP view, GROUP ops, GROUP admin;
811 GRANT SELECT ON notification TO GROUP view, GROUP ops, GROUP admin;
812 GRANT SELECT ON object TO GROUP view, GROUP ops, GROUP admin;
813 GRANT SELECT ON object_issue TO GROUP view, GROUP ops, GROUP admin;
814 GRANT SELECT ON object_priority TO GROUP view, GROUP ops, GROUP admin;
815 GRANT SELECT ON object_service TO GROUP view, GROUP ops, GROUP admin;
816 GRANT SELECT ON object_user TO GROUP view, GROUP ops, GROUP admin;
817 GRANT SELECT ON parameter TO GROUP view, GROUP ops, GROUP admin;
818 GRANT SELECT ON parameter_class TO GROUP view, GROUP ops, GROUP admin;
819 GRANT SELECT ON parameter_notification TO GROUP view, GROUP ops, GROUP admin;
820 GRANT SELECT ON priority TO GROUP view, GROUP ops, GROUP admin;
821 GRANT SELECT ON property TO GROUP view, GROUP ops, GROUP admin;
822 GRANT SELECT ON service TO GROUP view, GROUP ops, GROUP admin;
823 GRANT SELECT ON status TO GROUP view, GROUP ops, GROUP admin;
824 GRANT SELECT ON supported_os TO GROUP view, GROUP ops, GROUP admin;
825 GRANT SELECT ON type_of_issue TO GROUP view, GROUP ops, GROUP admin;
826 GRANT SELECT ON usr TO GROUP view, GROUP ops, GROUP admin;
827
828 GRANT INSERT ON action_user TO GROUP ops, GROUP admin;
829 GRANT UPDATE ON notification TO GROUP ops, GROUP admin;
830 GRANT INSERT ON object TO GROUP admin;
831 GRANT UPDATE ON object TO GROUP ops, GROUP admin;
832 GRANT DELETE ON object TO GROUP admin;
833 GRANT UPDATE ON usr TO GROUP view, GROUP ops, GROUP admin;
834 GRANT INSERT ON usr TO GROUP admin;
835 GRANT DELETE ON usr TO GROUP admin;