vagrant-logs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49e28a7c0aa315d741308b034b1832ce1c7ba03b
4
+ data.tar.gz: fecad9fe7923088f9be67e978663488727ebb321
5
+ SHA512:
6
+ metadata.gz: afc575872ae72d3a674b7f425a1b3339f7fd47e780400cb51eedd5bda88a7eacbbb89aaa889036b50644a5efef345183ead851446e836f0ccb4b4b020d017a23
7
+ data.tar.gz: 00a0d86e4b175d36f01ca4f5b688c097e82b5972e61a6110340ca9bb0c718f66a3e44313ffa7ffc22b645da82158179fee347fd2b77fff7df563b98a06289b2e
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .vagrant
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+
6
+ script:
7
+ - bundle exec rake test
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,11 @@
1
+ # Contributing
2
+
3
+ 1. Fork it
4
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
5
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
6
+ 4. Push to the branch (`git push origin my-new-feature`)
7
+ 5. Create new Pull Request
8
+
9
+ # publishing new release
10
+
11
+ Use `bundle exec rake release` to tag & publish a new release
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'gist'
6
+
7
+
8
+ group :development do
9
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
10
+ # gem "vagrant", git: "git://github.com/mitchellh/vagrant.git", tag: "v1.7.4"
11
+ # gem "vagrant", git: "git://github.com/mitchellh/vagrant.git", tag: "v1.3.5"
12
+
13
+ gem 'rubocop', require: false
14
+ end
15
+
16
+ group :plugins do
17
+ gem 'vagrant-logs', path: '.'
18
+ gem 'bib-vagrant'
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Till Klampaeckel, Florian Holzhauer, ImagineEasy Solutions LLC
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
22
+ OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # VagrantLogs
2
+
3
+ [![Build Status](https://travis-ci.org/easybiblabs/vagrant-logs.png?branch=master)](https://travis-ci.org/easybiblabs/vagrant-logs)
4
+ [![Coverage Status](https://coveralls.io/repos/easybiblabs/vagrant-status/badge.png)](https://coveralls.io/r/easybiblabs/vagrant-logs)
5
+
6
+ This is a work in progress - and subject to [additions and changes](CONTRIBUTING.md).
7
+
8
+ ## Objective
9
+
10
+ 1. Print several log information ...
11
+ 2. ...and / or upload them to a Gist.
12
+
13
+ ## Installation
14
+
15
+ Install the plugin:
16
+
17
+ $ vagrant plugin install vagrant-logs
18
+
19
+ Do not use this command in a directory with a Vagrantfile which requires the plugin. Vagrant does _always_ include the Vagrantfile, and therefore will fail before installation because of the missing plugin. Just ```cd``` somewhere else and retry the command, maybe from your homedir?
20
+
21
+ ## Usage
22
+
23
+ ### Gist upload
24
+
25
+ Upload to Gist can be activated by setting environment variable `GIST_UPLOAD`, e.g.:
26
+
27
+ `GIST_UPLOAD=true vagrant logs`
28
+
29
+ `GITHUB_TOKEN` must also be set as an environment variable.
30
+
31
+ ### Vagrantfile
32
+
33
+ In your `Vagrantfile`:
34
+
35
+ ```ruby
36
+ Vagrant.require_plugin 'vagrant-logs'
37
+
38
+ Vagrant.configure("2") do |config|
39
+ # list of log files
40
+ config.vagrant_logs.log_files = ['/var/log/*log']
41
+
42
+ # number of lines to log
43
+ config.vagrant_logs.lines = 5
44
+
45
+ # list of locally checked out repositories for which the current revision should be logged
46
+ config.vagrant_logs.repositories_to_check = ['~/Sites/easybib/cookbooks', '~/projects/ies/vagrant-logs']
47
+
48
+ # list of locally available clients to check for their versions
49
+ config.vagrant_logs.clients_to_check = ['vagrant', 'VBoxManage']
50
+ end
51
+ ```
52
+
53
+ ## Developing and Testing
54
+
55
+ Make sure you are using a Bundler version which is compatible with Vagrant which comes from GitHub like defined here:
56
+
57
+ ```
58
+ group :development do
59
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
60
+ end
61
+ ```
62
+
63
+ Bundler version 1.10.6 works fine and can be installed like this:
64
+
65
+ ```
66
+ gem install bundler -v '~> 1.10.6'
67
+ ```
68
+
69
+ Then, when you want to test Bib Vagrant use:
70
+
71
+ ```
72
+ bundle _1.10.6_ exec vagrant
73
+ ```
74
+
75
+ Happy developing and testing.
76
+
77
+ ## Contributing
78
+
79
+ See [Contributing](CONTRIBUTING.md)
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require 'minitest/autorun'
8
+
9
+ Encoding.default_external = Encoding::UTF_8
10
+ Encoding.default_internal = Encoding::UTF_8
11
+
12
+ # Immediately sync all stdout so that tools like buildbot can
13
+ # immediately load in the output.
14
+ $stdout.sync = true
15
+ $stderr.sync = true
16
+
17
+ # Change to the directory of this file.
18
+ Dir.chdir(File.expand_path("../", __FILE__))
19
+
20
+ # This installs the tasks that help with gem creation and
21
+ # publishing.
22
+ Bundler::GemHelper.install_tasks
23
+
24
+
25
+ task :test do
26
+ $LOAD_PATH.unshift('lib', 'test')
27
+ Dir.glob('./test/*_test.rb') do |f|
28
+ require f
29
+ end
30
+ end
data/Vagrantfile ADDED
@@ -0,0 +1,10 @@
1
+ Vagrant.configure('2') do |config|
2
+ # for testing ubuntu 14.04
3
+ config.vm.box = 'trusty-server-cloudimg-amd64-vagrant-disk1.box'
4
+ config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'
5
+
6
+ config.vagrant_logs.log_files = ['/var/log/*log']
7
+ config.vagrant_logs.lines = 5
8
+ # config.vagrant_logs.repositories_to_check = ['~/Sites/easybib/cookbooks']
9
+ config.vagrant_logs.clients_to_check = ['vagrant', 'VBoxManage']
10
+ end
@@ -0,0 +1,216 @@
1
+ require 'gist'
2
+
3
+
4
+ module VagrantPlugins
5
+ module CommandLogs
6
+ class Command < Vagrant.plugin('2', :command)
7
+ def self.synopsis
8
+ 'Print some log and information (and upload them to a Gist)'
9
+ end
10
+
11
+ def execute
12
+ result = {}
13
+
14
+ with_target_vms(@argv, single_target: true) do |vm|
15
+ prepare_log_file_names(vm)
16
+ result[:log_files] = fetch_log_files(vm)
17
+
18
+ result[:repository_revisions] = fetch_repository_revisions(vm)
19
+ result[:client_versions] = fetch_client_versions(vm)
20
+ result[:dns_resolution] = fetch_dns_resolution_check(vm)
21
+ end
22
+
23
+ result_as_string = result_to_string(result)
24
+
25
+ print result_as_string
26
+
27
+ if ENV['GIST_UPLOAD']
28
+ upload_to_gist(result_as_string, ENV['GITHUB_TOKEN'])
29
+ end
30
+
31
+ return 0
32
+ end
33
+
34
+
35
+ protected
36
+
37
+ def prepare_log_file_names(vm)
38
+ vm.config.vagrant_logs.log_files = expand_log_file_names(vm.config.vagrant_logs.log_files, vm)
39
+ end
40
+
41
+ def expand_log_file_names(log_files, vm)
42
+ puts "Expand files names: "
43
+
44
+ expanded_file_names = []
45
+
46
+ log_files.delete_if do |log_file|
47
+ if log_file.include?('*')
48
+ vm.communicate.sudo("ls -1 #{log_file}") do |type, data|
49
+ case type
50
+ when :stdout
51
+ expanded_file_names << data.split(/[\r\n]+/)
52
+ when :stderr
53
+ puts data and exit 1
54
+ end
55
+ end
56
+
57
+ true
58
+ end
59
+ end
60
+
61
+ puts "Ok\n"
62
+
63
+ (log_files + expanded_file_names).flatten
64
+ end
65
+
66
+ def fetch_log_files(vm)
67
+ puts "Fetch log files: "
68
+ result = {}
69
+
70
+ vm.config.vagrant_logs.log_files.each do |log_file|
71
+ vm.communicate.sudo("tail -#{vm.config.vagrant_logs.lines} #{log_file}") do |type, data|
72
+ case type
73
+ when :stdout
74
+ result[log_file] = data.split(/[\r\n]+/)
75
+ when :stderr
76
+ puts data and exit 1
77
+ end
78
+ end
79
+ end
80
+
81
+ puts "Ok\n"
82
+
83
+ result
84
+ end
85
+
86
+ def log_files_result_to_string(log_files_results)
87
+ result = "Log files\n"
88
+ result += "---------\n"
89
+
90
+ if log_files_results.nil?
91
+ result += "None fetched.\n"
92
+ else
93
+ log_files_results.each do |filename, log_file_results|
94
+ result += "#{filename}\n"
95
+ log_file_results.each do |log_file_result|
96
+ result += "#{log_file_result}\n"
97
+ end
98
+ result += "\n\n\n"
99
+ end
100
+ end
101
+
102
+ result + "\n"
103
+ end
104
+
105
+ def fetch_client_versions(vm)
106
+ result = {}
107
+
108
+ vm.config.vagrant_logs.clients_to_check.each do |client|
109
+ result[client] = `#{client} -v`
110
+ end
111
+
112
+ result
113
+ end
114
+
115
+ def client_versions_to_string(client_versions)
116
+ result = "Client versions\n"
117
+ result += "---------------\n"
118
+
119
+ if !client_versions.nil? and client_versions.any?
120
+ client_versions.each do |client, version|
121
+ result += "#{client}: #{version}\n"
122
+ end
123
+ else
124
+ result += "None checked.\n"
125
+ end
126
+
127
+ result + "\n"
128
+ end
129
+
130
+ def fetch_repository_revisions(vm)
131
+ result = {}
132
+
133
+ vm.config.vagrant_logs.repositories_to_check.each do |repository|
134
+ result[repository] = `(cd #{repository} && git rev-parse HEAD)`
135
+ end
136
+
137
+ result
138
+ end
139
+
140
+ def repository_revisions_to_string(repository_revisions)
141
+ result = "Repository revisions\n"
142
+ result += "--------------------\n"
143
+
144
+ if !repository_revisions.nil? and repository_revisions.any?
145
+ repository_revisions.each do |repository, revision|
146
+ result += "#{repository}: #{revision}\n"
147
+ end
148
+ else
149
+ result += "None checked.\n"
150
+ end
151
+
152
+ result + "\n"
153
+ end
154
+
155
+ def fetch_dns_resolution_check(vm)
156
+ puts "DNS resolution check: "
157
+
158
+ result = ''
159
+
160
+ vm.communicate.sudo("host -t ns google.com") do |type, data|
161
+ case type
162
+ when :stdout
163
+ result = data
164
+ when :stderr
165
+ puts data and exit 1
166
+ end
167
+ end
168
+
169
+ puts "Ok\n"
170
+
171
+ !result.include?('no servers could be reached')
172
+ end
173
+
174
+ def dns_resolution_result_to_string(dns_resolution)
175
+ result = "DNS resolution\n"
176
+ result += "--------------\n"
177
+
178
+ if dns_resolution == true
179
+ result += "Fine, works.\n"
180
+ elsif dns_resolution == false
181
+ result += "Doesn't seem to work.\n"
182
+ else
183
+ result += "Not checked.\n"
184
+ end
185
+
186
+ result + "\n"
187
+ end
188
+
189
+ def result_to_string(result)
190
+ repository_revisions_to_string(result[:repository_revisions]) +
191
+ client_versions_to_string(result[:client_versions]) +
192
+ dns_resolution_result_to_string(result[:dns_resolution]) +
193
+ log_files_result_to_string(result[:log_files])
194
+ end
195
+
196
+ def upload_to_gist(result, access_token)
197
+ puts "Gist upload\n"
198
+ puts "-----------\n"
199
+
200
+ if access_token.nil? or access_token.empty?
201
+ puts "Access token is missing (ENV['GITHUB_TOKEN']).\n"
202
+ else
203
+ gist = Gist.gist(result, filename: Time.now.to_i.to_s, access_token: access_token)
204
+
205
+ if gist
206
+ puts "Url: #{gist['html_url']}\n"
207
+ else
208
+ puts "Upload failed.\n"
209
+ end
210
+ end
211
+
212
+ puts "\n"
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,31 @@
1
+ module VagrantPlugins
2
+ module CommandLogs
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :log_files
5
+ attr_accessor :lines
6
+ attr_accessor :repositories_to_check
7
+ attr_accessor :clients_to_check
8
+
9
+
10
+ def initialize
11
+ @log_files = UNSET_VALUE
12
+ @lines = UNSET_VALUE
13
+ @repositories_to_check = UNSET_VALUE
14
+ @clients_to_check = UNSET_VALUE
15
+ end
16
+
17
+ def finalize!
18
+ if @log_files == UNSET_VALUE
19
+ @log_files = %w(/var/log/syslog /var/log/nginx/*log /var/log/php/*log .vagrant.d/data/landrush/log)
20
+ end
21
+
22
+ @lines = 50 if @lines == UNSET_VALUE
23
+
24
+ config = Bib::Vagrant::Config.new
25
+ @repositories_to_check = [config.get['cookbook_path']] || [] if @repositories_to_check == UNSET_VALUE
26
+
27
+ @clients_to_check = ['vagrant', 'VBoxManage'] if @clients_to_check == UNSET_VALUE
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module CommandLogs
3
+ class Plugin < Vagrant.plugin('2')
4
+ name 'vagrant-logs'
5
+
6
+ description 'Plugin allows printing logs or save them to a Gist'
7
+
8
+ command 'logs' do
9
+ require_relative 'command'
10
+ Command
11
+ end
12
+
13
+ config 'vagrant_logs' do
14
+ require_relative 'config'
15
+ Config
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module CommandLogs
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'vagrant-logs/command'
2
+ require 'vagrant-logs/config'
3
+ require 'vagrant-logs/plugin'
4
+ require 'vagrant-logs/version'
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'vagrant-logs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vagrant-logs'
8
+ spec.version = VagrantPlugins::CommandLogs::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = %w('seppsepp', 'fh')
11
+ spec.email = ['sebastian.lenk@gmail.com']
12
+ spec.description = 'A RubyGem to print log files and/or upload them to a Gist'
13
+ spec.summary = 'Print log files and/or upload to Gist'
14
+ spec.homepage = 'https://github.com/easybiblabs/vagrant-logs'
15
+ spec.license = 'New BSD License'
16
+
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'gist'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest', '~> 5.0.8'
27
+ spec.add_development_dependency 'coveralls'
28
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "'seppsepp',"
8
+ - "'fh'"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gist
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 5.0.8
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 5.0.8
70
+ - !ruby/object:Gem::Dependency
71
+ name: coveralls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: A RubyGem to print log files and/or upload them to a Gist
85
+ email:
86
+ - sebastian.lenk@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CONTRIBUTING.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - Vagrantfile
99
+ - lib/vagrant-logs.rb
100
+ - lib/vagrant-logs/command.rb
101
+ - lib/vagrant-logs/config.rb
102
+ - lib/vagrant-logs/plugin.rb
103
+ - lib/vagrant-logs/version.rb
104
+ - vagrant-logs.gemspec
105
+ homepage: https://github.com/easybiblabs/vagrant-logs
106
+ licenses:
107
+ - New BSD License
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Print log files and/or upload to Gist
129
+ test_files: []