992f656ec3314ffaa68e821345b66f09481e1f90
[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.6  2003-01-20 07:29:48  arjen
16 --  Added new tables to the database: parameter_class and parameter_notification
17 --
18 --  Revision 1.5  2003/01/18 08:46:48  arjen
19 --  Added new records to the 'type_of_issue' table.
20 --  Changed semantics of actionid 9 in the 'action' table.
21 --
22 --
23
24 CREATE SEQUENCE "action_actionid_seq";
25
26 CREATE TABLE "action"
27 (
28         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
29         "actionname" text,
30         "statuscode" character varying(3),
31         "description" text
32 );
33
34
35 COPY "action" FROM stdin;
36 1       Entry in the system     NEW     This indicates that a notification has been entered into the system.
37 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
38 3       Remarks added   PEN     Remarks have been added to the notification.
39 4       Priority changed manually       PEN     The priority of the notification has been changed by the user.
40 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.
41 6       Action taken    PEN     An action has been taken.
42 7       Assignment to user      PEN     The notification has been assigned to an user.
43 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.
44 9       Investigation completed PEN     Investigation has been done. Information is available to fix the problem.
45 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.
46 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.
47 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.
48 13      Action verified CLS     A check has been done and the results were approved. The notification has been closed.
49 15      SMS sent        OPN     An SMS has been sent.
50 14      E-mail sent     OPN     An e-mail has been sent.
51 16      Fax sent        OPN     An fax has been sent.
52 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
53 18      Notification closed     CLS     The notification has been closed.
54 19      Notification reopend    OPN     The notification has been reopend.
55 \.
56
57 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
58
59 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
60
61 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
62
63 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
64
65 SELECT setval ('"action_actionid_seq"', 19, true);
66
67 --
68 --
69
70 CREATE SEQUENCE "action_user_actionstepid_seq";
71
72 CREATE TABLE "action_user"
73 (
74         "actionstepid" bigint DEFAULT
75             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
76         "actionid" bigint,
77         "username" text,
78         "notificationid" bigint,
79         "timestamp" timestamp with time zone,
80         "statuscode" character varying(3),
81         "remarks" text
82 );
83
84 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
85
86 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
87
88 CREATE INDEX anu_username ON action_user USING btree (username);
89
90 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
91
92 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
93
94 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
95
96 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
97
98 --
99 --
100
101 CREATE TABLE "db_value"
102 (
103         "setting" text,
104         "setting_value" text
105 );
106
107
108 COPY "db_value" FROM stdin;
109 db_version      21
110 gcm_daemon_version      1
111 log_processing  0
112 \.
113
114 --
115 --
116
117 CREATE TABLE "history"
118 (
119    paramid            bigint,
120    modified           timestamp,
121    change_nature      text,       --  CREATED, MODIFIED or REMOVED
122    changed_property   text,
123    new_value          text,
124    remark             text
125
126 );
127
128 --
129 --
130
131 CREATE SEQUENCE "log_logid_seq";
132
133 CREATE TABLE "log"
134 (
135         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
136         "objectid" bigint,
137         "original_filename" text,
138         "servicecode" text,
139         "object_timestamp" timestamp with time zone,
140         "timestamp" timestamp with time zone,
141         "rawdata" text,
142         "processed" boolean DEFAULT false,
143         "recognized" boolean DEFAULT false
144 );
145
146 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
147
148 CREATE INDEX log_objectid ON log USING btree (objectid);
149
150 CREATE INDEX log_original_filename ON log USING btree (original_filename);
151
152 CREATE INDEX log_servicecode ON log USING btree (servicecode);
153
154 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
155
156 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
157
158 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
159
160 CREATE INDEX log_processed ON log USING btree (processed);
161
162 SELECT setval ('"log_logid_seq"', 1, false);
163
164
165 --
166 --
167
168 CREATE SEQUENCE "log_advid_seq";
169
170
171 CREATE TABLE "log_adv"
172 (
173         "log_advid" bigint DEFAULT
174               nextval('"log_advid_seq"'::text) NOT NULL,
175         "logid" bigint NOT NULL,
176         "detailed_table"    text
177 );
178
179
180 CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
181
182 CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
183
184 SELECT setval ('"log_advid_seq"', 1, false);
185
186 CREATE TABLE log_adv_kernel_network
187 (
188        device_in         text,
189        device_out        text,
190        hw_address        text, 
191        source_ip         INET,
192        destination_ip    INET,
193        packet_length     bigint, 
194        tos_bit           text, 
195        prec_bit          text,
196        ttl               int,
197        header_id         bigint,
198        source_port       int, 
199        destination_port  int,
200        body_length       int,
201        protocol          text, 
202        body_len          int,
203        window            text,
204        urgp              int,
205        syn               boolean DEFAULT false,
206        type              int,
207        code              int,
208        sequence_number   int,
209        res               text,
210        rst               boolean,
211        df                boolean
212 ) INHERITS (log_adv);
213
214
215 /*
216 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
217 CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
218 -- Initial date: September 18th 2002
219 -- Update: November 13th 2002
220 -- Author: Brenno J.S.A.A.F. de Winter
221 -- Abstract: This routine sets a flag
222 DECLARE
223    var_value    VARCHAR;
224    var_setting  VARCHAR;
225
226 BEGIN
227
228     UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
229     RETURN NULL;
230 END;
231  ' LANGUAGE 'plpgsql';
232
233
234 CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
235 */
236 --
237 --
238
239 CREATE TABLE "log_notification"
240 (
241         "notificationid" bigint,
242         "logid" bigint
243 );
244
245 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
246
247 CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
248
249 CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
250
251 --
252 --
253
254 CREATE SEQUENCE "notification_notificationid_seq";
255
256 CREATE TABLE "notification"
257 (
258         "notificationid" bigint DEFAULT
259             nextval('"notification_notificationid_seq"'::text) NOT NULL,
260         "objectid" bigint,
261         "type_of_issueid" bigint,
262         "timestamp" timestamp with time zone,
263         "statuscode" character varying(3),
264         "priority" integer,
265         "escalation_count_timestamp" timestamp with time zone,
266         "repeat_notification_timestamp" timestamp with time zone,
267         "securitylevel_view" integer,
268         "securitylevel_add" integer,
269         "securitylevel_close" integer
270 );
271
272 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
273
274 CREATE INDEX not_objectid ON notification USING btree (objectid);
275
276 CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
277
278 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
279
280 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
281
282 CREATE INDEX not_priority ON notification USING btree (priority);
283
284 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
285
286 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
287
288 SELECT setval ('"notification_notificationid_seq"', 1, false);
289
290 --
291 --
292
293 CREATE SEQUENCE "object_objectid_seq";
294
295 CREATE TABLE "object"
296 (
297         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
298         "objectname" text,
299         "objectcode" text,
300         "scp_enabled" boolean,
301         "scp_inet" inet,
302         "mail_enabled" boolean,
303         "mail_from" text,
304         "sms_enabled" boolean,
305         "sms_number" text,
306         "fax_enabled" boolean,
307         "fax_number" text,
308         "object_description" text,
309         "object_owner" text,
310         "physical_location" text,
311         "timezone" text,
312         "remark" text,
313         "os"     text,
314         "os_version"   text
315 );
316
317 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
318
319 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
320
321 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
322
323 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
324
325 CREATE INDEX os ON object (os);
326
327 CREATE INDEX os_version ON object (os, os_version);
328
329 SELECT setval ('"object_objectid_seq"', 1, false);
330
331 --
332 --
333
334 CREATE TABLE "object_issue"
335 (
336         "objectid" bigint,
337         "type_of_issueid" bigint,
338         "default_priority" integer,
339         "escalation" boolean,
340         "escalation_time" time without time zone,
341         "max_priority" integer,
342         "adjust_setting" text
343 );
344
345 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
346
347 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
348
349 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
350
351 --
352 --
353
354 CREATE TABLE "object_priority"
355 (
356         "objectid" bigint,
357         "priorityid" integer,
358         "send_mail" boolean,
359         "send_sms" boolean,
360         "send_fax" boolean,
361         "repeat_notification" boolean,
362         "interval_for_repeat" time without time zone
363 );
364
365 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
366
367 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
368
369 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
370
371 --
372 --
373
374 CREATE TABLE "object_service"
375 (
376         "objectid" bigint,
377         "servicecode" text,
378         "expected_interval" bigint,
379         "last_entry" timestamp with time zone,
380         "default_priority" integer,
381         "maximum_priority" integer,
382         "accepted" boolean
383 );
384
385 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
386
387 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
388
389 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
390
391 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
392
393 --
394 --
395
396 CREATE TABLE "object_user"
397 (
398         "objectid" bigint,
399         "username" text,
400         "security_level" integer
401 );
402
403 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
404
405 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
406
407 CREATE INDEX ous_username ON object_user USING btree (username);
408
409 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
410
411 --
412 --
413
414 CREATE SEQUENCE "paramid_seq";
415
416 CREATE TABLE "parameter"
417 (
418         "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
419         "objectid" bigint,
420         "name" text,
421         "class" text,
422         "description" text,
423
424         primary key (paramid)
425 );
426
427 CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
428
429 SELECT setval ('"paramid_seq"', 1, true);
430
431 --
432 --
433
434 CREATE TABLE "parameter_class"
435 (
436    "name"             text,     --  Name of the class: see parameter.class
437    "property_name"    text,
438    "description"      text,
439    "property_type"    text,     --  STATIC or DYNAMIC
440    "min"              float,    --  Default minimum value
441    "max"              float,    --  Default maximum value
442    "notify"           boolean,  --  Notify if something changes ?
443
444    primary key (name, property_name)
445 );
446
447 INSERT INTO parameter_class (name, property_name, description, property_type, notify)
448   VALUES ('package', 'version', 'The installed version of the package', 'STATIC', 't');
449
450 --
451 --
452
453 CREATE TABLE "parameter_notification"
454 (
455    "notificationid" bigint,
456    "paramid"        bigint,
457
458    primary key (notificationid, paramid)
459 );
460
461 --
462 --
463
464 CREATE TABLE "priority"
465 (
466         "priority" integer,
467         "send_mail" boolean,
468         "send_sms" boolean,
469         "send_fax" boolean,
470         "repeat_notification" boolean,
471         "interval_for_repeat" time without time zone
472 );
473
474
475 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
476
477 --
478 --
479
480 CREATE TABLE "property"
481 (
482    paramid bigint,
483    name    text,
484    value   text,
485    type    text,   --   STATIC or DYNAMIC
486    min     float,
487    max     float,
488
489    primary key (paramid, name)
490 );
491
492 --
493 --
494
495 CREATE TABLE "service"
496 (
497         "servicecode" text,
498         "servicename" text,
499         "default_priority" integer,
500         "max_priority" integer
501 );
502
503 COPY "service" FROM stdin;
504 httpd   httpd   1       5
505 imap    imap    1       5
506 imapd   imapd   1       5
507 kernel  kernel  1       5
508 sshd    sshd    1       5
509 su      su      1       5
510 syslogd syslogd 1       5
511 \.
512
513 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
514
515 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
516
517 --
518
519 CREATE TABLE "status"
520 (
521         "statuscode" character varying(3),
522         "statusname" text,
523         "open_notification" boolean,
524         "description" text
525 );
526
527
528 COPY "status" FROM stdin;
529 new     new entry       t       Just detected, but nothing has been done yet
530 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
531 pen     pending t       The notification is currently being worked on.
532 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
533 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
534 cls     closed  f       The notification has been closed
535 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
536 \.
537
538 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
539
540 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
541
542 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
543
544 --
545 --
546
547 CREATE TABLE supported_os
548 (
549     os_name text,
550     remarks text
551 );
552
553 CREATE UNIQUE INDEX spp_os ON supported_os (os_name);
554
555 --
556 --
557
558 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
559
560 CREATE TABLE "type_of_issue"
561 (
562         "type_of_issueid" bigint DEFAULT
563            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
564         "name" text,
565         "suggested_priority" text,
566         "description" text,
567         "active" boolean,
568         automated_check       boolean,
569         alert_level           int,
570         last_run              timestamp,
571         recheck_interval      timestamp
572 );
573
574
575 COPY "type_of_issue" FROM stdin;
576 1       manual entry    4       A manual entry of a notification        t
577 2       parameter created       3       A new parameter was created     t
578 3       property modified       3       The STATIC property of a parameter was modified t
579 4       parameter removed       3       A parameter was removed t
580 \.
581
582 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
583
584 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
585
586 CREATE INDEX toi_active ON type_of_issue USING btree (active);
587
588 SELECT setval ('"type_of_issue_type_of_issue_seq"', 4, true);
589
590 --
591 --
592
593 CREATE TABLE "usr"
594 (
595         "username" text NOT NULL,
596         "active_sessionid" bigint,
597         "account_active" boolean,
598         "security_level" integer
599 );
600
601 CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
602
603 CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
604
605 CREATE INDEX usr_account_active ON usr USING btree (account_active);
606
607 CREATE INDEX usr_security_level ON usr USING btree (security_level);
608