logstash-input-remote_proc 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dc453c833ce8e78a7d021ed114a74a8fd38aa8f
4
- data.tar.gz: 879f625f49a7ae91399abadc6849ef696e785a04
3
+ metadata.gz: 7c02140e9d9c51731875a6506a1bdd0186c50b5d
4
+ data.tar.gz: fcd1d2f715390bba9b4bb71fed8c065d968e5b94
5
5
  SHA512:
6
- metadata.gz: c38eea99b74cefcc1020f61d1790551b8f3f082e0d08d1aaaf864ada05b856ac83862ad17851318918bf48c0c5af3733ccb26e613414b4b74d872d4a40068e63
7
- data.tar.gz: 298988574d97df4e0b2f48619d9b401c8c6d9777409a2f44973b33bfbd0dd6fa4f04c279d23794591fd4fb1423c3023332b620ad27ffe5f6968da84d4246df50
6
+ metadata.gz: f36c5471a1bf132ae0ef534c931c241e29e7ac1af2ead1f21a24d1233f8f12d14506cf686fa89349d47c111c86c0af03274e78fac23c75c6e88f913a0df81157
7
+ data.tar.gz: d27e517f6d4fbf25c20ece9eb6d8e42978c3c9c8305827593565b376c032013f2edba659b222bce91cd57fd810270a9deb82b173968c813ad4f6d6ca25b2ac92
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.8
2
+ - Add 'proc_prefix_path' for each server.
3
+
1
4
  ## 0.1.7
2
5
  - Update CHANGELOG.md.
3
6
 
data/USAGE.md CHANGED
@@ -18,6 +18,8 @@ servers => [
18
18
  gateway_username => ${USER} || ${USERNAME} || 'nobody' # :string (default to unix $USER)
19
19
  gateway_password => ... # :string (needed if gateway_host is set and no 'ssh_private_key' is given), empty by default
20
20
  gateway_ssh_private_key => ... # :path (needed if no 'gateway_password'), empty by default
21
+ system_reader => "cat" # :string
22
+ proc_prefix_path => "/proc" # :string
21
23
  }
22
24
  ]
23
25
  ```
@@ -27,7 +29,7 @@ When no password is given, the private key path for both `host` and `gateway_hos
27
29
  **Default values for `proc_list`**
28
30
 
29
31
  ```logstash
30
- proc_list => ["cpuinfo", "meminfo", "loadavg", "vmstat", "diskstats", "netdev", "netwireless", "mounts", "crypto", "sysvipcshm"]
32
+ proc_list => ["cpuinfo", "stat", "meminfo", "loadavg", "vmstat", "diskstats", "netdev", "netwireless", "mounts", "crypto", "sysvipcshm"]
31
33
  ```
32
34
 
33
35
  If `proc_list` is not declared all of them are processed. An equivalent declaration is `proc_file => ["_all"]`.
@@ -35,75 +37,75 @@ If `proc_list` is not declared all of them are processed. An equivalent declarat
35
37
  ### SSH server with default values and authenticate by private key
36
38
 
37
39
  ```javascript
38
- input { remote_proc { servers => [{}] } }
40
+ input { remote_proc { servers => [{}] } }
39
41
  ```
40
42
 
41
43
  ### SSH server with default values and authenticate by private key for `cpuinfo` and `meminfo`
42
44
 
43
45
  ```javascript
44
- input { remote_proc { servers => [{}] proc_list => ["cpuinfo", "meminfo"] } }
46
+ input { remote_proc { servers => [{}] proc_list => ["cpuinfo", "meminfo"] } }
45
47
  ```
46
48
 
47
49
  ### With SSH server `host`, `port` and `username` and authenticate by private key
48
50
 
49
51
  ```javascript
50
- input {
51
- remote_proc {
52
- servers => [
53
- { host => "domain.com" port => 22 username => "fenicks" }
54
- ]
55
- }
52
+ input {
53
+ remote_proc {
54
+ servers => [
55
+ { host => "domain.com" port => 22 username => "fenicks" }
56
+ ]
56
57
  }
58
+ }
57
59
  ```
58
60
 
59
61
  ### With SSH server `host`, `port` and `username` and authenticate by a specific private key file
60
62
 
61
63
  ```javascript
62
- input {
63
- remote_proc {
64
- servers => [
65
- {
66
- host => "domain.com"
67
- port => 22
68
- username => "fenicks"
69
- ssh_private_key => "${HOME}/.ssh/id_rsa_domain.com"
70
- }
71
- ]
72
- }
64
+ input {
65
+ remote_proc {
66
+ servers => [
67
+ {
68
+ host => "domain.com"
69
+ port => 22
70
+ username => "fenicks"
71
+ ssh_private_key => "${HOME}/.ssh/id_rsa_domain.com"
72
+ }
73
+ ]
73
74
  }
75
+ }
74
76
  ```
75
77
 
76
78
  ### With SSH server `host`, `port` and `username` and authenticate by password
77
79
  ```javascript
78
- input {
79
- remote_proc {
80
- servers => [
81
- {
82
- host => "domain.com"
83
- port => 22
84
- username => "fenicks"
85
- password => "my_password!"
86
- }
87
- ]
88
- }
80
+ input {
81
+ remote_proc {
82
+ servers => [
83
+ {
84
+ host => "domain.com"
85
+ port => 22
86
+ username => "fenicks"
87
+ password => "my_password!"
88
+ }
89
+ ]
89
90
  }
91
+ }
90
92
  ```
91
93
  ### With SSH Gateway by with private key file and SSH `host` and `password`
92
94
  ```javascript
93
- input {
94
- remote_proc {
95
- servers => [
96
- {
97
- host => "domain.com"
98
- port => 22
99
- username => "fenicks"
100
- password => "my_password!"
101
- gateway_host => "gateway.com"
102
- gateway_username => "username_passemuraille"
103
- gateway_port => 4242
104
- gateway_ssh_private_key => "/path/to/private/key"
105
- }
106
- ]
107
- }
95
+ input {
96
+ remote_proc {
97
+ servers => [
98
+ {
99
+ host => "domain.com"
100
+ port => 22
101
+ username => "fenicks"
102
+ password => "my_password!"
103
+ gateway_host => "gateway.com"
104
+ gateway_username => "username_passemuraille"
105
+ gateway_port => 4242
106
+ gateway_ssh_private_key => "/path/to/private/key"
107
+ }
108
+ ]
108
109
  }
110
+ }
109
111
  ```
@@ -63,24 +63,29 @@ module LogStash
63
63
  'gateway_port' => 22, # :number
64
64
  'gateway_username' => ENV['USER'] || ENV['USERNAME'] || 'nobody', # :string (default to unix $USER)
65
65
  'gateway_password' => nil, # :string
66
- 'gateway_ssh_private_key' => nil # :string
66
+ 'gateway_ssh_private_key' => nil, # :string
67
+ 'system_reader' => 'cat', # :string
68
+ 'proc_prefix_path' => '/proc' # :string
67
69
  }.freeze
68
70
 
69
71
  # Liste of commands for each `/proc` endpoints.
70
72
  COMMANDS = {
71
- cpuinfo: 'cat /proc/cpuinfo',
72
- stat: 'cat /proc/stat',
73
- meminfo: 'cat /proc/meminfo',
74
- loadavg: 'cat /proc/loadavg',
75
- vmstat: 'cat /proc/vmstat',
76
- diskstats: 'cat /proc/diskstats',
77
- netdev: 'cat /proc/net/dev',
78
- netwireless: 'cat /proc/net/wireless',
79
- mounts: 'cat /proc/mounts',
80
- crypto: 'cat /proc/crypto',
81
- sysvipcshm: 'cat /proc/sysvipc/shm'
73
+ cpuinfo: '%{system_reader} %{proc_prefix_path}/cpuinfo',
74
+ stat: '%{system_reader} %{proc_prefix_path}/stat',
75
+ meminfo: '%{system_reader} %{proc_prefix_path}/meminfo',
76
+ loadavg: '%{system_reader} %{proc_prefix_path}/loadavg',
77
+ vmstat: '%{system_reader} %{proc_prefix_path}/vmstat',
78
+ diskstats: '%{system_reader} %{proc_prefix_path}/diskstats',
79
+ netdev: '%{system_reader} %{proc_prefix_path}/net/dev',
80
+ netwireless: '%{system_reader} %{proc_prefix_path}/net/wireless',
81
+ mounts: '%{system_reader} %{proc_prefix_path}/mounts',
82
+ crypto: '%{system_reader} %{proc_prefix_path}/crypto',
83
+ sysvipcshm: '%{system_reader} %{proc_prefix_path}/sysvipc/shm'
82
84
  }.freeze
83
85
 
86
+ # By default call all procfs method
87
+ DEFAULT_PROC_LIST = ['_all'].freeze
88
+
84
89
  config_name 'remote_proc'
85
90
 
86
91
  # If undefined, Logstash will complain, even if codec is unused.
@@ -121,7 +126,6 @@ module LogStash
121
126
 
122
127
  @ssh_sessions = []
123
128
  @ssh_gateways = []
124
- @commands = ['_all']
125
129
 
126
130
  configure!
127
131
  end # def register
@@ -130,10 +134,10 @@ module LogStash
130
134
  # we can abort the loop if stop? becomes true
131
135
  until stop?
132
136
  @ssh_sessions.each do |ssh|
133
- @commands.each do |method, command|
134
- result_data = String.new('')
135
- error_data = String.new('')
136
- channel = ssh.open_channel do |chan|
137
+ ssh.open_channel do |chan|
138
+ chan.connection.options[:properties]['_commands'].each do |method, command|
139
+ result_data = String.new('')
140
+ error_data = String.new('')
137
141
  chan.exec(command) do |ch, success|
138
142
  next unless success
139
143
  # "on_data" called when the process writes to stdout
@@ -142,30 +146,30 @@ module LogStash
142
146
  ch.on_extended_data { |_ch, _type, data| error_data << data }
143
147
  ch.on_close(&:close)
144
148
  end
149
+ chan.wait
150
+ unless error_data.empty?
151
+ error_data.chomp!
152
+ error_data = error_data.force_encoding('UTF-8')
153
+ @logger.warn(error_data)
154
+ next
155
+ end
156
+ next if result_data.empty?
157
+ result = send("proc_#{method}",
158
+ result_data.force_encoding('UTF-8'))
159
+ next if result.empty?
160
+ event = LogStash::Event.new(
161
+ method => result,
162
+ host: @host,
163
+ type: @type || "system-#{method}",
164
+ metric_name: "system-#{method}",
165
+ remote_host: chan.connection.options[:properties]['host'],
166
+ remote_port: chan.connection.options[:properties]['port'],
167
+ command: command,
168
+ message: result_data
169
+ )
170
+ decorate(event)
171
+ queue << event
145
172
  end
146
- channel.wait
147
- unless error_data.empty?
148
- error_data.chomp!
149
- error_data = error_data.force_encoding('UTF-8')
150
- @logger.warn(error_data)
151
- next
152
- end
153
- next if result_data.empty?
154
- result = send("proc_#{method}",
155
- result_data.force_encoding('UTF-8'))
156
- next if result.empty?
157
- event = LogStash::Event.new(
158
- method => result,
159
- host: @host,
160
- type: @type || "system-#{method}",
161
- metric_name: "system-#{method}",
162
- remote_host: channel.connection.options[:properties]['host'],
163
- remote_port: channel.connection.options[:properties]['port'],
164
- command: command,
165
- message: result_data
166
- )
167
- decorate(event)
168
- queue << event
169
173
  end
170
174
  ssh.loop
171
175
  end # @ssh_sessions block
@@ -181,16 +185,25 @@ module LogStash
181
185
  private
182
186
 
183
187
  # Return only valide property keys.
184
- def prepare_servers!(data)
185
- data.select! { |k| SERVER_OPTIONS.include?(k) }
186
- data.merge!(SERVER_OPTIONS) { |_key_, old, _new_| old }
188
+ def prepare_servers!(server)
189
+ server.select! { |k| SERVER_OPTIONS.include?(k) }
190
+ server.merge!(SERVER_OPTIONS) { |_key_, old, _new_| old }
191
+ cmds = if (@proc_list - ['_all']).empty?
192
+ COMMANDS.dup
193
+ else
194
+ COMMANDS.select { |k, _| @proc_list.include?(k.to_s) }
195
+ end
196
+ # Replace 'system_reader' and 'proc_prefix_path' in all commands
197
+ server['_commands'] = cmds.each do |k, v|
198
+ cmds[k] = v % { system_reader: server['system_reader'],
199
+ proc_prefix_path: server['proc_prefix_path'] }
200
+ end.freeze
187
201
  end
188
202
 
189
203
  # Prepare all server configuration
190
204
  def configure!
191
205
  @servers.each do |s|
192
206
  prepare_servers!(s)
193
-
194
207
  session_options = { properties: s }
195
208
  session_options[:port] = s['port'] if s['port']
196
209
  session_options[:password] = s['password'] if s['password']
@@ -218,11 +231,6 @@ module LogStash
218
231
  session_options)
219
232
  end
220
233
  end
221
- @commands = if (@proc_list - ['_all']).empty?
222
- COMMANDS
223
- else
224
- COMMANDS.select { |k, _| @proc_list.include?(k.to_s) }
225
- end
226
234
  end
227
235
 
228
236
  # Process SYSVIPCSHM data
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-remote_proc'
3
- s.version = '0.1.7'
3
+ s.version = '0.1.8'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'This Logstash plugin collects PROCFS metrics through remote SSH servers.'
6
6
  s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-remote_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement