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