melito-em-syslog 0.0.1

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.
Files changed (4) hide show
  1. data/README +43 -0
  2. data/lib/em/syslog.rb +65 -0
  3. data/test.rb +32 -0
  4. metadata +64 -0
data/README ADDED
@@ -0,0 +1,43 @@
1
+ em-syslog
2
+ #########
3
+ Simple syslog integration into EventMachine at the class level.
4
+
5
+ Still needs work and testing.
6
+
7
+ To install:
8
+
9
+ git clone git://github.com/melito/em-syslog.git
10
+
11
+ -or-
12
+
13
+ sudo gem install melito-em-syslog -s http://gems.github.com
14
+
15
+ SYNOPSIS:
16
+
17
+ # Setup syslog
18
+ EM.syslog_setup('centralserver.com', 514)
19
+
20
+ # Send commands
21
+ EM.emergency('system is unusable')
22
+ EM.alert('action must be taken immediately')
23
+ EM.critical('critical conditions')
24
+ EM.error('error conditions')
25
+ EM.warning('warning conditions')
26
+ EM.notice('normal but significant conditions')
27
+ EM.informational('informational messages')
28
+ EM.info('informational messages (short name for the previous)')
29
+ EM.debug('debug-level messages')
30
+
31
+ BUGS:
32
+ kqueue doesn't seem to work. (Haven't tested epoll)
33
+
34
+ TODO:
35
+ Benchmark
36
+ Take some of the server examples and insert.
37
+ Make sure blocking is minimal/non-existant
38
+ Add support for syslog-ng
39
+ Refactor
40
+ Add support for TCP (syslog-ng)
41
+ Add support for TLS (syslog-ng)
42
+ Clean up API
43
+ Just improve everything.
data/lib/em/syslog.rb ADDED
@@ -0,0 +1,65 @@
1
+ require "rubygems"
2
+ require "eventmachine"
3
+ require "socket"
4
+
5
+ module EventMachine
6
+ module Protocols
7
+ module Syslog
8
+ # THIEVERY: http://github.com/kpumuk/ruby_syslog
9
+ SEVERITIES = {
10
+ :emergency => 0, # system is unusable
11
+ :alert => 1, # action must be taken immediately
12
+ :critical => 2, # critical conditions
13
+ :error => 3, # error conditions
14
+ :warning => 4, # warning conditions
15
+ :notice => 5, # normal but significant condition
16
+ :informational => 6, # informational messages
17
+ :info => 6, # informational messages (short name for the previous)
18
+ :debug => 7 # debug-level messages
19
+ }
20
+
21
+ class << self
22
+ # THIEVERY: http://github.com/kpumuk/ruby_syslog
23
+ def log(severity, message, time = nil)
24
+ raise "Syslog Server not set" if EM.syslog_server.nil?
25
+
26
+ severity = SEVERITIES[severity] if severity.is_a? Symbol
27
+ time ||= Time.now
28
+ hostname = Socket.gethostname
29
+ day = time.strftime('%b %d').sub(/0(\d)/, ' \\1')
30
+ tag = "#{$0.split('/').last}[#{Process.pid}]"
31
+
32
+ send_msg "<#{0 * 8 + severity}>#{day} #{time.strftime('%T')} #{hostname} #{tag}: #{message}"
33
+ end
34
+
35
+ def send_msg(data)
36
+ EM.next_tick{
37
+ EM.open_datagram_socket('0.0.0.0', 0) {|c|
38
+ c.send_datagram(data, EM.syslog_server, EM.syslog_port)
39
+ }
40
+ }
41
+ end
42
+ private :send_msg
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ # Class methods for EM
50
+ class << self
51
+ attr_reader :syslog_server, :syslog_port
52
+ def syslog_setup(server, port=514)
53
+ @syslog_server, @syslog_port = server, port
54
+ end
55
+
56
+ # THIEVERY: http://github.com/kpumuk/ruby_syslog
57
+ EM::P::Syslog::SEVERITIES.keys.each do |severity|
58
+ define_method severity do |message|
59
+ EM::P::Syslog.log(severity, message)
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
data/test.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "lib/em/syslog"
2
+
3
+ #SYSLOG_SERVER = '192.168.249.134'
4
+ SYSLOG_SERVER = '0.0.0.0'
5
+ SYSLOG_PORT = 514
6
+
7
+ #EM.kqueue
8
+ #EM.epoll
9
+ EM.run {
10
+
11
+ # This is gonna be our 'syslog' server for testing to make sure we're getting the correct packets
12
+ #EM.open_datagram_socket SYSLOG_SERVER, SYSLOG_PORT do |c|
13
+ # def c.receive_data data
14
+ # p data
15
+ # end
16
+ #end
17
+
18
+ EM.add_periodic_timer(1) {
19
+ EM.syslog_setup(SYSLOG_SERVER, SYSLOG_PORT)
20
+
21
+ EM.emergency('system is unusable')
22
+ EM.alert('action must be taken immediately')
23
+ EM.critical('critical conditions')
24
+ EM.error('error conditions')
25
+ EM.warning('warning conditions')
26
+ EM.notice('normal but significant conditions')
27
+ EM.informational('informational messages')
28
+ EM.info('informational messages (short name for the previous)')
29
+ EM.debug('debug-level messages')
30
+ }
31
+
32
+ }
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: melito-em-syslog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mel Gray
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-30 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Simple syslog integration into EventMachine at the class level.
26
+ email: melgray@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - lib/em/syslog.rb
36
+ - test.rb
37
+ has_rdoc: false
38
+ homepage: http://www.github.com/melito/em-syslog
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Simple syslog integration into EventMachine at the class level.
63
+ test_files: []
64
+