Added new table to the database: log_adv_daemon_email.
[gnucomo.git] / src / database / create.sql
index 95ea41e..21d0ef6 100644 (file)
 -- Before running this script with 'psql -f', you should have your
 -- DBA create the database and give access permissions.
 --
+--  $Log: create.sql,v $
+--  Revision 1.12  2003-02-21 08:38:38  arjen
+--  Added new table to the database: log_adv_daemon_email.
+--
+--  Revision 1.11  2003/02/16 08:24:38  arjen
+--  Added a new entry to the action table: Notification was displayed in the listing
+--
+--  Revision 1.10  2003/02/14 06:32:27  arjen
+--  Setup the groups and database permissions. The three groups
+--  are: view, ops and admin.
+--  Added a new entry to the action table.
+--
+--  Revision 1.9  2003/02/13 08:46:54  arjen
+--  Added log, notification and parameter counters to the 'object' table.
+--  Counting these things at the time a user interface needs them is
+--  too slow. Other programs, like gcm_daemon en gcm_input should prepare
+--  these counters for quick retrieval.
+--
+--  Revision 1.8  2003/02/08 07:36:41  arjen
+--  Added new table to the database : log_adv_daemon
+--
+--  Revision 1.7  2003/02/05 09:29:08  arjen
+--  Bug fix: action.statuscode was in upper case.
+--
+--  Revision 1.6  2003/01/20 07:29:48  arjen
+--  Added new tables to the database: parameter_class and parameter_notification
+--
+--  Revision 1.5  2003/01/18 08:46:48  arjen
+--  Added new records to the 'type_of_issue' table.
+--  Changed semantics of actionid 9 in the 'action' table.
+--
 --
 
 CREATE SEQUENCE "action_actionid_seq";
@@ -25,25 +56,27 @@ CREATE TABLE "action"
 
 
 COPY "action" FROM stdin;
-1      Entry in the system     NEW     This indicates that a notification has been entered into the system.
-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
-3      Remarks added   PEN     Remarks have been added to the notification.
-4      Priority changed manually       PEN     The priority of the notification has been changed by the user.
-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.
-6      Action taken    PEN     An action has been taken.
-7      Assignment to user      PEN     The notification has been assigned to an user.
-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.
-9      Make output reference   REF     The automated output from an object was sent to gnucomo. The input has been identified as a valid reference for the future. For that reason the status is now REFERENCE
-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.
-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.
-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.
-13     Action verified CLS     A check has been done and the results were approved. The notification has been closed.
-15     SMS sent        OPN     An SMS has been sent.
-14     E-mail sent     OPN     An e-mail has been sent.
-16     Fax sent        OPN     An fax has been sent.
+1      Entry in the system     new     This indicates that a notification has been entered into the system.
+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
+3      Remarks added   pen     Remarks have been added to the notification.
+4      Priority changed manually       pen     The priority of the notification has been changed by the user.
+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.
+6      Action taken    pen     An action has been taken.
+7      Assignment to user      pen     The notification has been assigned to an user.
+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.
+9      Investigation completed pen     Investigation has been done. Information is available to fix the problem.
+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.
+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.
+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.
+13     Action verified cls     A check has been done and the results were approved. The notification has been closed.
+15     SMS sent        opn     An SMS has been sent.
+14     E-mail sent     opn     An e-mail has been sent.
+16     Fax sent        opn     An fax has been sent.
 17     Log entries shown       \N      The log entries relevant to the notification have been shown.
-18     Notification closed     CLS     The notification has been closed.
-19     Notification reopend    OPN     The notification has been reopend.
+18     Notification closed     cls     The notification has been closed.
+19     Notification reopend    opn     The notification has been reopend.
+20     Redisplayed to user     \N      The notification has been presented to a user. This is not the first time
+21     Displayed in list       \N      The notification has been presented in a list with other notifications.
 \.
 
 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
@@ -90,6 +123,37 @@ SELECT setval ('"action_user_actionstepid_seq"', 1, false);
 --
 --
 
+CREATE TABLE "db_value"
+(
+       "setting" text,
+       "setting_value" text
+);
+
+
+COPY "db_value" FROM stdin;
+db_version     32
+gcm_daemon_version     1
+log_processing 0
+last_notification      0
+\.
+
+--
+--
+
+CREATE TABLE "history"
+(
+   paramid            bigint,
+   modified           timestamp,
+   change_nature      text,       --  CREATED, MODIFIED or REMOVED
+   changed_property   text,
+   new_value          text,
+   remark             text
+
+);
+
+--
+--
+
 CREATE SEQUENCE "log_logid_seq";
 
 CREATE TABLE "log"
@@ -100,7 +164,9 @@ CREATE TABLE "log"
        "servicecode" text,
        "object_timestamp" timestamp with time zone,
        "timestamp" timestamp with time zone,
-       "rawdata" text
+       "rawdata" text,
+       "processed" boolean DEFAULT false,
+        "recognized" boolean DEFAULT false
 );
 
 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
@@ -117,48 +183,104 @@ CREATE INDEX log_timestmap ON log USING btree ("timestamp");
 
 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
 
+CREATE INDEX log_processed ON log USING btree (processed);
+
 SELECT setval ('"log_logid_seq"', 1, false);
 
+
 --
 --
 
+CREATE SEQUENCE "log_advid_seq";
+
+
 CREATE TABLE "log_adv"
 (
-       "logid" bigint,
-       "source_ip" inet,
-       "destination_ip" inet,
-       "mac_address" macaddr,
-       "packetlength" integer,
-       "protocol" text,
-       "source_port" integer,
-       "destination_port" integer,
-       "messageid" text,
-       "system_username" text,
-       "networkdevice" text
+       "log_advid" bigint DEFAULT
+              nextval('"log_advid_seq"'::text) NOT NULL,
+       "logid" bigint NOT NULL,
+       "detailed_table"    text
 );
 
-CREATE INDEX loa_logid ON log_adv USING btree (logid);
-
-CREATE INDEX loa_source_ip ON log_adv USING btree (source_ip);
-
-CREATE INDEX loa_destination_ip ON log_adv USING btree (destination_ip);
-
-CREATE INDEX loa_mac_address ON log_adv USING btree (mac_address);
-
-CREATE INDEX loa_packetlength ON log_adv USING btree (packetlength);
 
-CREATE INDEX loa_protocol ON log_adv USING btree (protocol);
+CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
 
-CREATE INDEX loa_source_port ON log_adv USING btree (source_port);
+CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
 
-CREATE INDEX loa_destination_port ON log_adv USING btree (destination_port);
+SELECT setval ('"log_advid_seq"', 1, false);
 
-CREATE INDEX loa_messageid ON log_adv USING btree (messageid);
-
-CREATE INDEX loa_system_username ON log_adv USING btree (system_username);
+CREATE TABLE log_adv_kernel_network
+(
+       device_in         text,
+       device_out        text,
+       hw_address        text, 
+       source_ip         INET,
+       destination_ip    INET,
+       packet_length     bigint, 
+       tos_bit           text, 
+       prec_bit          text,
+       ttl               int,
+       header_id         bigint,
+       source_port       int, 
+       destination_port  int,
+       body_length       int,
+       protocol          text, 
+       body_len          int,
+       window            text,
+       urgp              int,
+       syn               boolean DEFAULT false,
+       type              int,
+       code              int,
+       sequence_number   int,
+       res               text,
+       rst               boolean,
+       df                boolean
+) INHERITS (log_adv);
+
+CREATE TABLE log_adv_daemon
+(
+       service TEXT,
+       event   TEXT
+) INHERITS (log_adv);
 
-CREATE INDEX loa_networkdevice ON log_adv USING btree (networkdevice);
+CREATE INDEX log_adv_daemon_service ON log_adv_daemon (service);
 
+CREATE TABLE log_adv_daemon_email
+(
+     source_ip            INET,
+     destination_ip       INET,
+     internal_messageid   TEXT, 
+     external_messageid   TEXT,
+     to_email             TEXT,
+     from_email           TEXT,
+     delay                TIME,
+     xdelay               TIME,
+     mailer               TEXT,
+     status               TEXT,
+     pid                  INT
+) INHERITS (log_adv_daemon);
+
+/*
+CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
+CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
+-- Initial date: September 18th 2002
+-- Update: November 13th 2002
+-- Author: Brenno J.S.A.A.F. de Winter
+-- Abstract: This routine sets a flag
+DECLARE
+   var_value   VARCHAR;
+   var_setting VARCHAR;
+
+BEGIN
+
+    UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
+    RETURN NULL;
+END;
+ ' LANGUAGE 'plpgsql';
+
+
+CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
+*/
 --
 --
 
@@ -184,7 +306,7 @@ CREATE TABLE "notification"
        "notificationid" bigint DEFAULT
             nextval('"notification_notificationid_seq"'::text) NOT NULL,
        "objectid" bigint,
-       "type_of_notificationid" bigint,
+       "type_of_issueid" bigint,
        "timestamp" timestamp with time zone,
        "statuscode" character varying(3),
        "priority" integer,
@@ -199,7 +321,7 @@ CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree
 
 CREATE INDEX not_objectid ON notification USING btree (objectid);
 
-CREATE INDEX not_type_of_notificationid ON notification USING btree (type_of_notificationid);
+CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
 
 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
 
@@ -235,7 +357,12 @@ CREATE TABLE "object"
        "object_owner" text,
        "physical_location" text,
        "timezone" text,
-       "remark" text
+       "remark" text,
+        "os"     text,
+        "os_version"   text,
+        "log_count"    bigint,
+        "notification_count"   bigint,
+        "parameter_count"      bigint
 );
 
 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
@@ -246,6 +373,10 @@ CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
 
 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
 
+CREATE INDEX os ON object (os);
+
+CREATE INDEX os_version ON object (os, os_version);
+
 SELECT setval ('"object_objectid_seq"', 1, false);
 
 --
@@ -254,7 +385,7 @@ SELECT setval ('"object_objectid_seq"', 1, false);
 CREATE TABLE "object_issue"
 (
        "objectid" bigint,
-       "type_of_notificationid" bigint,
+       "type_of_issueid" bigint,
        "default_priority" integer,
        "escalation" boolean,
        "escalation_time" time without time zone,
@@ -262,11 +393,11 @@ CREATE TABLE "object_issue"
        "adjust_setting" text
 );
 
-CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_notificationid);
+CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
 
 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
 
-CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_notificationid);
+CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
 
 --
 --
@@ -313,37 +444,70 @@ CREATE INDEX obs_accepted ON object_service USING btree (accepted);
 --
 --
 
-CREATE TABLE "object_system_user"
+CREATE TABLE "object_user"
 (
        "objectid" bigint,
-       "system_username" text,
-       "can_login" boolean,
-       "can_be_root" boolean
+       "username" text,
+       "security_level" integer
 );
 
-CREATE UNIQUE INDEX osu_pk ON object_system_user USING btree (objectid, system_username);
+CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
+
+CREATE INDEX ous_objectid ON object_user USING btree (objectid);
 
-CREATE INDEX osu_objectid ON object_system_user USING btree (objectid);
+CREATE INDEX ous_username ON object_user USING btree (username);
 
-CREATE INDEX osu_system_username ON object_system_user USING btree (system_username);
+CREATE INDEX ous_security_level ON object_user USING btree (security_level);
 
 --
 --
 
-CREATE TABLE "object_user"
+CREATE SEQUENCE "paramid_seq";
+
+CREATE TABLE "parameter"
 (
-       "objectid" bigint,
-       "username" text,
-       "security_level" integer
+       "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
+        "objectid" bigint,
+       "name" text,
+        "class" text,
+        "description" text,
+
+        primary key (paramid)
 );
 
-CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
+CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
 
-CREATE INDEX ous_objectid ON object_user USING btree (objectid);
+SELECT setval ('"paramid_seq"', 1, true);
 
-CREATE INDEX ous_username ON object_user USING btree (username);
+--
+--
 
-CREATE INDEX ous_security_level ON object_user USING btree (security_level);
+CREATE TABLE "parameter_class"
+(
+   "name"             text,     --  Name of the class: see parameter.class
+   "property_name"    text,
+   "description"      text,
+   "property_type"    text,     --  STATIC or DYNAMIC
+   "min"              float,    --  Default minimum value
+   "max"              float,    --  Default maximum value
+   "notify"           boolean,  --  Notify if something changes ?
+
+   primary key (name, property_name)
+);
+
+INSERT INTO parameter_class (name, property_name, description, property_type, notify)
+  VALUES ('package', 'version', 'The installed version of the package', 'STATIC', 't');
+
+--
+--
+
+CREATE TABLE "parameter_notification"
+(
+   "notificationid" bigint,
+   "paramid"        bigint,
+
+   primary key (notificationid, paramid)
+);
 
 --
 --
@@ -364,6 +528,21 @@ CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
 --
 --
 
+CREATE TABLE "property"
+(
+   paramid bigint,
+   name    text,
+   value   text,
+   type    text,   --   STATIC or DYNAMIC
+   min     float,
+   max     float,
+
+   primary key (paramid, name)
+);
+
+--
+--
+
 CREATE TABLE "service"
 (
        "servicecode" text,
@@ -372,12 +551,21 @@ CREATE TABLE "service"
        "max_priority" integer
 );
 
+COPY "service" FROM stdin;
+httpd  httpd   1       5
+imap   imap    1       5
+imapd  imapd   1       5
+kernel kernel  1       5
+sshd   sshd    1       5
+su     su      1       5
+syslogd        syslogd 1       5
+\.
+
 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
 
 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
 
 --
---
 
 CREATE TABLE "status"
 (
@@ -407,6 +595,17 @@ CREATE INDEX sta_open_notification ON status USING btree (open_notification);
 --
 --
 
+CREATE TABLE supported_os
+(
+    os_name text,
+    remarks text
+);
+
+CREATE UNIQUE INDEX spp_os ON supported_os (os_name);
+
+--
+--
+
 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
 
 CREATE TABLE "type_of_issue"
@@ -416,12 +615,19 @@ CREATE TABLE "type_of_issue"
        "name" text,
        "suggested_priority" text,
        "description" text,
-       "active" boolean
+       "active" boolean,
+        automated_check       boolean,
+        alert_level           int,
+        last_run              timestamp,
+        recheck_interval      timestamp
 );
 
 
 COPY "type_of_issue" FROM stdin;
 1      manual entry    4       A manual entry of a notification        t
+2      parameter created       3       A new parameter was created     t
+3      property modified       3       The STATIC property of a parameter was modified t
+4      parameter removed       3       A parameter was removed t
 \.
 
 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
@@ -430,39 +636,65 @@ CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
 
 CREATE INDEX toi_active ON type_of_issue USING btree (active);
 
-SELECT setval ('"type_of_issue_type_of_issue_seq"', 1, true);
-
---
---
-
-CREATE SEQUENCE "unprocessed_l_unprocessedid_seq";
-
-CREATE TABLE "unprocessed_log"
-(
-       "unprocessedid" bigint DEFAULT
-           nextval('"unprocessed_l_unprocessedid_seq"'::text) NOT NULL,
-       "objectid" bigint,
-       "servicecode" text
-);
-
-CREATE UNIQUE INDEX unprocessed_l_unprocessedid_key ON unprocessed_log USING btree (unprocessedid);
-
-SELECT setval ('"unprocessed_l_unprocessedid_seq"', 1, false);
+SELECT setval ('"type_of_issue_type_of_issue_seq"', 4, true);
 
 --
 --
 
-CREATE TABLE "user_gnucomo"
+CREATE TABLE "usr"
 (
-       "username" text,
-       "password" text,
+       "username" text NOT NULL,
        "active_sessionid" bigint,
        "account_active" boolean,
        "security_level" integer
 );
 
-CREATE UNIQUE INDEX usr_pk ON user_gnucomo USING btree (username);
-
-CREATE INDEX usr_active_sessionid ON user_gnucomo USING btree (active_sessionid);
-
-
+CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
+
+CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
+
+CREATE INDEX usr_account_active ON usr USING btree (account_active);
+
+CREATE INDEX usr_security_level ON usr USING btree (security_level);
+
+--
+--  Set up user groups and grant permissions in the proper places.
+
+CREATE GROUP view;
+CREATE GROUP ops;
+CREATE GROUP admin;
+
+GRANT SELECT ON action TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON action_user TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON db_value TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON history TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON log TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON log_adv TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON log_adv_daemon TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON log_adv_kernel_network TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON log_notification TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON notification TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON object TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON object_issue TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON object_priority TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON object_service TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON object_user TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON parameter TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON parameter_class TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON parameter_notification TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON priority TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON property TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON service TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON status TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON supported_os TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON type_of_issue TO GROUP view, GROUP ops, GROUP admin;
+GRANT SELECT ON usr TO GROUP view, GROUP ops, GROUP admin;
+
+GRANT INSERT ON action_user TO GROUP ops, GROUP admin;
+GRANT UPDATE ON notification TO GROUP ops, GROUP admin;
+GRANT INSERT ON object GROUP admin;
+GRANT UPDATE ON object TO GROUP ops, GROUP admin;
+GRANT DELETE ON object GROUP admin;
+GRANT UPDATE ON usr TO GROUP view, GROUP ops, GROUP admin;
+GRANT INSERT ON usr TO GROUP admin;
+GRANT DELETE ON usr TO GROUP admin;