koma 0.15.0 → 0.16.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f46ff7aca0cb294d271c2303a06e036ca557b4d1
4
- data.tar.gz: 889bcf68fefb14832aa53709621dcd844a1c4e60
3
+ metadata.gz: b6e94b0bc0d4e9b4bbdfefeb510bbc4b7eb2a429
4
+ data.tar.gz: 5f13188a65d9397006317c93f61ad8de3cdec855
5
5
  SHA512:
6
- metadata.gz: 6fcbb276e6518cbe64883858c3f49485a3607f0111b25513828af277ea2dd248d1ba55c20c250adde0b4c6734c3b25ff864db7939e309b92c8d7832bdf0c38f9
7
- data.tar.gz: f91c31e0247d7667dc06b29bec966de40c3b7ea168ae22363f1f09252310dda4983c37589917c48bfa1d3665d82b394fe7d28a23c49c1d14d9fdc5c188212a91
6
+ metadata.gz: df23263ecc1afab1281963073e9497b49f7ce2affdf6e27dd328efb1a9b2b1dfc8547436371aa37e572b87a269a101d858bbaddd8d2925f4ca04f8ddbb261533
7
+ data.tar.gz: d97c9d07b2d7405239a16223d43d545c2bb34a3c6f3430f141f2026379bf1cf7511be28bd38946705738715c4c9fde4ed1e2fae400552ee4226946fc62ca4ead
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Koma [![Gem](https://img.shields.io/gem/v/koma.svg)](https://rubygems.org/gems/koma) [![Build Status](https://travis-ci.org/k1LoW/koma.svg?branch=master)](https://travis-ci.org/k1LoW/koma)
2
2
 
3
- Koma gather host inventory without agent.
3
+ Koma is an inventory monitoring tool that doesn’t require agent installation on the sever side.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add the following line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'koma'
@@ -132,7 +132,7 @@ group
132
132
  service
133
133
  ```
134
134
 
135
- ## Contributing
135
+ ## Contribution
136
136
 
137
137
  1. Fork it ( https://github.com/k1LoW/koma/fork )
138
138
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['k1LoW']
10
10
  spec.email = ['k1lowxb@gmail.com']
11
11
 
12
- spec.summary = 'Koma gather host inventory without agent.'
13
- spec.description = 'Koma gather host inventory without agent.'
12
+ spec.summary = 'Koma is an inventory monitoring tool that doesn’t require agent installation on the sever side.'
13
+ spec.description = 'Koma is an inventory monitoring tool that doesn’t require agent installation on the sever side.'
14
14
  spec.homepage = 'https://github.com/k1LoW/koma'
15
15
  spec.license = 'MIT'
16
16
 
@@ -1,6 +1,7 @@
1
1
  require 'thor'
2
2
  require 'json'
3
3
  require 'yaml'
4
+ require 'csv'
4
5
 
5
6
  module Koma
6
7
  class CLI < Thor
@@ -9,6 +10,7 @@ module Koma
9
10
  desc 'ssh <host1,host2,..>', 'stdout remote host inventory'
10
11
  option :key, type: :string, banner: '<key1,key2,..>', desc: 'inventory keys', aliases: :k
11
12
  option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :Y
13
+ option :csv, type: :boolean, desc: 'stdout CSV', aliases: :C
12
14
  option :identity_file, type: :string, banner: '<identity_file>', desc: 'identity file', aliases: :i
13
15
  option :port, type: :numeric, banner: '<port>', desc: 'port', aliases: :p
14
16
  Koma::HostInventory.disabled_keys.each do |key|
@@ -31,6 +33,8 @@ module Koma
31
33
  gathered = backend.gather
32
34
  if options[:yaml]
33
35
  puts YAML.dump(gathered)
36
+ elsif options[:csv]
37
+ puts csv_dump(host, gathered)
34
38
  else
35
39
  puts JSON.pretty_generate(gathered)
36
40
  end
@@ -38,6 +42,7 @@ module Koma
38
42
 
39
43
  desc 'run-command <host1,host2,..> <command1> <command2> ...', 'run command on remote hosts'
40
44
  option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :Y
45
+ option :csv, type: :boolean, desc: 'stdout CSV', aliases: :C
41
46
  option :identity_file, type: :string, banner: '<identity_file>', desc: 'identity file', aliases: :i
42
47
  option :port, type: :numeric, banner: '<port>', desc: 'port', aliases: :p
43
48
  def run_command(host = nil, *commands)
@@ -68,6 +73,8 @@ module Koma
68
73
  gathered = backend.run_commands(commands)
69
74
  if options[:yaml]
70
75
  puts YAML.dump(gathered)
76
+ elsif options[:csv]
77
+ puts csv_dump(host, gathered)
71
78
  else
72
79
  puts JSON.pretty_generate(gathered)
73
80
  end
@@ -76,15 +83,19 @@ module Koma
76
83
  desc 'exec', 'stdout local host inventory'
77
84
  option :key, type: :string, banner: '<key1,key2,..>', desc: 'inventory keys', aliases: :k
78
85
  option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :Y
86
+ option :csv, type: :boolean, desc: 'stdout CSV', aliases: :C
79
87
  Koma::HostInventory.disabled_keys.each do |key|
80
88
  option "enable-#{key}", type: :boolean, desc: "enable #{key}"
81
89
  end
82
90
  def exec
83
91
  backend = Koma::Backend::Exec.new(nil, options)
92
+ gathered = backend.gather
84
93
  if options[:yaml]
85
- puts YAML.dump(backend.gather)
94
+ puts YAML.dump(gathered)
95
+ elsif options[:csv]
96
+ puts csv_dump(host, gathered)
86
97
  else
87
- puts JSON.pretty_generate(backend.gather)
98
+ puts JSON.pretty_generate(gathered)
88
99
  end
89
100
  end
90
101
 
@@ -115,5 +126,45 @@ module Koma
115
126
  EOH
116
127
  puts message
117
128
  end
129
+
130
+ private
131
+
132
+ def csv_dump(hoststr, gathered)
133
+ hosts = hoststr.split(',')
134
+ if gathered.keys.sort == hosts.sort
135
+ header = ['host'] + gathered.values.first.keys
136
+ csv_data = CSV.generate() do |csv|
137
+ csv << header
138
+ gathered.each do |host, vals|
139
+ results = []
140
+ vals.each do |_, v|
141
+ if v.is_a?(Hash) && v.key?(:stdout) && v[:exit_status] == 0
142
+ results.push(v[:stdout])
143
+ else
144
+ results.push(v)
145
+ end
146
+ end
147
+ cols = [host] + results
148
+ csv << cols
149
+ end
150
+ end
151
+ else
152
+ header = ['host'] + gathered.keys
153
+ csv_data = CSV.generate() do |csv|
154
+ csv << header
155
+ results = []
156
+ gathered.values.each do |v|
157
+ if v.is_a?(Hash) && v.key?(:stdout) && v[:exit_status] == 0
158
+ results.push(v[:stdout])
159
+ else
160
+ results.push(v)
161
+ end
162
+ end
163
+ cols = [hoststr] + results
164
+ csv << cols
165
+ end
166
+ end
167
+ return csv_data
168
+ end
118
169
  end
119
170
  end
@@ -1,3 +1,3 @@
1
1
  module Koma
2
- VERSION = '0.15.0'
2
+ VERSION = '0.16.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -164,7 +164,8 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description: Koma gather host inventory without agent.
167
+ description: Koma is an inventory monitoring tool that doesn’t require agent installation
168
+ on the sever side.
168
169
  email:
169
170
  - k1lowxb@gmail.com
170
171
  executables:
@@ -235,8 +236,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
236
  version: '0'
236
237
  requirements: []
237
238
  rubyforge_project:
238
- rubygems_version: 2.2.2
239
+ rubygems_version: 2.6.14
239
240
  signing_key:
240
241
  specification_version: 4
241
- summary: Koma gather host inventory without agent.
242
+ summary: Koma is an inventory monitoring tool that doesn’t require agent installation
243
+ on the sever side.
242
244
  test_files: []