diff --git a/lib/gl_tail.rb b/lib/gl_tail.rb index f7f1c8c..2b0212d 100644 --- a/lib/gl_tail.rb +++ b/lib/gl_tail.rb @@ -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 diff --git a/lib/gl_tail/config/yaml_parser.rb b/lib/gl_tail/config/yaml_parser.rb index a30401d..9523888 100644 --- a/lib/gl_tail/config/yaml_parser.rb +++ b/lib/gl_tail/config/yaml_parser.rb @@ -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) diff --git a/lib/gl_tail/sources/command.rb b/lib/gl_tail/sources/command.rb new file mode 100644 index 0000000..c8ea8a5 --- /dev/null +++ b/lib/gl_tail/sources/command.rb @@ -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 \ No newline at end of file diff --git a/lib/gl_tail/sources/tshark.rb b/lib/gl_tail/sources/tshark.rb index c57c76c..85a93c0 100644 --- a/lib/gl_tail/sources/tshark.rb +++ b/lib/gl_tail/sources/tshark.rb @@ -1,4 +1,3 @@ -require 'pty' module GlTail module Source