incubator-alois-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fla...@apache.org
Subject svn commit: r1040570 - in /incubator/alois/trunk/prisma: bin/prisma data/prisma/prisma_database/model/log_meta.rb
Date Tue, 30 Nov 2010 15:08:51 GMT
Author: flavio
Date: Tue Nov 30 15:08:50 2010
New Revision: 1040570

URL: http://svn.apache.org/viewvc?rev=1040570&view=rev
Log:
Prisma can now import logs from stdin

Modified:
    incubator/alois/trunk/prisma/bin/prisma
    incubator/alois/trunk/prisma/data/prisma/prisma_database/model/log_meta.rb

Modified: incubator/alois/trunk/prisma/bin/prisma
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/bin/prisma?rev=1040570&r1=1040569&r2=1040570&view=diff
==============================================================================
--- incubator/alois/trunk/prisma/bin/prisma (original)
+++ incubator/alois/trunk/prisma/bin/prisma Tue Nov 30 15:08:50 2010
@@ -13,7 +13,7 @@ waiting_time = nil
 force = false
 force_user = nil
 count = nil
-
+migrate_redo = false
 action, params = optparse({
 			    :text => "TODO: add text here",
 			    :actions => {
@@ -21,7 +21,8 @@ action, params = optparse({
 			      "dump DB" => "Dump database schema",
 			      "load DB" => "Load database schema",
 			      "check DB" => "Check database version",
-                              "start SOURCECLASS" => "start"
+                              "start SOURCECLASS" => "start",
+                              "stdin" => "Read logs from stdin (for syslog)",
                             }}) {|o|
   o.on( "-d", "--daemon", "Run as daemon." ) do |daemon| end
   o.on( "-f", "--force", "Force prisma to run even if do_not_run_prisma is defined." ) do
|force| end
@@ -36,6 +37,8 @@ action, params = optparse({
     waiting_time = w.to_i
   end
 
+  o.on( "-r", "--redo COUNT", "Redo the latest migration, only valid for migrate task.")
do |migrate_redo| end
+
   o.on( "--all", "Transform all messages in the queue and exit afterwards." ) do |a|
     type = :all
   end
@@ -56,6 +59,7 @@ options = {
 case action
 when "migrate"
   # migration
+  options[:redo] = migrate_redo.to_i if migrate_redo
   Prisma::Database.migrate(params[:db], ENV["VERSION"] ? ENV["VERSION"].to_i : nil, options)
 when "dump"
   Prisma::Database.schema_dump(params[:db], options)
@@ -64,6 +68,21 @@ when "load"
 when "check"
   Prisma::Database.load_all(options)
   Prisma::Database.check(params[:db], options)
+when "stdin"
+  Prisma::Database.load_all(options)
+  Prisma::Database.check("prisma" , options)
+  Prisma::Database.check("pumpy" , options)
+
+  raise "Stdin processing can not be run as daemon" if daemon
+  
+  source = FileMeta.new
+  source.basename = "STDIN"
+  source.save
+
+  STDIN.each {|line|
+    meta = PureMeta.new.prisma_initialize(source, {:message=>line})
+    meta.transform
+  }
 when "start"
   if force; $do_not_run_prisma = false; end
   if $do_not_run_prisma

Modified: incubator/alois/trunk/prisma/data/prisma/prisma_database/model/log_meta.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/prisma/data/prisma/prisma_database/model/log_meta.rb?rev=1040570&r1=1040569&r2=1040570&view=diff
==============================================================================
--- incubator/alois/trunk/prisma/data/prisma/prisma_database/model/log_meta.rb (original)
+++ incubator/alois/trunk/prisma/data/prisma/prisma_database/model/log_meta.rb Tue Nov 30
15:08:50 2010
@@ -23,6 +23,19 @@
 
     def self.expressions
       ret = []
+        # Nov 29 10:36:58 testhost kernel: [251102.020761] ...
+      ret.push({ :condition => lambda {|mesage, meta_class, meta_instance| meta_class
== PureMeta },
+		 :regex => /^([^ ]*) *(\d+) (..:\d\d:\d\d) ([^ ]*) ([^ ]*)\: \[(\d+\.\d+)\] (.*)$/,
+		 :result_filter => lambda {|results, meta_instance|
+                   # TODO: time offset and facility should not be ommited
+                   results.delete_at(4);results.delete_at(4)
+
+		   results[0] = DateTime.strptime("#{results[0]} #{results[1]} #{Time.now.year}", "%b %d
%Y")
+		   results.delete_at(1)
+		   results
+		 },
+		 :fields => [:date, :time, :host, :message]})      
+
       ret.push({ :condition => lambda {|mesage, meta_class, meta_instance| meta_class
== PureMeta },
 		 :regex => /^([^ ]*) *(\d+) (..:\d\d:\d\d) ([^ ]*) (.*)$/,
 		 :result_filter => lambda {|results, meta_instance| 		   
@@ -31,6 +44,7 @@
 		   results
 		 },
 		 :fields => [:date, :time, :host, :message]})      
+
       return ret
     end
         



Mime
View raw message