log_view 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e838a3daf5bcdc1c3be148824b962eaff711923
4
+ data.tar.gz: df455375c1b94c9bbbe8c7635f4c164cbeffc97f
5
+ SHA512:
6
+ metadata.gz: ef8f11c911728a6c80f8c0b41125b37abab31b0eb36f65d3f473360581198442f54943d1443d3e14b35883cf5d4e6a66f2166d2343ee48791ed5c6a813d8a0ef
7
+ data.tar.gz: 3cf9d280776b7ccc186b3cce97ed6fb189c8a3d0ff18bb3452a0684d81f64fcf876e743f64f18c04f155a340e0e67150e3c3ee5c2b9e60f876b80ba7f7b1f999
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in log_view.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ log_view (0.0.1)
5
+ net-ssh (>= 2.8.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (3.1.2)
11
+ columnize (~> 0.8)
12
+ debugger-linecache (~> 1.2)
13
+ columnize (0.8.9)
14
+ debugger-linecache (1.2.0)
15
+ diff-lcs (1.2.5)
16
+ net-ssh (2.8.0)
17
+ rake (10.3.0)
18
+ rspec (2.14.1)
19
+ rspec-core (~> 2.14.0)
20
+ rspec-expectations (~> 2.14.0)
21
+ rspec-mocks (~> 2.14.0)
22
+ rspec-core (2.14.8)
23
+ rspec-expectations (2.14.5)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.14.6)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.6)
32
+ byebug
33
+ log_view!
34
+ rake
35
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,53 @@
1
+ <<<<<<< HEAD
2
+ <<<<<<< HEAD
3
+ Copyright (c) 2014 marcos.ocf01
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ =======
26
+ =======
27
+ >>>>>>> 91cd8985ee4d86da6b004537697792ed202fbf42
28
+ The MIT License (MIT)
29
+
30
+ Copyright (c) 2014 MarcosOcf
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all
40
+ copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48
+ <<<<<<< HEAD
49
+ SOFTWARE.
50
+ >>>>>>> cd84c66e6ad6861c3c926fafe54210708a1f3a30
51
+ =======
52
+ SOFTWARE.
53
+ >>>>>>> 91cd8985ee4d86da6b004537697792ed202fbf42
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # LogView
2
+
3
+ ## Installation
4
+
5
+ Execute
6
+
7
+ ```sh
8
+ $ gem install log_view
9
+ ```
10
+
11
+ ## Getting Started
12
+
13
+ 1. Execute $ log_view
14
+
15
+ The software will create a .log_view.yml file in your home
16
+
17
+ 2. Configure the .log_view.yml file as the described exemple in the .log_view.yml file
18
+
19
+ 3. Run:
20
+
21
+ ```sh
22
+ $ log_view
23
+ ```
24
+
25
+ This step will show your configured projects.
26
+
27
+ Use the described options in the output of third step to perform your
28
+
29
+ ```sh
30
+ $ log_view <project-name> <options>
31
+ ```
32
+ ## Help
33
+
34
+ Execute command line without parameters
35
+
36
+ ```sh
37
+ $ log_view
38
+ ```
39
+ ## Basic Commands
40
+
41
+ log_view gem offers four commands
42
+
43
+ 1. **--split-log**
44
+
45
+ The split-log option
46
+
47
+ This command will separate log by file and server
48
+
49
+ ```sh
50
+ $ log_view <project_name> --split-log
51
+ ```
52
+ 2. **--grep**
53
+
54
+ The grep option
55
+
56
+ This is the basic grep function.
57
+
58
+ You should write like:
59
+
60
+ ```sh
61
+ $ log_view <project_name> --grep <grep_string>
62
+ ```
63
+ 3. **-s**
64
+
65
+ The choose server option
66
+
67
+ This command allow you to choose a single server to monitoring
68
+
69
+ ```sh
70
+ $ log_view <project_name> -s <server name>
71
+ ```
72
+
73
+ You can write any single parts of server's name. Like this exemple:
74
+
75
+ ```yaml
76
+ project_name1:
77
+ user: a
78
+ password: b
79
+ servers:
80
+ - test-server1
81
+ - test-server2
82
+ files:
83
+ - test-file1
84
+ - test-file2
85
+ ```
86
+ ```sh
87
+ $ log_view project_name1 -s server1
88
+ ```
89
+
90
+ 4. **-f**
91
+
92
+ The choose file option
93
+
94
+ This command allow you to choose a single file to monitoring
95
+
96
+ ```sh
97
+ $ log_view <project_name> -f <file name>
98
+ ```
99
+
100
+ You can write any single parts of file's name. Like this exemple:
101
+
102
+ ```yaml
103
+ project_name1:
104
+ user: a
105
+ password: b
106
+ servers:
107
+ - test-server1
108
+ - test-server2
109
+ files:
110
+ - test-file1
111
+ - test-file2
112
+ ```
113
+ ```sh
114
+ $ log_view project_name1 -f file1
115
+ ```
116
+
117
+
118
+
119
+
120
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/log_view ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'log_view'
4
+
5
+ config = LogView::Config.new
6
+ command = LogView::Command.new(config, ARGV)
7
+ command.boot!
@@ -0,0 +1,23 @@
1
+ module LogView
2
+ module Colors
3
+ COLOR_CODES = {
4
+ green: 32,
5
+ red: 31,
6
+ blue: 34,
7
+ yellow: 33,
8
+ light_blue: 36,
9
+ pink: 35
10
+ }
11
+
12
+ COLOR_CODES.each_pair do |color, code|
13
+ define_method("paint_#{color}") { |string|
14
+ paint code, string
15
+ }
16
+ end
17
+
18
+ def paint color_code, string
19
+ "\e[#{color_code}m#{string}\e[0m"
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ module LogView
2
+ class Command
3
+ include LogView::Colors
4
+
5
+ def initialize config, argv = nil
6
+ @config = config
7
+ @array = argv.compact.map(&:strip).reject {|s| s.empty?}
8
+ end
9
+
10
+ def boot!
11
+ if @array.nil? or @array.empty?
12
+ puts help
13
+ return
14
+ end
15
+
16
+ project_name = @array.first
17
+ project_config = @config.load_project(project_name)
18
+ project_opts = OptParser.new.parse @array, project_config
19
+
20
+ do_ssh = DoTail.new(project_name, project_opts)
21
+
22
+ trap("SIGINT") {
23
+ print "\nClosing... "
24
+ do_ssh.close
25
+ print "that's all folks!\n"
26
+ exit!
27
+ }
28
+
29
+ do_ssh.start
30
+ end
31
+
32
+ private
33
+ def help
34
+ array = []
35
+ array << "LogView version #{VERSION}"
36
+ array << "Configuration file at: #{paint_green(Config.config_file_path)}"
37
+ array << "Projects:"
38
+ projects = @config.projects || []
39
+ if projects.empty?
40
+ array << " No projects configured, please take a look at the configuration file"
41
+ else
42
+ projects.each do |project|
43
+ array << " - #{project}"
44
+ end
45
+ end
46
+ array << "\nHelp:"
47
+ array << " $ lg_vw <project_name>"
48
+ array << "\n"
49
+ array << " $ lg_vw <project_name> --grep <string-name>"
50
+ array << "\n"
51
+ array << " $ lg_vw <project_name> --split-log"
52
+ array << "\n"
53
+ array << " $ lg_vw <project_name> -s <server-name>"
54
+ array << "\n"
55
+ array << " $ lg_vw <project_name> -f <file-name>"
56
+ array << "\n"
57
+ array.join("\n")
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,40 @@
1
+ module LogView
2
+ class Config
3
+ extend Forwardable
4
+
5
+ CONFIG_FILE_NAME = ".log_view.yml"
6
+ CONFIG_SAMPLE = %Q{
7
+ # This is a sample, please fill the options with your own configurations
8
+ #
9
+ #
10
+ # project_name:
11
+ # user: my_ssh_user
12
+ # password: my_ssh_password
13
+ # servers:
14
+ # - some_name@some_server.com
15
+ # files:
16
+ # - "/log/dir/my_log_file.log"
17
+ #
18
+ }
19
+ def_delegators :@project, :user, :password, :servers, :files
20
+ attr_reader :projects
21
+
22
+ def initialize
23
+ path = Config.config_file_path
24
+ File.open(path, "w") {|f| f.write(CONFIG_SAMPLE)} unless File.exists?(path)
25
+
26
+ hash = YAML.load_file(path)
27
+ @projects = hash ? hash.keys : []
28
+ @config = OpenStruct.new(hash)
29
+ end
30
+
31
+ def load_project name
32
+ project_config = @config.send("#{name}")
33
+ OpenStruct.new(project_config)
34
+ end
35
+
36
+ def self.config_file_path
37
+ File.join(Dir.home, CONFIG_FILE_NAME)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,58 @@
1
+ module LogView
2
+ class DoSSH
3
+ include LogView::Colors
4
+
5
+ def initialize project, obj_config
6
+ @project = project.to_s
7
+ @thread_array = []
8
+ @should_close = false
9
+ @obj_config = obj_config
10
+ end
11
+
12
+ def start
13
+ each_server do |server|
14
+ run_on_server(server) {|session, file|
15
+
16
+ exec session, server, file
17
+
18
+ }
19
+ end
20
+ end
21
+
22
+ def close
23
+ @should_close = true
24
+ @thread_array.map(&:exit)
25
+ end
26
+
27
+ protected
28
+ def execute_command server, channel, file
29
+ raise NotImplementedError.new
30
+ end
31
+
32
+ private
33
+ def each_server &block
34
+ @obj_config.servers.each {|server| @thread_array << block.call(server)}
35
+ @thread_array.map(&:join)
36
+ end
37
+
38
+ def run_on_server server, &block
39
+ Thread.new {
40
+ Net::SSH.start(server, @obj_config.user, password: @obj_config.password) do |session|
41
+ @obj_config.files.each {|file| block.call(session, file)}
42
+ session.loop { not @should_close }
43
+ end
44
+ }
45
+ end
46
+
47
+ def exec session, server, file
48
+ session.open_channel do |channel|
49
+ channel.request_pty do |ch|
50
+
51
+ execute_command server, channel, file
52
+
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,27 @@
1
+ module LogView
2
+ class DoTail < DoSSH
3
+ include LogView::Colors
4
+
5
+ protected
6
+ def execute_command server, channel, file
7
+ channel.on_data {|ch, data| puts create_split(data, server, file)}
8
+ puts channel.exec(" tail -f #{file}" + @obj_config.grep_string + "\n")
9
+ end
10
+
11
+ private
12
+ def create_split data, server, file
13
+ if @obj_config.options.split_log == true
14
+ string = "\n[#{paint(32, server)}:#{paint(33,file)}]:\n#{data}\n"
15
+ else
16
+ string = ":\n#{data}\n"
17
+ end
18
+
19
+ string
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+
26
+
27
+
@@ -0,0 +1,75 @@
1
+ module LogView
2
+ class OptParser
3
+ include LogView::Colors
4
+
5
+ def initialize
6
+ @options = OpenStruct.new
7
+ apply_defaults
8
+ end
9
+
10
+ def parse args, config
11
+ opt_parser = new_opt_parser @options
12
+ opt_parser.parse!(args)
13
+ generate_config config
14
+ end
15
+
16
+ private
17
+ def apply_defaults
18
+ @options.grep = false
19
+ @options.split_log = false
20
+ @options.if_files = false
21
+ @options.if_server = false
22
+ end
23
+
24
+ def new_opt_parser options
25
+ OptionParser.new do |opts|
26
+ opts.on("--grep","--grep string", String) {|grep|
27
+ options.grep = true
28
+ options.grep_string = grep
29
+ }
30
+
31
+ opts.on("--split-log") {
32
+ options.split_log = true
33
+ }
34
+
35
+ opts.on("-f","--file string", String) {|file|
36
+ options.if_files = true
37
+ options.files = file
38
+ }
39
+
40
+ opts.on("-s", "--server string", String) {|server|
41
+ options.if_server = true
42
+ options.server = server
43
+ }
44
+ end
45
+ end
46
+
47
+ def generate_config config
48
+ config.tap do |conf|
49
+ conf.options = @options
50
+ create_grep conf
51
+ create_files conf
52
+ create_servers conf
53
+ end
54
+ end
55
+
56
+ def create_grep config
57
+ config.grep_string = ""
58
+ config.grep_string << " | grep --color=always #{config.options.grep_string}" if config.options.grep
59
+ end
60
+
61
+ def create_files config
62
+ return unless config.options.if_files
63
+
64
+ config.files = config.files.select {|file| file.include?(config.options.files.to_s)}
65
+ puts paint_red("\tWarning -- no files with #{config.options.files.to_s}") if config.files.empty?
66
+ end
67
+
68
+ def create_servers config
69
+ return unless config.options.if_server
70
+
71
+ config.servers = config.servers.select {|server| server.include?(config.options.server.to_s)}
72
+ puts paint_red("\tWarning -- no servers with #{config.options.server.to_s}") if config.servers.empty?
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module LogView
2
+ VERSION = "0.0.1"
3
+ end
data/lib/log_view.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+ require 'net/ssh'
4
+ require 'forwardable'
5
+ require 'optparse'
6
+ require "log_view/version"
7
+ require "log_view/colors"
8
+ require "log_view/do_ssh"
9
+ require "log_view/do_tail"
10
+ require "log_view/config"
11
+ require "log_view/command"
12
+ require "log_view/option_parser"
13
+
14
+ module LogView
15
+ end
data/log_view.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'log_view/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "log_view"
8
+ spec.version = LogView::VERSION
9
+ spec.authors = ["marcos.ocf01"]
10
+ spec.email = ["marcos.ocf01@gmail.com"]
11
+ spec.summary = %q{log_view is a parallel monitoring logs gem}
12
+ spec.description = %q{log_view is a parallel monitoring logs gem who uses ssh connection to make tail on described files in multiple servers.
13
+
14
+ }
15
+ spec.homepage = "https://github.com/MarcosOcf/log_view"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "net-ssh", "~> 2.8.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.3.0"
27
+ spec.add_development_dependency "rspec", "~> 2.14.1"
28
+ spec.add_development_dependency "byebug", "~> 3.1.2"
29
+ end
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe LogView::Command do
4
+ before do
5
+ LogView::Config.stub(:config_file_path).and_return("spec/fixtures/config.yml")
6
+ end
7
+
8
+ before do
9
+ LogView::DoTail.stub(:start).and_return true
10
+ end
11
+
12
+ let :config do
13
+ LogView::Config.new
14
+ end
15
+
16
+ let :project_name do
17
+ "project_name1"
18
+ end
19
+
20
+ let :args do
21
+ [project_name, '--grep', nil, nil, nil,'string', nil, '--split-log'," " '-s', 'test-server1', '-f', 'test-file1']
22
+ end
23
+
24
+ describe 'initialize' do
25
+ it 'teste' do
26
+ #config = LogView::Config.new
27
+ init = LogView::Command.new(config, args)
28
+ init.instance_of?(LogView::Command).should eql true
29
+ end
30
+ end
31
+
32
+ describe '#boot!' do
33
+ subject do
34
+ LogView::Command.new(config, args)
35
+ end
36
+
37
+ before do
38
+ LogView::DoTail.stub(:start).and_return true
39
+ end
40
+
41
+ describe 'empty array' do
42
+ subject do
43
+ LogView::Command.new(config, [])
44
+ end
45
+
46
+ it 'should call help' do
47
+ subject.boot!.should eql nil
48
+ end
49
+ end
50
+
51
+ describe 'nil array' do
52
+ subject do
53
+ LogView::Command.new(config, [nil])
54
+ end
55
+
56
+ it 'should call help' do
57
+ subject.boot!.should eql nil
58
+ end
59
+ end
60
+
61
+ describe 'args array' do
62
+ subject do
63
+ LogView::Command.new(config, args)
64
+ end
65
+
66
+ let :obj do
67
+ double("DoTail")
68
+ end
69
+
70
+ before do
71
+ obj.stub(:new).and_return(obj)
72
+ obj.stub(:start).and_return(true)
73
+ end
74
+
75
+ before do
76
+ LogView::DoTail.stub(:new).and_return(obj)
77
+ end
78
+
79
+ it 'should call start' do
80
+ subject.boot!.should eql true
81
+ end
82
+ end
83
+
84
+ describe 'help' do
85
+
86
+ before do
87
+ LogView::Command.stub(:help).and_return true
88
+ end
89
+
90
+ it 'Should call help function' do
91
+ LogView::Command.send(:help).should eql true
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe LogView::Config do
4
+
5
+ describe "initialize" do
6
+ describe "if file exists" do
7
+ before do
8
+ LogView::Config.stub(:config_file_path).and_return("spec/fixtures/config.yml")
9
+ end
10
+
11
+ subject do
12
+ LogView::Config.new
13
+ end
14
+
15
+ it "projects" do
16
+ subject.projects.should eql ["project_name1", "project_name2"]
17
+ end
18
+ end
19
+
20
+ describe "if file not exists" do
21
+ before do
22
+ LogView::Config.stub(:config_file_path).and_return("spec/fixtures/config2.yml")
23
+ end
24
+
25
+ after do
26
+ FileUtils.rm_f "spec/fixtures/config2.yml"
27
+ end
28
+
29
+ it "projects" do
30
+ subject.projects.should eql []
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#load_project" do
36
+ before do
37
+ LogView::Config.stub(:config_file_path).and_return("spec/fixtures/config.yml")
38
+ end
39
+
40
+ let :config do
41
+ LogView::Config.new
42
+ end
43
+
44
+ let :project_name do
45
+ "project_name1"
46
+ end
47
+
48
+ subject do
49
+ config.load_project project_name
50
+ end
51
+
52
+ it "attributes test" do
53
+ subject.should_not be_nil
54
+ subject.should respond_to :user
55
+ subject.should respond_to :password
56
+ subject.should respond_to :servers
57
+ subject.should respond_to :files
58
+ subject.user.should eql "a"
59
+ subject.password.should eql "b"
60
+ subject.files.should eql ["test-file1","test-file2"]
61
+ subject.servers.should eql ["test-server1","test-server2"]
62
+ end
63
+ end
64
+ describe "config_file_path" do
65
+ let :home_path do
66
+ "/home/do/usuario"
67
+ end
68
+
69
+ before do
70
+ Dir.stub(:home).and_return(home_path)
71
+ end
72
+
73
+ it "test of directories" do
74
+ LogView::Config.config_file_path.should eql "#{home_path}/#{LogView::Config::CONFIG_FILE_NAME}"
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe LogView::DoSSH do
4
+
5
+ let :project do
6
+ 'project_name1'
7
+ end
8
+
9
+ let :obj_config do
10
+ double "obj_config"
11
+ end
12
+
13
+ subject do
14
+ LogView::DoSSH.new project, obj_config
15
+ end
16
+
17
+ describe "initialize" do
18
+
19
+ it "should configure project" do
20
+ subject.instance_variable_get(:@project).should eql 'project_name1'
21
+ end
22
+ it "should define should_close false" do
23
+ subject.instance_variable_get(:@should_close).should eql false
24
+ end
25
+ end
26
+
27
+ describe "close function" do
28
+
29
+ let :thread1 do
30
+ double "Thread.new"
31
+ end
32
+
33
+ let :thread2 do
34
+ double "Thread.new"
35
+ end
36
+
37
+ describe "on first step" do
38
+
39
+ it "should define should_close true" do
40
+ subject.close
41
+ subject.instance_variable_get(:@should_close).should eql true
42
+ end
43
+ end
44
+
45
+ describe "on second step" do
46
+
47
+ before do
48
+ thread1.should_receive(:exit)
49
+ thread2.should_receive(:exit)
50
+ end
51
+
52
+ it "should call exit for all threads" do
53
+ subject.instance_variable_set(:@thread_array, [thread1, thread2])
54
+ subject.close
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "start function" do
60
+
61
+ # let :obj_config do
62
+ # OpenStruct.new
63
+ # end
64
+
65
+ # let :files do
66
+ # ["test-file1", "test-file2"]
67
+ # end
68
+
69
+ # let :servers do
70
+ # ["test-server1", "test-server2"]
71
+ # end
72
+
73
+ # before do
74
+ # Net::SSH.stub(:start) do |server, user, hash|
75
+ # puts "===========> ei"
76
+ # puts [server, user, hash].inspect
77
+
78
+ # end
79
+
80
+ # obj_config.servers = servers
81
+ # end
82
+
83
+ it "should receive execute command" do
84
+ # subject.should_receive(:execute_command)
85
+ # subject.start
86
+ pending
87
+ end
88
+
89
+ end
90
+ end
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe LogView::DoTail do
4
+
5
+ let :project do
6
+ 'project_name1'
7
+ end
8
+
9
+ let :data do
10
+ 'data_string_exemple'
11
+ end
12
+
13
+ let :server do
14
+ 'test-server1'
15
+ end
16
+
17
+ let :file do
18
+ 'test-file1'
19
+ end
20
+
21
+ describe "initialize" do
22
+ let :project do
23
+ "choosen_project"
24
+ end
25
+ let :obj_config do
26
+ "configures_object"
27
+ end
28
+
29
+ subject do
30
+ LogView::DoTail.new project, obj_config
31
+ end
32
+
33
+ it "should return instance_of DoTail" do
34
+ dotail = LogView::DoTail.new project, obj_config
35
+ dotail.instance_of?(LogView::DoTail).should eql true
36
+ end
37
+ end
38
+
39
+ describe "create_split" do
40
+
41
+ let :obj_config do
42
+ OpenStruct.new
43
+ end
44
+
45
+ let :options do
46
+ OpenStruct.new
47
+ end
48
+
49
+ before do
50
+ options.split_log = true
51
+ obj_config.options = options
52
+ end
53
+ subject do
54
+ LogView::DoTail.new project, obj_config
55
+ end
56
+ COLOR_CODES = {
57
+ green: 32,
58
+ yellow: 33
59
+ }
60
+
61
+ def paint color_code, string
62
+ "\e[#{color_code}m#{string}\e[0m"
63
+ end
64
+
65
+ it 'should split LogView by server and file' do
66
+ subject.send(:create_split, data, server, file).should eql "\n[#{paint(32, server)}:#{paint(33,file)}]:\n#{data}\n"
67
+ end
68
+ end
69
+
70
+ describe 'execute_command' do
71
+
72
+ let :obj_config do
73
+ OpenStruct.new
74
+ end
75
+
76
+ subject do
77
+ LogView::DoTail.new project, obj_config
78
+ end
79
+
80
+ let :create_split do
81
+ double "create_split"
82
+ end
83
+
84
+ let :channel do
85
+ double "channel"
86
+ end
87
+
88
+ let :data do
89
+ double "data"
90
+ end
91
+
92
+ let :test_string do
93
+ ' grep string test '
94
+ end
95
+
96
+ before do
97
+ obj_config.grep_string = ''
98
+ end
99
+
100
+ before do
101
+ channel.stub(:on_data).and_return true
102
+ channel.stub(:exec).and_return test_string
103
+ STDOUT.should_receive(:puts).with(test_string)
104
+ end
105
+
106
+ it 'should call create_split 1 time' do
107
+ subject.send(:execute_command, server, channel, file)
108
+ end
109
+
110
+ end
111
+ end
112
+
113
+
114
+
115
+
116
+
@@ -0,0 +1,19 @@
1
+ project_name1:
2
+ user: a
3
+ password: b
4
+ servers:
5
+ - test-server1
6
+ - test-server2
7
+ files:
8
+ - test-file1
9
+ - test-file2
10
+
11
+ project_name2:
12
+ user: a
13
+ password: b
14
+ servers:
15
+ - test-server1
16
+ - test-server2
17
+ files:
18
+ - test-file1
19
+ - test-file2
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe LogView::OptParser do
4
+ let :project_name do
5
+ "project_name1"
6
+ end
7
+
8
+ before do
9
+ LogView::Config.stub(:config_file_path).and_return("spec/fixtures/config.yml")
10
+ config.load_project project_name
11
+ end
12
+
13
+ let :config do
14
+ LogView::Config.new
15
+ end
16
+
17
+ let :args do
18
+ [project_name, '--grep', 'string', '--split-log', '-s', 'test-server1', '-f', 'test-file1']
19
+ end
20
+ subject do
21
+ LogView::OptParser.new.parse(args, config.load_project(project_name))
22
+ end
23
+
24
+ describe "#parse" do
25
+
26
+ it "grep test" do
27
+ subject.grep_string.should eql " | grep --color=always string"
28
+ end
29
+
30
+ it "split-log test" do
31
+ subject.options.split_log.should eql true
32
+ end
33
+
34
+ describe 'choosing existent' do
35
+ it "file test" do
36
+ subject.options.if_files.should eql true
37
+ subject.options.files.should eql 'test-file1'
38
+ end
39
+
40
+ it "servers test" do
41
+ subject.options.if_server.should eql true
42
+ subject.options.server.should eql 'test-server1'
43
+ end
44
+ end
45
+
46
+ describe 'choosing inexistent' do
47
+ let :args do
48
+ [project_name, '--grep', 'string', '--split-log', '-s', 'test-server10', '-f', 'test-file10']
49
+ end
50
+
51
+ it 'file test' do
52
+ subject.options.if_files.should eql true
53
+ subject.options.files.should eql 'test-file10'
54
+ end
55
+
56
+ it 'server test' do
57
+ subject.options.if_server.should eql true
58
+ subject.options.server.should eql 'test-server10'
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http:
7
+
8
+ require "byebug"
9
+ require "log_view"
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - marcos.ocf01
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 10.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.2
83
+ description: "log_view is a parallel monitoring logs gem who uses ssh connection to
84
+ make tail on described files in multiple servers. \n\n "
85
+ email:
86
+ - marcos.ocf01@gmail.com
87
+ executables:
88
+ - log_view
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".DS_Store"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - bin/log_view
101
+ - lib/log_view.rb
102
+ - lib/log_view/colors.rb
103
+ - lib/log_view/command.rb
104
+ - lib/log_view/config.rb
105
+ - lib/log_view/do_ssh.rb
106
+ - lib/log_view/do_tail.rb
107
+ - lib/log_view/option_parser.rb
108
+ - lib/log_view/version.rb
109
+ - log_view.gemspec
110
+ - spec/.DS_Store
111
+ - spec/command_spec.rb
112
+ - spec/config_spec.rb
113
+ - spec/do_ssh_spec.rb
114
+ - spec/do_tail_spec.rb
115
+ - spec/fixtures/config.yml
116
+ - spec/option_parser_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/MarcosOcf/log_view
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: log_view is a parallel monitoring logs gem
142
+ test_files:
143
+ - spec/.DS_Store
144
+ - spec/command_spec.rb
145
+ - spec/config_spec.rb
146
+ - spec/do_ssh_spec.rb
147
+ - spec/do_tail_spec.rb
148
+ - spec/fixtures/config.yml
149
+ - spec/option_parser_spec.rb
150
+ - spec/spec_helper.rb