notifyme 0.3 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -22,7 +22,60 @@ $ notifyme_daemon stop
22
22
 
23
23
  == Example
24
24
 
25
- Please check the notifyme_config.rb file.
25
+ == Check HTTP Server (e.g. Nginx)
26
+
27
+ require 'socket'
28
+
29
+ NotifyMe::Start.config do
30
+ # output to the console
31
+ log :stdout
32
+
33
+ # output format is text
34
+ log_format :text
35
+
36
+ # define the task
37
+ task :checking_http_server do |t|
38
+
39
+ # running every 5 seconds
40
+ t.sleep_time = 5
41
+
42
+ # checking command
43
+ t.command = lambda {
44
+ begin
45
+ TCPSocket.new('localhost', 80)
46
+ nil
47
+ rescue Exception => e
48
+ e.to_s
49
+ end
50
+ }
51
+
52
+ # if the server is not running, the restart_command will be executed
53
+ t.restart_command = lambda { %x{/etc/init.d/nginx start} }
54
+ end
55
+
56
+ end
57
+
58
+ == Check the "cupsd" process (from "ps -e")
59
+
60
+ NotifyMe::Start.config do
61
+ log :stdout
62
+ log_format :json
63
+ task :checking_cupsd do |t|
64
+ t.sleep_time = 5
65
+ t.command = lambda {
66
+ if %x{ps -e}.include? " cupsd"
67
+ nil
68
+ else
69
+ "Warnning: the process cupsd is not running!"
70
+ end
71
+ }
72
+ t.restart_command = lambda {
73
+ `/etc/init.d/cups start`
74
+ }
75
+ end
76
+ end
77
+
78
+ More please check the notifyme_config.rb file.
26
79
 
27
80
  == Output
28
81
 
@@ -30,8 +83,8 @@ The output from every task's command will be processed (send to endpoint) only i
30
83
 
31
84
  == Version
32
85
 
33
- v 0.3
86
+ v 0.4
34
87
 
35
- == Author
88
+ == TODO
36
89
 
37
- xianhua.zhou@gmail.com
90
+ Add some SPECS
@@ -36,19 +36,34 @@ module NotifyMe
36
36
  )
37
37
 
38
38
  # go go go!
39
+ recipients = if param[:to_email].is_a? Hash
40
+ param[:to_email].values
41
+ else
42
+ param[:to_email]
43
+ end
39
44
  smtp.start(param[:helo_domain] || default_host,
40
45
  param[:account],
41
46
  param[:password],
42
- param[:authtype] || :plain) do |mail|
43
- mail.send_message message(param, task), param[:from_email], param[:to_email]
44
- end
47
+ param[:authtype] || :plain
48
+ ) do |mail|
49
+ mail.send_message message(param, task), param[:from_email], recipients
50
+ end
45
51
  end
46
52
 
47
53
  private
48
54
  def message(param, task)
55
+ to = case param[:to_email]
56
+ when Hash
57
+ param[:to_email].collect{|k, v| "#{k} <#{v}>" }.join(', ')
58
+ when Array
59
+ param[:to_email].collect{|v| "#{v.split('@').first} <#{v}>"}.join(", ")
60
+ else
61
+ "#{param[:to_name] || param[:to_email].split('@').first} <#{param[:to_email]}>"
62
+ end
63
+
49
64
  time = Time.now
50
65
  "From: #{param[:from_name] || param[:from_email]} <#{param[:from_email]}>\r\n" \
51
- << "To: #{param[:to_name] || param[:to_email]} <#{param[:to_email]}>\r\n" \
66
+ << "To: #{to}\r\n" \
52
67
  << "Subject: #{param[:subject]}\r\n" \
53
68
  << "Date: #{time.to_s}\r\n" \
54
69
  << "Content-type: text/plain; charset=UTF-8\r\n" \
@@ -3,7 +3,7 @@ require 'notifyme/log'
3
3
 
4
4
  module NotifyMe
5
5
 
6
- VERSION = '0.3'
6
+ VERSION = '0.4'
7
7
 
8
8
  class Start
9
9
  class << self
data/notifyme_config.rb CHANGED
@@ -1,9 +1,3 @@
1
- class MyTask
2
- def call
3
- Time.now.to_s
4
- end
5
- end
6
-
7
1
  NotifyMe::Start.config do
8
2
  log :stdout
9
3
 
@@ -18,8 +12,13 @@ NotifyMe::Start.config do
18
12
 
19
13
  :from_email => 'from@gmail.com',
20
14
  :from_name => 'from name',
15
+
21
16
  :to_email => 'to@gmail.com',
22
17
  :to_name => 'to name'
18
+
19
+ # or
20
+ :to_email => {'User a' => 'a@gmail.com', 'User b' => 'b@gmail.com'}
21
+ :to_email => ['User a <a@gmail.com>', 'User b<b@gmail.com']
23
22
  =end
24
23
 
25
24
  # log :file, '/tmp/test.txt'
@@ -33,14 +32,32 @@ NotifyMe::Start.config do
33
32
 
34
33
  # add some tasks
35
34
 
36
- task :checking_disk do |t|
37
- t.sleep_time = 3
38
- t.command = Proc.new { %x{df -h} }
35
+ #
36
+ # check disk space usage every 60 seconds,
37
+ # if one of the disks' space usage > 95%, notification will be sent.
38
+ #
39
+ task :checking_disk_usage do |t|
40
+ t.sleep_time = 60
41
+ t.command = lambda {
42
+ if %x{df -h}.scan(/\s+(\d+)%\s+/).find {|pcent| pcent.first.to_i > 95}
43
+ "Warnning: at least 1 disk space usage > 95%"
44
+ else
45
+ nil
46
+ end
47
+ }
39
48
  end
40
49
 
41
- task :checking_date do |t|
42
- t.sleep_time = 2
43
- t.command = MyTask
44
- t.restart_command = Proc.new { %x{dates} }
50
+ task :checking_localhost_http do |t|
51
+ t.sleep_time = 5
52
+ t.command = lambda {
53
+ require 'socket'
54
+ begin
55
+ TCPSocket.new('localhost', 80)
56
+ nil
57
+ rescue Exception => e
58
+ e.to_s
59
+ end
60
+ }
61
+ t.restart_command = lambda { %x{/etc/init.d/httpd start} }
45
62
  end
46
63
  end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- version: "0.3"
7
+ - 4
8
+ version: "0.4"
9
9
  platform: ruby
10
10
  authors:
11
11
  - xianhua.zhou
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-11-17 00:00:00 +08:00
16
+ date: 2011-09-03 00:00:00 +08:00
17
17
  default_executable: notifyme_daemon
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -56,20 +56,20 @@ extensions: []
56
56
  extra_rdoc_files: []
57
57
 
58
58
  files:
59
+ - lib/notifyme.rb
59
60
  - lib/vendor/smtp_add_tls_support.rb
60
- - lib/notifyme/log/stdout.rb
61
+ - lib/notifyme/log.rb
62
+ - lib/notifyme/task.rb
61
63
  - lib/notifyme/log/mail.rb
64
+ - lib/notifyme/log/stdout.rb
62
65
  - lib/notifyme/log/file.rb
63
- - lib/notifyme/task.rb
64
66
  - lib/notifyme/start.rb
65
- - lib/notifyme/log.rb
66
- - lib/notifyme.rb
67
67
  - README.rdoc
68
68
  - CHANGELOG
69
69
  - INSTALL
70
70
  - notifyme_config.rb
71
- - bin/notifyme
72
71
  - bin/notifyme_daemon
72
+ - bin/notifyme
73
73
  has_rdoc: true
74
74
  homepage: http://github.com/xianhuazhou/NotifyMe
75
75
  licenses: []