Permalink
Browse files

remote_syslog binary, sample config file, eventmachine tail and UDP e…

…mitter, gemspec, sample rc file
  • Loading branch information...
1 parent e1998fa commit fcff3849948ba5008fdc16fe8cafddb7eafe8eb5 @troy troy committed Nov 17, 2010
View
@@ -2,3 +2,4 @@
.DS_Store
._*
*.sw?
+pkg/*
View
@@ -0,0 +1,3 @@
+gem 'daemons'
+gem 'eventmachine'
+gem 'eventmachine-tail'
View
@@ -0,0 +1,14 @@
+GEM
+ specs:
+ daemons (1.1.0)
+ eventmachine (0.12.10)
+ eventmachine-tail (0.5.20101005181243)
+ eventmachine
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ daemons
+ eventmachine
+ eventmachine-tail
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Seven Scale LLC
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
+NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
0 README
No changes.
View
@@ -0,0 +1,96 @@
+# remote_syslog Ruby daemon & sender
+
+Lightweight Ruby daemon to tail one or more log files and transmit UDP syslog
+messages to a remote syslog host (centralized log aggregation).
+
+remote_syslog generates UDP packets itself instead of depending on a system
+syslog daemon, so its configuration doesn't affect system-wide
+logging - syslog is just the transport.
+
+Uses:
+
+* collecting logs from servers & daemons which don't natively support syslog
+* when reconfiguring the system logger is less convenient than a
+purpose-built daemon (e.g., automated app deployments)
+* aggregating files not generated by daemons (e.g., package manager logs)
+
+The library can also be used to generate one-off log messages from Ruby code.
+
+Tested with the hosted log management service [Papertrail] and should work for
+transmitting to any syslog server.
+
+
+## Installation
+
+Install the gem, which includes a binary called "remote_syslog":
+
+ gem install remote_syslog
+
+Optionally, create a log_files.yml with the log file paths to read and the
+host/port to log to (see examples/log_files.yml.example). These can also be
+specified as arguments to the remote_syslog daemon. More below.
+
+
+## Usage
+
+ $ remote_syslog -h
+ Usage: remote_syslog [options] <path to add'l log 1> .. <path to add'l log n>
+
+ Example: remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log
+
+ Options:
+ -c, --configfile PATH Path to config (/etc/log_files.yml)
+ -d, --dest-host HOSTNAME Destination syslog hostname or IP (logs.papertrailapp.com)
+ -D, --no-detach Don't daemonize and detach from the terminal
+ -f, --facility FACILITY Facility (user)
+ -p, --dest-port PORT Destination syslog port (514)
+ -P, --pid-dir DIRECTORY Directory to write .pid file in (/var/run/)
+ -s, --severity SEVERITY Severity (notice)
+ -h, --help Show this message
+
+
+## Example
+
+Daemonize, collecting from files mentioned in ./config/logs.yml as well as
+/var/log/mysqld.log:
+ remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log
+
+Stay attached to the terminal, look for and use /etc/log_files.yml if it exists,
+write PID to /tmp/remote_syslog.pid, and send with facility local0:
+ remote_syslog -d a.server.com -f local0 -P /tmp /var/log/mysqld.log
+
+remote_syslog will daemonize by default. A sample init file is in the gem as
+remote_syslog.init.d. You may be able to:
+ cp examples/remote_syslog.init.d /etc/init.d/remote_syslog
+
+
+## Configuration
+
+The gem comes with a sample config. Optionally:
+
+ cp examples/log_files.yml.example /etc/log_files.yml
+
+log_files.yml has filenames to log from (as an array) and hostname and port
+to log to (as a hash). Only 1 destination server is supported; the command-line
+argument wins. Filenames given on the command line are additive to those
+in the config file.
+
+
+## Contribute
+
+Bug report:
+
+1. See whether the issue has already been reported:
+ http://github.com/papertrail/remote_syslog/issues/
+2. If you don't find one, create an issue with a repro case.
+
+Enhancement or fix:
+
+1. Fork the project:
+ http://github.com/papertrail/remote_syslog
+2. Make your changes with tests.
+3. Commit the changes without changing the Rakefile or other files unrelated
+to your enhancement.
+4. Send a pull request.
+
+[Papertrail]: http://papertrailapp.com/
View
150 Rakefile
@@ -0,0 +1,150 @@
+require 'rubygems'
+require 'rake'
+require 'date'
+
+#############################################################################
+#
+# Helper functions
+#
+#############################################################################
+
+def name
+ @name ||= Dir['*.gemspec'].first.split('.').first
+end
+
+def version
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+end
+
+def date
+ Date.today.to_s
+end
+
+def rubyforge_project
+ name
+end
+
+def gemspec_file
+ "#{name}.gemspec"
+end
+
+def gem_file
+ "#{name}-#{version}.gem"
+end
+
+def replace_header(head, header_name)
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
+end
+
+#############################################################################
+#
+# Standard tasks
+#
+#############################################################################
+
+task :default => :test
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+desc "Generate RCov test coverage and open in your browser"
+task :coverage do
+ require 'rcov'
+ sh "rm -fr coverage"
+ sh "rcov test/test_*.rb"
+ sh "open coverage/index.html"
+end
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "#{name} #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+desc "Open an irb session preloaded with this library"
+task :console do
+ sh "irb -rubygems -r ./lib/#{name}.rb"
+end
+
+#############################################################################
+#
+# Custom tasks (add your own tasks here)
+#
+#############################################################################
+
+
+
+#############################################################################
+#
+# Packaging tasks
+#
+#############################################################################
+
+desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
+task :release => :build do
+ unless `git branch` =~ /^\* master$/
+ puts "You must be on the master branch to release!"
+ exit!
+ end
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
+ sh "git tag v#{version}"
+ sh "git push origin master"
+ sh "git push origin v#{version}"
+# sh "gem push pkg/#{name}-#{version}.gem"
+end
+
+desc "Build #{gem_file} into the pkg directory"
+task :build => :gemspec do
+ sh "mkdir -p pkg"
+ sh "gem build #{gemspec_file}"
+ sh "mv #{gem_file} pkg"
+end
+
+desc "Generate #{gemspec_file}"
+task :gemspec => :validate do
+ # read spec file and split out manifest section
+ spec = File.read(gemspec_file)
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
+
+ # replace name version and date
+ replace_header(head, :name)
+ replace_header(head, :version)
+ replace_header(head, :date)
+ #comment this out if your rubyforge_project has a different name
+ #replace_header(head, :rubyforge_project)
+
+ # determine file list from git ls-files
+ files = `git ls-files`.
+ split("\n").
+ sort.
+ reject { |file| file =~ /^\./ }.
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
+ map { |file| " #{file}" }.
+ join("\n")
+
+ # piece file back together and write
+ manifest = " s.files = %w[\n#{files}\n ]\n"
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
+ puts "Updated #{gemspec_file}"
+end
+
+desc "Validate #{gemspec_file}"
+task :validate do
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
+ unless libfiles.empty?
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
+ exit!
+ end
+ unless Dir['VERSION*'].empty?
+ puts "A `VERSION` file at root level violates Gem best practices."
+ exit!
+ end
+end
Oops, something went wrong.

0 comments on commit fcff384

Please sign in to comment.