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