Skip to content

Commit

Permalink
References Fudge#21, allowing local commands to be run and parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
pyro2927 committed Apr 25, 2012
1 parent 7435c02 commit 87f0c55
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/gl_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ module GlTail
$PHYSICS = false
end

begin
require 'pty'
rescue LoadError
puts "pty required"
exit
end

$:.unshift(File.dirname(__FILE__)) # this should be obsolete once its a gem

# load our libraries
Expand Down
4 changes: 3 additions & 1 deletion lib/gl_tail/config/yaml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def parse_servers
name = server.shift
data = server.shift

if data['source'] && data['source'].downcase == 'local'
if data['source'] && data['source'].downcase == 'local' && data['command']
src = GlTail::Source::Command.new(@config)
elsif data['source'] && data['source'].downcase == 'local'
src = GlTail::Source::Local.new(@config)
elsif data['source'] && data['source'].downcase == 'tshark'
src = GlTail::Source::TShark.new(@config)
Expand Down
42 changes: 42 additions & 0 deletions lib/gl_tail/sources/command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module GlTail
module Source

class Command < Base
config_attribute :source, "The type of Source"
config_attribute :command, "The command to run"

def init
@lines = []
Thread.new do #start thread
begin
puts "Running command #{command}"
PTY.spawn( command ) do |stdin, stdout, pid|
begin
# Do stuff with the output here. Just printing to show it works
stdin.each { |line|
@lines.push(line)
}
rescue Errno::EIO
# puts "Errno:EIO error, but this probably just means " +
# "that the process has finished giving output"
end
end
rescue PTY::ChildExited
puts "Command has exited!"
end
end #end thread
end

def process
unless @lines.length == 0
parser.parse(@lines[0])
@lines.delete_at(0)
end
end

def update
end

end
end
end
1 change: 0 additions & 1 deletion lib/gl_tail/sources/tshark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'pty'
module GlTail
module Source

Expand Down

0 comments on commit 87f0c55

Please sign in to comment.