Permalink
Browse files

start working on tests for recipes

  • Loading branch information...
jordansissel committed Oct 27, 2012
1 parent 0e93090 commit fee99b235d7e0f8df4e3776a60c492c67b5d0972
Showing with 46 additions and 7 deletions.
  1. +8 −7 recipes/mysql/mysql-slow.conf
  2. +38 −0 recipes/mysql/test.rb
@@ -1,16 +1,17 @@
filter {
grok {
type => "mysql-slow"
+ singles => true
pattern => [
- "^# User@Host: %{USER:user}\[[^\]]+\] @ %{HOST:host} \[%{IP:ip}]",
+ "^# User@Host: %{USER:user}(?>\[[^\]]+\])? @ %{HOST:host} \[%{IP:ip}?\]",
"^# Query_time: %{NUMBER:duration:float} Lock_time: %{NUMBER:lock_wait:float} Rows_sent: %{NUMBER:results:int} \s*Rows_examined: %{NUMBER:scanned:int}",
"^SET timestamp=%{NUMBER:timestamp};"
]
}
multiline {
type => "mysql-slow"
- match => "^# Time: "
+ pattern => "^# Time: "
what => next
}
@@ -23,11 +24,11 @@ filter {
date {
type => "mysql-slow"
- timestamp => UNIXEPOCH
+ timestamp => UNIX
}
- mutate {
- type => "mysql-slow"
- remove => "timestamp"
- }
+ #mutate {
+ #type => "mysql-slow"
+ #remove => "timestamp"
+ #}
}
View
@@ -0,0 +1,38 @@
+require "ap"
+describe "mysql logs" do
+ extend LogStash::RSpec
+
+ describe "slow query log" do
+ # The logstash config goes here.
+ # At this time, only filters are supported.
+ config File.read("mysql-slow.conf")
+
+ data = File.open(__FILE__)
+ data.each { |line| break if line == "__END__\n" }
+
+ events = data.collect do |line|
+ LogStash::Event.new("@message" => line.chomp, "@type" => "mysql-slow")
+ end
+
+ sample events do
+ event = subject.first
+ #ap event.to_hash
+ insist { subject["user"] } == "amavis"
+ insist { subject["host"] } == "randomhost.local"
+ insist { subject["ip"] } == "10.1.22.33"
+ insist { subject["duration"] } == 114
+ insist { subject["lock_wait"] } == 0
+ insist { subject["results"] } == 25856
+ insist { subject["scanned"] } == 10864578
+ insist { subject.timestamp } == "2012-10-25T15:40:26.000Z"
+ end
+ end
+end
+
+__END__
+# Time: 121025 15:40:26
+# User@Host: amavis[amavis] @ [10.3.67.54]
+# Query_time: 114 Lock_time: 0 Rows_sent: 25856 Rows_examined: 10864578
+SET timestamp=1351204826;
+/* amavis cleanquarantine N:D:S:Amavis 175 */ select msg_headers.id, filename from msg_headers, users where (users.id=msg_headers.user_id) and (date_add(storetime, interval retention day) < now());
+

0 comments on commit fee99b2

Please sign in to comment.