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