Added index to the history table.
[gnucomo.git] / src / database / create.sql
index dc66c84..1c3ba8d 100644 (file)
 -- DBA create the database and give access permissions.
 --
 --  $Log: create.sql,v $
---  Revision 1.5  2003-01-18 08:46:48  arjen
+--  Revision 1.15  2003-08-05 07:43:24  arjen
+--  Added index to the history table.
+--
+--  Revision 1.14  2003/07/09 07:14:59  arjen
+--  New database tables: notification_check, notification_check_buffer,
+--  notification_check_line and object_statistics.
+--
+--  Revision 1.13  2003/03/29 08:27:05  arjen
+--  New columns in the table 'log_adv_daemon_email': size, pri, relay,
+--  status_details and dsn.
+--  Added several indices for the table 'log_adv_daemon_email'.
+--
+--  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.
 --
@@ -30,25 +68,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      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.
+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);
@@ -103,9 +143,10 @@ CREATE TABLE "db_value"
 
 
 COPY "db_value" FROM stdin;
-db_version     20
-gcm_daemon_version     1
+db_version     41
+gcm_daemon_version     5
 log_processing 0
+last_notification      0
 \.
 
 --
@@ -122,6 +163,8 @@ CREATE TABLE "history"
 
 );
 
+CREATE INDEX history_pid_mod  ON history(paramid, modified);
+
 --
 --
 
@@ -208,6 +251,40 @@ CREATE TABLE log_adv_kernel_network
        df                boolean
 ) INHERITS (log_adv);
 
+CREATE TABLE log_adv_daemon
+(
+       service TEXT,
+       event   TEXT
+) INHERITS (log_adv);
+
+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,
+     size                 INT,
+     pri                  INT,
+     relay                TEXT,
+     status_details       TEXT,
+     dsn                  TEXT
+) INHERITS (log_adv_daemon);
+
+CREATE INDEX log_adv_daemon_email_s_ip ON log_adv_daemon_email (source_ip);
+CREATE INDEX log_adv_daemon_email_d_ip ON log_adv_daemon_email (destination_ip);
+CREATE INDEX log_adv_daemon_email_to   ON log_adv_daemon_email (to_email);
+CREATE INDEX log_adv_daemon_email_from ON log_adv_daemon_email (from_email);
+CREATE INDEX log_adv_email_status      ON log_adv_daemon_email (status);
+
 
 /*
 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
@@ -287,6 +364,73 @@ SELECT setval ('"notification_notificationid_seq"', 1, false);
 --
 --
 
+CREATE SEQUENCE checkid_seq;
+    
+CREATE TABLE notification_check
+(
+     checkid                 bigint DEFAULT nextval('checkid_seq'::text) NOT NULL,
+     checkname               TEXT,
+     description             TEXT,
+     time_between_executions INTERVAL, 
+     last_execution          DATETIME,
+     execution_counter       BIGINT,
+     notificationcounter     BIGINT,
+     decreasinglist          BOOLEAN default false,
+     type_of_issueid         BIGINT
+);
+
+CREATE UNIQUE INDEX not_check_checkid ON notification_check (checkid);
+
+CREATE UNIQUE INDEX not_check_checkname ON notification_check (checkname);
+
+CREATE INDEX not_check_check_lastexec ON notification_check (last_execution);
+
+--
+--
+
+CREATE TABLE notification_check_buffer
+(
+    checkid     BIGINT,
+    sortorder   INTEGER,
+    pid         INTEGER,
+    logid       bigint
+);
+
+CREATE INDEX notcheckbuffer_checkid ON notification_check_buffer(checkid);
+     
+CREATE INDEX notcheckbuffer_sort ON notification_check_buffer(sortorder);
+
+CREATE INDEX notcheckbuffer_pid ON notification_check_buffer(pid);
+     
+CREATE INDEX notcheckbuffer_logid ON notification_check_buffer(logid);
+
+--
+--
+
+CREATE SEQUENCE checklineid_seq;
+     
+CREATE TABLE notification_check_line
+(
+    checklineid             BIGINT DEFAULT nextval('checklineid_seq'::text) NOT NULL,
+    checkid                 BIGINT,
+    sortorder               INTEGER,
+    last_logid              BIGINT default 0,
+    historicboundary        INTERVAL default 0,
+    use_logid               BOOLEAN default false,
+    sql_query               TEXT
+);
+     
+CREATE UNIQUE INDEX notcheckline_checklineid ON notification_check_line (checklineid);
+
+CREATE INDEX notcheckline_checkid            ON notification_check_line (checkid);
+
+CREATE INDEX notcheckline_sort               ON notification_check_line (sortorder);
+
+CREATE INDEX notcheckline_check_sort         ON notification_check_line (checkid, sortorder);
+
+--
+--
+
 CREATE SEQUENCE "object_objectid_seq";
 
 CREATE TABLE "object"
@@ -308,7 +452,10 @@ CREATE TABLE "object"
        "timezone" text,
        "remark" text,
         "os"     text,
-        "os_version"   text
+        "os_version"   text,
+        "log_count"    bigint,
+        "notification_count"   bigint,
+        "parameter_count"      bigint
 );
 
 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
@@ -390,6 +537,20 @@ CREATE INDEX obs_accepted ON object_service USING btree (accepted);
 --
 --
 
+CREATE TABLE object_statistics
+(
+    objectid       bigint,
+    statname       text,
+    statvalue      double precision,
+
+    primary key (objectid, statname)
+);
+
+CREATE INDEX obj_stat_objid ON object_statistics USING btree (objectid);
+
+--
+--
+
 CREATE TABLE "object_user"
 (
        "objectid" bigint,
@@ -428,6 +589,36 @@ SELECT setval ('"paramid_seq"', 1, true);
 --
 --
 
+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)
+);
+
+--
+--
+
 CREATE TABLE "priority"
 (
        "priority" integer,
@@ -542,7 +733,7 @@ CREATE TABLE "type_of_issue"
 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
+3      property modified       3       The STATIC property of a parameter was modified t
 4      parameter removed       3       A parameter was removed t
 \.
 
@@ -573,3 +764,44 @@ 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;