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