Make an extra index on the log_abuse table
[gnucomo.git] / src / gcm_daemon / classes / gnucomo_db_version.php
index a83930a..d84a3e5 100644 (file)
@@ -14,7 +14,7 @@
    {
      case 1:
        //DROP the rule that prohibits updates (change of spec).
-       $local_sql = "DROP RULE log_update";
+       $local_sql = "DROP RULE log_update ON log";
        $dbms->query($local_sql); //DISABLED FOR NEW ROLE LOG-tABLE  ???
 
      case 2:
@@ -339,7 +339,7 @@ case 36:
      $local_sql  = "CREATE TABLE notification_check (";
      $local_sql .= "checkid bigint DEFAULT nextval('checkid_seq'::text) NOT NULL,";
      $local_sql .= "checkname TEXT, description TEXT, time_between_executions INTERVAL, ";
-     $local_sql .= "last_execution DATETIME, execution_counter BIGINT,";
+     $local_sql .= "last_execution timestamp, execution_counter BIGINT,";
      $local_sql .= "notificationcounter BIGINT)";
      $dbms->query($local_sql);
 
@@ -486,14 +486,200 @@ case 42:
      $local_sql = "INSERT INTO service VALUES ('modprobe','Kernel modules', 1, 5) ";
      $dbms->query($local_sql);
 
+case 43:
+
+     //  We need to change the type of the 'delay' and 'xdelay' fields in
+     //  the 'log_adv_daemon_email' table from type time to type interval.
+     //  This can not be done directly; it requires recreating the entire
+     //  table and copying data from the old table.
+
+     $local_sql = "ALTER TABLE log_adv_daemon_email RENAME TO old_table";
+     $dbms->query($local_sql);
+
+     $local_sql = "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                interval,
+                      xdelay               interval,
+                      mailer               TEXT,
+                      status               TEXT,
+                      pid                  INT,
+                      size                 INT,
+                      pri                  INT,
+                      relay                TEXT,
+                      status_details       TEXT,
+                      dsn                  TEXT
+                 ) INHERITS (log_adv_daemon)";
+     $dbms->query($local_sql);
+
+     $local_sql = "INSERT INTO log_adv_daemon_email SELECT * FROM old_table";
+     $dbms->query($local_sql);
+
+     $local_sql = "DROP TABLE old_table";
+     $dbms->query($local_sql);
+
+     // The indices need to be recreated as well.
+
+     $local_sql = "CREATE INDEX log_adv_daemon_email_s_ip ON log_adv_daemon_email (source_ip)";
+     $dbms->query($local_sql);
+
+     $local_sql = "CREATE INDEX log_adv_daemon_email_d_ip ON log_adv_daemon_email (destination_ip)";
+     $dbms->query($local_sql);
+
+     $local_sql = "CREATE INDEX log_adv_daemon_email_to   ON log_adv_daemon_email (to_email)";
+     $dbms->query($local_sql);
+
+     $local_sql = "CREATE INDEX log_adv_daemon_email_from ON log_adv_daemon_email (from_email)";
+     $dbms->query($local_sql);
+
+     $local_sql = "CREATE INDEX log_adv_email_status      ON log_adv_daemon_email (status)";
+     $dbms->query($local_sql);
+
+   case 44:
+
+     $local_sql = "CREATE TABLE object_abuse
+                   (
+                           objectid   bigint,
+                           source     inet,
+                           nr_abuses  integer,
+                           status     text,
+
+                           primary key (objectid, source)
+                   );";
+     $dbms->query($local_sql);
+     $dbms->query("GRANT SELECT ON log_adv_daemon_email TO GROUP view, GROUP ops, GROUP admin");
+     $dbms->query("GRANT SELECT ON object_abuse TO GROUP view, GROUP ops, GROUP admin");
+     $dbms->query("GRANT INSERT ON object_abuse TO GROUP admin");
+     $dbms->query("GRANT UPDATE ON object_abuse TO GROUP ops, GROUP admin");
+     $dbms->query("GRANT DELETE ON object_abuse TO GROUP admin");
+     $dbms->query("GRANT SELECT ON object_statistics TO GROUP view, GROUP ops, GROUP admin");
+
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('abuses exceeded',5,'Abuse treshold exceeded from an IP address', true) ";
+     $dbms->query($local_sql);
+
+   case 45:
+
+     $local_sql = "CREATE TABLE service_pattern
+                   (
+                         service   text,
+                         rank      int,
+                         pattern   text,
+                         action    text,
+                         argument  text,
+
+                         primary key (service, rank)
+                   )";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO service_pattern VALUES ('ANY', 999999, '.+', 'notify', 'unmatched log')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('unmatched log',5,'Log entries could not be matched', true) ";
+     $dbms->query($local_sql);
+
+   case 46:
+
+     $local_sql = "CREATE TABLE log_abuse
+                   (
+                           logid      bigint,
+                          objectid   bigint,
+                           source     inet
+                   )";
+     $dbms->query($local_sql);
+
+   case 47:
+
+     $local_sql = "INSERT INTO service_pattern VALUES ('ANY', 999990, '[Ee][Rr][Rr][Oo][Rr]', 'notify', 'Error detected')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('Error detected',5,'An Error is reported in the log', true) ";
+     $dbms->query($local_sql);
+
+     $local_sql = "INSERT INTO service_pattern VALUES ('ANY', 999991, '[Ff][Aa][Ii][Ll]', 'notify', 'Failure detected')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('Failure detected',5,'A Failure is reported in the log', true) ";
+     $dbms->query($local_sql);
+
+     $local_sql = "INSERT INTO service_pattern VALUES ('ANY', 999992, '[Ww][Aa][Rr][Nn]', 'notify', 'Warning detected')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('Warning detected',3,'A Warning is reported in the log', true) ";
+     $dbms->query($local_sql);
+
+   case 48:
+
+     $dbms->query("GRANT SELECT ON service_pattern TO GROUP view, GROUP ops, GROUP admin");
+     $dbms->query("GRANT INSERT ON service_pattern TO GROUP admin");
+     $dbms->query("GRANT UPDATE ON service_pattern TO GROUP ops, GROUP admin");
+     $dbms->query("GRANT DELETE ON service_pattern TO GROUP admin");
+     $dbms->query("GRANT SELECT ON log_abuse TO GROUP view, GROUP ops, GROUP admin");
+
+   case 49:
+     $local_sql = "ALTER TABLE object_abuse ADD COLUMN  last_change   timestamp";
+     $dbms->query($local_sql);
+
+   case 50:
+
+     $dbms->query("DROP SEQUENCE log_advid_seq");
+     $dbms->query("DROP TABLE log_adv_kernel_network");
+     $dbms->query("DROP TABLE log_adv_daemon_email");
+     $dbms->query("DROP TABLE log_adv_daemon");
+     $dbms->query("DROP TABLE log_adv");
+
+   case 51:
+
+     $local_sql = "INSERT INTO type_of_issue (name, suggested_priority, description, active)";
+     $local_sql .= " VALUES ('property out of range',5,'The DYNAMIC property of a parameter is out of range', true) ";
+     $dbms->query($local_sql);
+
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, notify)";
+     $local_sql .= " VALUES ('filesystem', 'device', 'Volume on which the filesystem resides', 'STATIC', 't')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, notify)";
+     $local_sql .= " VALUES ('filesystem', 'size', 'Total size in kilobytes', 'STATIC', 't')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, min, max, notify)";
+     $local_sql .= " VALUES ('filesystem', 'used', 'Number of kilobytes used', 'DYNAMIC', 0, 1000000, 't')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, min, max, notify)";
+     $local_sql .= " VALUES ('filesystem', 'available', 'Number of kilobytes available', 'DYNAMIC', 1000, 1000000, 't')";
+     $dbms->query($local_sql);
+
+   case 52:
+
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, notify)";
+     $local_sql .= " VALUES ('filesystem', 'Inodes', 'Total number of i-nodes', 'STATIC', 't')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, min, max, notify)";
+     $local_sql .= " VALUES ('filesystem', 'Iused', 'Number of i-nodes used', 'DYNAMIC', 0, 1000000, 't')";
+     $dbms->query($local_sql);
+     $local_sql = "INSERT INTO parameter_class (name, property_name, description, property_type, min, max, notify)";
+     $local_sql .= " VALUES ('filesystem', 'Ifree', 'Number of i-nodes available', 'DYNAMIC', 1000, 1000000, 't')";
+     $dbms->query($local_sql);
+
+   case 53:
+
+     $dbms->query("GRANT UPDATE ON action_user_actionstepid_seq TO GROUP ops, GROUP admin");
+
+     $dbms->query("GRANT INSERT ON property TO GROUP admin");
+     $dbms->query("GRANT UPDATE ON property TO GROUP admin");
+     $dbms->query("CREATE INDEX log_ab_src ON log_abuse (source, objectid)");
+
+/*
+TODO:
+*/
 //These columns have to be removed when a new version of PGSQL has become mainstream that supportsa DROP COLUMN
 /*
                          
      $local_sql = "ALTER TABLE log DROP COLUMN recognized";
      $dbms->query($local_sql);
 
-     $local_sql = "ALTER TABLE logng DROP COLUMN recognized";
-     $dbms->query($local_sql);
 */
 
    }