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