post_remote_log 1.6.3 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,14 +20,13 @@ if ARGV.delete("-d")
20
20
  end
21
21
 
22
22
  require 'post_remote_log'
23
- require 'post_remote_log/simple_xml'
24
- require 'post_remote_log/methods/xmlrpc'
25
- require 'post_remote_log/methods/email'
23
+ require 'post_remote_log/methods'
26
24
 
27
25
  require 'yaml'
28
26
 
29
27
  OPTIONS = {
30
- :config => "/etc/post-remote-log.conf"
28
+ :config => "/etc/post-remote-log.conf",
29
+ :verbose => false
31
30
  }
32
31
 
33
32
  ARGV.options do |o|
@@ -44,6 +43,10 @@ ARGV.options do |o|
44
43
  o.on("-d", "Run in background as a daemon. Requires daemon-exec.") do
45
44
  # This option is handled above.
46
45
  end
46
+
47
+ o.on("-v", "Verbose output.") do
48
+ OPTIONS[:verbose] = true
49
+ end
47
50
  end.parse!
48
51
 
49
52
  # Load the configuration
@@ -75,16 +78,15 @@ $values = {
75
78
  :report => report
76
79
  }
77
80
 
78
- $methods = {
79
- :xmlrpc => PostRemoteLog::Methods::XMLRPC,
80
- :email => PostRemoteLog::Methods::Email
81
- }
82
-
83
- $config[:methods].values.each do |config|
81
+ $config[:methods].each do |entry|
84
82
  begin
83
+ name, config = entry
84
+
85
+ puts "Evaluating method #{config[:method]}:#{name} which is #{config[:disabled] ? 'disabled' : 'enabled'}..." if OPTIONS[:verbose]
86
+
85
87
  next if config[:disabled] == true
86
88
 
87
- method = $methods[config[:method].to_sym]
89
+ method = PostRemoteLog::Methods.load_method(config[:method])
88
90
 
89
91
  method.send(config, $values)
90
92
  rescue => ex
@@ -0,0 +1,18 @@
1
+
2
+ module PostRemoteLog
3
+
4
+ module Methods
5
+ @@methods = {}
6
+
7
+ def self.load_method(name)
8
+ name = name.to_sym
9
+
10
+ unless @@methods[name]
11
+ require File.join(File.dirname(__FILE__), "methods", name.to_s)
12
+ end
13
+
14
+ return @@methods[name]
15
+ end
16
+ end
17
+
18
+ end
@@ -14,12 +14,13 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  require 'post_remote_log/xml'
17
+
17
18
  require 'net/smtp'
18
19
  require 'digest'
19
20
 
20
21
  module PostRemoteLog
21
22
  module Methods
22
-
23
+
23
24
  class Email
24
25
  def self.send(config, values)
25
26
  message = PostRemoteLog.build_xml_message(values)
@@ -70,8 +71,16 @@ module PostRemoteLog
70
71
  email.puts [values[:report]].pack("m")
71
72
 
72
73
  email.puts "--#{marker}--"
73
-
74
- smtp = Net::SMTP.new(config[:host], config[:port])
74
+
75
+ port = 25
76
+
77
+ if config[:tls]
78
+ port = 587
79
+ end
80
+
81
+ port = config[:port] || port
82
+
83
+ smtp = Net::SMTP.new(config[:host], port)
75
84
 
76
85
  begin
77
86
  if config[:tls]
@@ -85,17 +94,22 @@ module PostRemoteLog
85
94
  smtp.enable_starttls(context)
86
95
  end
87
96
 
88
- smtp.start(values[:hostname], config[:user], config[:pass], config[:auth])
97
+ auth = config[:auth] ? config[:auth].to_sym : nil
98
+ auth ||= :plain if config[:password]
89
99
 
90
- smtp.sendmail(email.string, from, [to])
100
+ smtp.start(values[:hostname], config[:user], config[:password], auth)
91
101
 
92
- $stderr.puts "Remote log created successfully."
102
+ smtp.sendmail(email.string, from, [to])
93
103
  ensure
94
- smtp.finish
104
+ if smtp.started?
105
+ smtp.finish
106
+ end
95
107
  end
96
108
  end
97
109
  end
98
-
110
+
111
+ @@methods[:email] = Email
112
+
99
113
  end
100
114
  end
101
115
 
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2009 Samuel Williams. Released under the GNU GPLv3.
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require 'ruby-growl'
17
+
18
+ module PostRemoteLog
19
+ module Methods
20
+
21
+ class Growl
22
+ def self.send(config, values)
23
+ g = ::Growl.new(config[:host], "PostRemoteLog", [values[:classification]], [values[:classification]], config[:password])
24
+
25
+ message = StringIO.new
26
+ [:uptime, :system, :hostname, :address].each do |key|
27
+ message.puts "[#{key}] #{values[key]}"
28
+ end
29
+
30
+ message.puts
31
+ message.puts values[:report]
32
+
33
+ g.notify(values[:classification], "Remote Log [#{values[:classification]}] from #{values[:hostname]}", message.string, config[:priority] || 0, config[:sticky])
34
+ end
35
+ end
36
+
37
+ @@methods[:growl] = Growl
38
+
39
+ end
40
+ end
@@ -23,8 +23,11 @@ module PostRemoteLog
23
23
  def self.send(config, values)
24
24
  message = PostRemoteLog.build_xml_message(values)
25
25
 
26
- Net::HTTP.start(config[:host], config[:port]) do |http|
27
- response = http.post(config[:path], message.string, {"Content-Type" => "text/xml"})
26
+ port = config[:port] || 9080
27
+ path = config[:path] || "/post-remote-log"
28
+
29
+ Net::HTTP.start(config[:host], port) do |http|
30
+ response = http.post(path, message.string, {"Content-Type" => "text/xml"})
28
31
 
29
32
  unless (200...300).include?(response.code.to_i)
30
33
  $stderr.puts "Could not create remote log record..."
@@ -32,12 +35,12 @@ module PostRemoteLog
32
35
  $stderr.puts "Code: #{response.code}"
33
36
  $stderr.puts "Message: #{response.message}"
34
37
  $stderr.puts "Body:\n #{response.body}"
35
- else
36
- $stderr.puts "Remote log created successfully."
37
38
  end
38
39
  end
39
40
  end
40
41
  end
41
42
 
43
+ @@methods[:xmlrpc] = XMLRPC
44
+
42
45
  end
43
46
  end
@@ -16,8 +16,8 @@
16
16
  module PostRemoteLog
17
17
  module VERSION #:nodoc:
18
18
  MAJOR = 1
19
- MINOR = 6
20
- TINY = 3
19
+ MINOR = 7
20
+ TINY = 0
21
21
 
22
22
  STRING = [MAJOR, MINOR, TINY].join('.')
23
23
  end
@@ -13,6 +13,8 @@
13
13
  # You should have received a copy of the GNU General Public License
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
+ require 'post_remote_log/simple_xml'
17
+
16
18
  module PostRemoteLog
17
19
 
18
20
  # Builds an XML formatted message from the supplied values
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 6
8
- - 3
9
- version: 1.6.3
7
+ - 7
8
+ - 0
9
+ version: 1.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Samuel Williams
@@ -41,7 +41,9 @@ extra_rdoc_files:
41
41
  files:
42
42
  - lib/post_remote_log/extensions.rb
43
43
  - lib/post_remote_log/methods/email.rb
44
+ - lib/post_remote_log/methods/growl.rb
44
45
  - lib/post_remote_log/methods/xmlrpc.rb
46
+ - lib/post_remote_log/methods.rb
45
47
  - lib/post_remote_log/server.rb
46
48
  - lib/post_remote_log/simple_xml.rb
47
49
  - lib/post_remote_log/version.rb