benotified 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +51 -0
- data/Manifest +28 -0
- data/README.md +132 -0
- data/Rakefile +24 -0
- data/benotified.gemspec +33 -0
- data/examples/monitor.rb +27 -0
- data/lib/be_notified.rb +9 -0
- data/lib/be_notified/commands.rb +13 -0
- data/lib/be_notified/commands/host_not_alive.rb +29 -0
- data/lib/be_notified/commands/number_of_files.rb +33 -0
- data/lib/be_notified/commands/program_running.rb +46 -0
- data/lib/be_notified/commands/size_of_file.rb +34 -0
- data/lib/be_notified/configuration.rb +91 -0
- data/lib/be_notified/monitor.rb +77 -0
- data/lib/be_notified/notifier.rb +104 -0
- data/lib/be_notified/version.rb +3 -0
- data/lib/benotified.rb +3 -0
- data/test/commands/test_host_not_alive.rb +28 -0
- data/test/commands/test_number_of_files.rb +46 -0
- data/test/commands/test_program_running.rb +27 -0
- data/test/commands/test_size_of_file.rb +32 -0
- data/test/notifiers/test_email_notifier.rb +52 -0
- data/test/notifiers/test_log_notifier.rb +43 -0
- data/test/test_configuration.rb +126 -0
- data/test/test_helper.rb +6 -0
- data/test/test_monitor.rb +36 -0
- data/test/test_notifier.rb +20 -0
- metadata +138 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class TestEmailNotifier < Test::Unit::TestCase
|
5
|
+
include BeNotified::Notifiers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
email_options = {
|
9
|
+
:email => {
|
10
|
+
:smtp_address => 'localhost',
|
11
|
+
:smtp_port => 25,
|
12
|
+
:domain => 'example.com',
|
13
|
+
:username => 'login',
|
14
|
+
:password => 'pass',
|
15
|
+
:to => 'to@example.com',
|
16
|
+
:from => 'from@example.com',
|
17
|
+
:subject => 'The Subject'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
# Make sure we always start fresh
|
22
|
+
BeNotified::Configuration.instance_variable_set(:@options, nil)
|
23
|
+
|
24
|
+
# In most cases pretend that configuration file does not exists
|
25
|
+
BeNotified::Configuration.stubs(:load_config_file).returns("")
|
26
|
+
|
27
|
+
# Merge email_options
|
28
|
+
BeNotified::Configuration.stubs(:config_file_options).returns(email_options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_configuration_access
|
32
|
+
assert Email.new.respond_to? :options
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_notifier_type_before_using_email
|
36
|
+
BeNotified::Configuration.options.merge!({:notifier_type => BeNotified::Notifiers::Log})
|
37
|
+
|
38
|
+
assert_raise ArgumentError do
|
39
|
+
Email.new.notify("Trying to send an email")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Test sending email
|
44
|
+
def test_sending_email
|
45
|
+
BeNotified::Configuration.options.merge!({:notifier_type => BeNotified::Notifiers::Email})
|
46
|
+
|
47
|
+
sender = mock(:deliver)
|
48
|
+
Email::Mailer.expects(:email).returns(sender)
|
49
|
+
|
50
|
+
Email.new.notify("sending emails works fine")
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestLogNotifier < Test::Unit::TestCase
|
4
|
+
include BeNotified::Notifiers
|
5
|
+
include Log4r
|
6
|
+
|
7
|
+
def setup
|
8
|
+
# Make sure we always start fresh
|
9
|
+
BeNotified::Configuration.instance_variable_set(:@options, nil)
|
10
|
+
|
11
|
+
# Pretend that configuration file does not exists
|
12
|
+
BeNotified::Configuration.stubs(:load_config_file).returns("")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_configuration_access
|
16
|
+
assert Log.new.respond_to? :options
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_stdout_outputter
|
20
|
+
log = Log.new
|
21
|
+
|
22
|
+
# By default monitor should log to stdout
|
23
|
+
assert log.logger.outputters.include?(Outputter.stdout)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_file_outputter
|
27
|
+
log = Log.new
|
28
|
+
|
29
|
+
BeNotified::Configuration.options.merge!({:logger_file => '/tmp/be_notified.log'})
|
30
|
+
|
31
|
+
# Set expectation on FileOutputter
|
32
|
+
FileOutputter.expects(:new)
|
33
|
+
log.logger
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_logger_notifications
|
37
|
+
log = Log.new
|
38
|
+
|
39
|
+
# Log to stdout on warn level
|
40
|
+
log.logger.expects(:warn).with("testing logger notifications")
|
41
|
+
log.notify("testing logger notifications")
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestConfiguration < Test::Unit::TestCase
|
4
|
+
include BeNotified
|
5
|
+
|
6
|
+
def setup
|
7
|
+
# Make sure we always start fresh
|
8
|
+
Configuration.instance_variable_set(:@options, nil)
|
9
|
+
|
10
|
+
# In most cases pretend that configuration file does not exists
|
11
|
+
Configuration.stubs(:load_config_file).returns("")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_configuration_having_default_values
|
15
|
+
assert_equal Notifiers::Log, Configuration.options[:notifier_type]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_adding_a_value_to_configuration_from_the_monitor
|
19
|
+
monitor = BeNotified::Monitor.new do
|
20
|
+
opts = {
|
21
|
+
:test => 'test'
|
22
|
+
}
|
23
|
+
configuration(opts)
|
24
|
+
end
|
25
|
+
assert_equal 'test', BeNotified::Configuration.options[:test]
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_overwriting_options_from_configuration
|
29
|
+
Configuration.options.merge!({:logger_file => '/tmp/be_notified.log'})
|
30
|
+
|
31
|
+
monitor = BeNotified::Monitor.new do
|
32
|
+
opts = {
|
33
|
+
:logger_file => 'test_file.log'
|
34
|
+
}
|
35
|
+
configuration(opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal 'test_file.log', BeNotified::Configuration.options[:logger_file]
|
39
|
+
assert_equal 'test_file.log', monitor.options[:logger_file]
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_options_for_email_should_be_stored_in_hash
|
43
|
+
assert Configuration.options[:email].is_a? Hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_loading_config_from_file
|
47
|
+
# Unstub 'load_config_file'
|
48
|
+
Mocha::Mockery.instance.stubba.unstub_all
|
49
|
+
|
50
|
+
File.expects(:open).returns(mock(:read => json_file_content))
|
51
|
+
assert_equal json_file_content, Configuration.load_config_file
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_loading_config_for_non_existing_file
|
55
|
+
# Unstub 'load_config_file'
|
56
|
+
Mocha::Mockery.instance.stubba.unstub_all
|
57
|
+
|
58
|
+
File.expects(:open).raises(Errno::ENOENT)
|
59
|
+
assert_equal "", Configuration.load_config_file
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_parsing_invalid_file
|
63
|
+
Configuration.expects(:load_config_file).returns(json_file_content)
|
64
|
+
Configuration.expects(:puts)
|
65
|
+
|
66
|
+
JSON.expects(:parse).raises(JSON::ParserError)
|
67
|
+
|
68
|
+
assert_equal Hash.new, Configuration.config_file_options
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_pasring_valid_json_content
|
72
|
+
Configuration.expects(:load_config_file).returns(json_file_content)
|
73
|
+
|
74
|
+
opts = { :logger_file => "/tmp/be_notified.log" }
|
75
|
+
assert_equal opts, Configuration.config_file_options
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_merging_default_config_with_config_from_file
|
79
|
+
Configuration.expects(:load_config_file).returns(json_file_content)
|
80
|
+
assert_equal "/tmp/be_notified.log", Configuration.options[:logger_file]
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_validation_of_emails_configuration
|
84
|
+
Configuration.expects(:load_config_file).returns(json_incomplete_file_content_for_email_options)
|
85
|
+
|
86
|
+
assert_raise ArgumentError do
|
87
|
+
Configuration.options
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_validation_of_emails_options_should_not_happen_when_logger_used
|
92
|
+
Configuration.expects(:load_config_file).returns(json_file_content_with_email_options_and_logger_notifier)
|
93
|
+
|
94
|
+
assert_nothing_raised do
|
95
|
+
Configuration.options
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def json_file_content
|
102
|
+
json_content = <<-END
|
103
|
+
{"logger_file":"/tmp/be_notified.log"}
|
104
|
+
END
|
105
|
+
end
|
106
|
+
|
107
|
+
def json_file_content_with_email_options
|
108
|
+
json_content = <<-END
|
109
|
+
{"notifier_type":"BeNotified::Notifiers::Email","email":{"smtp_address":"localhost","smtp_port":25,"domain":"example.com","username":"login","password":"pass","to":"to@example.com","from":"from@example.com","subject":"The Subject"}}
|
110
|
+
END
|
111
|
+
end
|
112
|
+
|
113
|
+
def json_incomplete_file_content_for_email_options
|
114
|
+
json_content = <<-END
|
115
|
+
{"notifier_type":"BeNotified::Notifiers::Email","email":{"smtp_address":"localhost","domain":"example.com","username":"login","password":"pass","to":"to@example.com","from":"from@example.com","subject":"The Subject"}}
|
116
|
+
END
|
117
|
+
end
|
118
|
+
|
119
|
+
def json_file_content_with_email_options_and_logger_notifier
|
120
|
+
json_content = <<-END
|
121
|
+
{"notifier_type":"BeNotified::Notifiers::Log","email":{"smtp_address":"localhost","domain":"example.com","username":"login","password":"pass","to":"to@example.com","from":"from@example.com","subject":"The Subject"}}
|
122
|
+
END
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestMonitor < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# Make sure we always start fresh
|
7
|
+
BeNotified::Configuration.instance_variable_set(:@options, nil)
|
8
|
+
|
9
|
+
# Pretend that configuration file does not exists
|
10
|
+
BeNotified::Configuration.stubs(:load_config_file).returns("")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_do_notify
|
14
|
+
BeNotified::Notifier.any_instance.expects(:notify)
|
15
|
+
|
16
|
+
monitor = BeNotified::Monitor.new {}
|
17
|
+
monitor.expects(:notifier_type).returns(BeNotified::Notifiers::Email)
|
18
|
+
monitor.alert_when "test notification" do
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_dont_notify
|
24
|
+
monitor = BeNotified::Monitor.new {}
|
25
|
+
monitor.expects(:notifier_type).never
|
26
|
+
|
27
|
+
monitor.alert_when "do not notify" do
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_notifier_default_type
|
33
|
+
monitor = BeNotified::Monitor.new {}
|
34
|
+
assert_equal BeNotified::Notifiers::Log, monitor.notifier_type
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestNotifier < Test::Unit::TestCase
|
4
|
+
include BeNotified
|
5
|
+
|
6
|
+
def test_notifier_sending_messages_to_log
|
7
|
+
Notifiers::Log.any_instance.expects(:notify).with("test log notifier")
|
8
|
+
Notifier.new(Notifiers::Log, "test log notifier").notify
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_notifier_sending_messages_to_email
|
12
|
+
Notifiers::Email.any_instance.expects(:notify).with("test email notifier")
|
13
|
+
Notifier.new(Notifiers::Email, "test email notifier").notify
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_notifier_sending_messages_to_email_for_string_type_of_notifier
|
17
|
+
Notifiers::Email.any_instance.expects(:notify).with("test email notifier")
|
18
|
+
Notifier.new("Notifiers::Email", "test email notifier").notify
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benotified
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dominik Staskiewicz
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApzdGFk
|
19
|
+
b21pbmlrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
|
20
|
+
b20wHhcNMTEwMTA2MjMwNzM2WhcNMTIwMTA2MjMwNzM2WjBBMRMwEQYDVQQDDApz
|
21
|
+
dGFkb21pbmlrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
22
|
+
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDD2GpkWpnWvjH7
|
23
|
+
7seIdaFsEiwXRwaJmSz9FOrc4Yuuww7FIO2JJNXNjYbYZIi2L2UFZ4QR6mcjmbnx
|
24
|
+
xPP/bnbch8w2bsaiLMGHZu8dKz/YJ8HTcJ3zwP0aq4mM9Xs1IBTPKImwGD7Mll7d
|
25
|
+
HArVoXpYSr0KkvuTfus7rul6yuZze0uALjUFX/kPLMy4y5ksmRjXWHQL/p8/VyQz
|
26
|
+
j0/iEeD7Gj7LTTeyd2bVnkhH45eCW+oyLOas2BInmp23g9PjQOCJKg2/afMaHc+l
|
27
|
+
/l5gsSiTdnUd1erQsX7FSBvOLQN00hcnh0lPTWui/ZL1QG3PI0Fw94sMUCeZyU5E
|
28
|
+
EtgPbASFAgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFFCLRokiL1VlUl12
|
29
|
+
QYH/prpHQEDiMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAjwoBNyZI
|
30
|
+
o9eAPlSbGjUvSqZlqEthf3OhHrEtoDFCqGWc7atxz/pZFC48JUFV0UWQlkY/NMKG
|
31
|
+
y+rOogrrJc5cFwWO/WdwAq2m6kfPm7fDlOGS8FTV5RlHZeppOrVgAHq/U0DLfUt4
|
32
|
+
sLbM5rx6cDa/JpbFFfC9utxnZw94j4kNl1WdGSycMem7Jxwd8iPUFKi3UfASNl+F
|
33
|
+
oJmkjDyU4j4l/MwEsateO3jaJBHfR55jeBc/PposKqEFnGaiBMd+NMLXf50L1hI9
|
34
|
+
SS3CfZyfUqCUm+6aSsicRklnvAJ8S74To2JkO3qp+av0CQkLQ1VWpl79nNhZJN5M
|
35
|
+
wYwJN5o4GnGcdg==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2011-01-19 00:00:00 +01:00
|
39
|
+
default_executable:
|
40
|
+
dependencies: []
|
41
|
+
|
42
|
+
description: Library to monitor your programs and resources. It will notify you by email or just log the event if something goes wrong.
|
43
|
+
email: stadominik @nospam@ gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README.md
|
50
|
+
- lib/be_notified.rb
|
51
|
+
- lib/be_notified/commands.rb
|
52
|
+
- lib/be_notified/commands/host_not_alive.rb
|
53
|
+
- lib/be_notified/commands/number_of_files.rb
|
54
|
+
- lib/be_notified/commands/program_running.rb
|
55
|
+
- lib/be_notified/commands/size_of_file.rb
|
56
|
+
- lib/be_notified/configuration.rb
|
57
|
+
- lib/be_notified/monitor.rb
|
58
|
+
- lib/be_notified/notifier.rb
|
59
|
+
- lib/be_notified/version.rb
|
60
|
+
- lib/benotified.rb
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- Manifest
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- benotified.gemspec
|
68
|
+
- examples/monitor.rb
|
69
|
+
- lib/be_notified.rb
|
70
|
+
- lib/be_notified/commands.rb
|
71
|
+
- lib/be_notified/commands/host_not_alive.rb
|
72
|
+
- lib/be_notified/commands/number_of_files.rb
|
73
|
+
- lib/be_notified/commands/program_running.rb
|
74
|
+
- lib/be_notified/commands/size_of_file.rb
|
75
|
+
- lib/be_notified/configuration.rb
|
76
|
+
- lib/be_notified/monitor.rb
|
77
|
+
- lib/be_notified/notifier.rb
|
78
|
+
- lib/be_notified/version.rb
|
79
|
+
- lib/benotified.rb
|
80
|
+
- test/commands/test_host_not_alive.rb
|
81
|
+
- test/commands/test_number_of_files.rb
|
82
|
+
- test/commands/test_program_running.rb
|
83
|
+
- test/commands/test_size_of_file.rb
|
84
|
+
- test/notifiers/test_email_notifier.rb
|
85
|
+
- test/notifiers/test_log_notifier.rb
|
86
|
+
- test/test_configuration.rb
|
87
|
+
- test/test_helper.rb
|
88
|
+
- test/test_monitor.rb
|
89
|
+
- test/test_notifier.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/staskie/be-notified
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- --line-numbers
|
97
|
+
- --inline-source
|
98
|
+
- --title
|
99
|
+
- Benotified
|
100
|
+
- --main
|
101
|
+
- README.md
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 1
|
119
|
+
- 2
|
120
|
+
version: "1.2"
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: benotified
|
124
|
+
rubygems_version: 1.3.7
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Library to monitor your programs and resources. It will notify you by email or just log the event if something goes wrong.
|
128
|
+
test_files:
|
129
|
+
- test/commands/test_host_not_alive.rb
|
130
|
+
- test/commands/test_number_of_files.rb
|
131
|
+
- test/commands/test_program_running.rb
|
132
|
+
- test/commands/test_size_of_file.rb
|
133
|
+
- test/notifiers/test_email_notifier.rb
|
134
|
+
- test/notifiers/test_log_notifier.rb
|
135
|
+
- test/test_configuration.rb
|
136
|
+
- test/test_helper.rb
|
137
|
+
- test/test_monitor.rb
|
138
|
+
- test/test_notifier.rb
|
metadata.gz.sig
ADDED
Binary file
|