log_master 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/log_master/configuration.rb +2 -1
- data/lib/log_master/director.rb +6 -5
- data/lib/log_master/notifier.rb +4 -1
- data/lib/log_master.rb +1 -3
- data/lib/templates/log_master/notifier/update_notification.html.erb +11 -6
- data/log_master.gemspec +2 -2
- data/spec/director_spec.rb +21 -0
- data/spec/notification_spec.rb +3 -3
- data/spec/spec_helper.rb +9 -3
- data/tasks/log_master.rake +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -4,7 +4,7 @@ module LogMaster
|
|
4
4
|
class Configuration
|
5
5
|
include Singleton
|
6
6
|
|
7
|
-
attr_accessor :title, :reporting
|
7
|
+
attr_accessor :title, :reporting, :failure_conditions
|
8
8
|
|
9
9
|
# These are options that directly affect the email
|
10
10
|
attr_accessor :recipients, :from, :reply_to
|
@@ -18,6 +18,7 @@ module LogMaster
|
|
18
18
|
def reset
|
19
19
|
@title = "No Title"
|
20
20
|
@reporting = {}
|
21
|
+
@failure_conditions = []
|
21
22
|
|
22
23
|
@@configured = false
|
23
24
|
end
|
data/lib/log_master/director.rb
CHANGED
@@ -7,9 +7,10 @@ module LogMaster
|
|
7
7
|
|
8
8
|
def initialize(files)
|
9
9
|
raise "LogMaster has not yet been configured" unless Configuration.configured?
|
10
|
+
@configuration = Configuration.instance
|
11
|
+
@reports = {}
|
10
12
|
|
11
13
|
create_log_files(files)
|
12
|
-
@reports = {}
|
13
14
|
end
|
14
15
|
|
15
16
|
def run
|
@@ -26,18 +27,18 @@ module LogMaster
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
@reports
|
30
|
+
def successful?
|
31
|
+
@configuration.failure_conditions.all? {|fc| @reports.fetch(fc, 0) == 0} && @logs.all? {|l| l.valid?}
|
31
32
|
end
|
32
33
|
|
33
34
|
def send_email
|
34
|
-
Notifier.deliver_update_notification(
|
35
|
+
Notifier.deliver_update_notification(successful?, @reports, @logs)
|
35
36
|
end
|
36
37
|
|
37
38
|
private
|
38
39
|
def create_log_files(files)
|
39
40
|
files = files.respond_to?(:each) ? files : [files]
|
40
|
-
@logs = files.map { |f| LogFile.new(f,
|
41
|
+
@logs = files.map { |f| LogFile.new(f, @configuration.reporting) }
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/lib/log_master/notifier.rb
CHANGED
@@ -14,7 +14,10 @@ module LogMaster
|
|
14
14
|
sent_on Time.now
|
15
15
|
body :title => @configuration.title, :logs => logs, :reports => reports
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def template_path
|
19
|
+
File.expand_path(File.dirname(__FILE__) + "/../../templates/log_master/notifier/update_notification.html.erb")
|
20
|
+
end
|
18
21
|
|
19
22
|
def create_subject
|
20
23
|
@configuration.title + (@status ? " SUCCESSFUL" : " FAILED")
|
data/lib/log_master.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'action_mailer'
|
3
3
|
rescue LoadError
|
4
4
|
warn 'To use LogMaster you need the actionmailer gem:'
|
5
5
|
warn '$ sudo gem install actionmailer'
|
6
6
|
raise
|
7
7
|
end
|
8
8
|
|
9
|
-
ActionMailer::Base.template_root = File.dirname(__FILE__) + "/templates"
|
10
|
-
|
11
9
|
require 'log_master/configuration'
|
12
10
|
require 'log_master/director'
|
13
11
|
require 'log_master/log_file'
|
@@ -1,8 +1,11 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
1
|
<html>
|
3
2
|
<head>
|
4
3
|
<title><%= @subject %></title>
|
5
4
|
<style type="text/css">
|
5
|
+
h3 {
|
6
|
+
text-align: center;
|
7
|
+
}
|
8
|
+
|
6
9
|
.pre {
|
7
10
|
white-space: pre;
|
8
11
|
font-family: monospace;
|
@@ -33,23 +36,25 @@
|
|
33
36
|
</style>
|
34
37
|
</head>
|
35
38
|
<body>
|
36
|
-
<
|
39
|
+
<h3>
|
37
40
|
<%= @title %>
|
38
|
-
</
|
41
|
+
</h3>
|
42
|
+
|
43
|
+
<h4>Overall Summary</h4>
|
39
44
|
<p>
|
40
45
|
<% @reports.each do |name, count| %>
|
41
|
-
<strong class="<%= name %>"><%= name.to_s.titleize %>: </strong><%= count %><br />
|
46
|
+
<strong class="<%= name %>"><%= name.to_s.titleize.pluralize %>: </strong><%= count %><br />
|
42
47
|
<% end %>
|
43
48
|
</p>
|
44
49
|
|
45
50
|
<hr />
|
46
51
|
|
47
52
|
<% @logs.each do |log| -%>
|
48
|
-
<
|
53
|
+
<p class="log"><%= log.file_name %></p>
|
49
54
|
|
50
55
|
<div class="pre">
|
51
56
|
<% log.body.each do |line| -%>
|
52
|
-
<span class="<%= stylize_output(line) %>"><%= line.chomp -%></span
|
57
|
+
<span class="<%= stylize_output(line) %>"><%= line.chomp -%></span><br />
|
53
58
|
<% end -%>
|
54
59
|
</div>
|
55
60
|
|
data/log_master.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{log_master}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Zachary Belzer"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-03}
|
13
13
|
s.description = %q{Creates and emails a simple report for a set of log (or text) files. Useful for aggretating small log files.}
|
14
14
|
s.email = %q{zbelzer@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/director_spec.rb
CHANGED
@@ -23,5 +23,26 @@ module LogMaster
|
|
23
23
|
log_master.reports[:error].should == 2
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
|
28
|
+
describe "successful?" do
|
29
|
+
it "should be true when no aggregate count for failure_conditions" do
|
30
|
+
log_master = Director.new(log_file_path('log_without_errors.log'))
|
31
|
+
log_master.run
|
32
|
+
log_master.should be_successful
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be false when aggregate count for failure_conditions > 0" do
|
36
|
+
log_master = Director.new(log_file_path('log_with_errors.log'))
|
37
|
+
log_master.run
|
38
|
+
log_master.should_not be_successful
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be false when given missing file" do
|
42
|
+
log_master = Director.new(log_file_path('nosuchfile.log'))
|
43
|
+
log_master.run
|
44
|
+
log_master.should_not be_successful
|
45
|
+
end
|
46
|
+
end
|
26
47
|
end
|
27
48
|
end
|
data/spec/notification_spec.rb
CHANGED
@@ -20,9 +20,9 @@ module LogMaster
|
|
20
20
|
|
21
21
|
it "should contain the aggregate report" do
|
22
22
|
email = Notifier.deliver_update_notification(true, {:error => 1, :warn => 2, :fatal => 0}, [])
|
23
|
-
email.should have_body_text(/
|
24
|
-
email.should have_body_text(/
|
25
|
-
email.should have_body_text(/
|
23
|
+
email.should have_body_text(/Errors:.*1/)
|
24
|
+
email.should have_body_text(/Warns:.*2/)
|
25
|
+
email.should have_body_text(/Fatals:.*0/)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should contain each of the provided logfiles" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'rubygems'
|
4
|
+
|
5
|
+
# Explicitly required so we can set class vars before Notifier gets loaded
|
6
|
+
require 'action_mailer'
|
7
|
+
|
8
|
+
ActionMailer::Base.template_root = File.dirname(__FILE__) + "/../lib/templates"
|
9
|
+
ActionMailer::Base.delivery_method = :test
|
10
|
+
# ActionMailer::Base.logger = Logger.new('test.log')
|
11
|
+
|
4
12
|
require 'log_master'
|
5
13
|
require 'spec'
|
6
14
|
require 'spec/autorun'
|
@@ -13,12 +21,10 @@ require File.dirname(__FILE__) + '/../lib/log_master'
|
|
13
21
|
|
14
22
|
FIXTURES_DIR = File.dirname(__FILE__) + "/fixtures"
|
15
23
|
|
16
|
-
ActionMailer::Base.delivery_method = :test
|
17
|
-
# ActionMailer::Base.logger = Logger.new('test.log')
|
18
|
-
|
19
24
|
LogMaster::Configuration.configure do |config|
|
20
25
|
config.title = "Testing LogMaster"
|
21
26
|
config.reporting = {:warn => /WARN/, :error => /ERROR/, :fatal => /FATAL/}
|
27
|
+
config.failure_conditions = [:error, :fatal]
|
22
28
|
config.recipients = {:success => "success@example.com", :failure => "failure@example.com"}
|
23
29
|
end
|
24
30
|
|
data/tasks/log_master.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Belzer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-03 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|