koma 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/koma.gemspec +2 -2
- data/lib/koma/cli.rb +53 -2
- data/lib/koma/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6e94b0bc0d4e9b4bbdfefeb510bbc4b7eb2a429
|
4
|
+
data.tar.gz: 5f13188a65d9397006317c93f61ad8de3cdec855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
##
|
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`)
|
data/koma.gemspec
CHANGED
@@ -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
|
13
|
-
spec.description = 'Koma
|
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
|
|
data/lib/koma/cli.rb
CHANGED
@@ -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(
|
94
|
+
puts YAML.dump(gathered)
|
95
|
+
elsif options[:csv]
|
96
|
+
puts csv_dump(host, gathered)
|
86
97
|
else
|
87
|
-
puts JSON.pretty_generate(
|
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
|
data/lib/koma/version.rb
CHANGED
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.
|
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:
|
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
|
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.
|
239
|
+
rubygems_version: 2.6.14
|
239
240
|
signing_key:
|
240
241
|
specification_version: 4
|
241
|
-
summary: Koma
|
242
|
+
summary: Koma is an inventory monitoring tool that doesn’t require agent installation
|
243
|
+
on the sever side.
|
242
244
|
test_files: []
|