panoptimon 0.0.2 → 0.1.0

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: 2ec4c546129725a6c662ae42fab05ac37d2ef7d5
4
- data.tar.gz: 3c52bd2b259bf5d5b43b168d6c0b078b29169681
3
+ metadata.gz: fb30066421e308022d06fc05ff455ce9a399bf8d
4
+ data.tar.gz: e1cf21306197c7b0e1eed6493b58b93e1b5ddcf9
5
5
  SHA512:
6
- metadata.gz: 0baa25a867349f8702542e9232e7e7478074cb918c901033a5de65ae0b310e2cfeee7e164f4666faa6ae1b4a9abca1735d5a17f7fa27e7b4e4b4294655002652
7
- data.tar.gz: 332e77a896f7291841125ff938d4f80004f91c164e704027cc327c3ae9113e6534d5a3da809d77f630c7a31c41b628a0d3d172aaedc86951ed5704fe61374ed9
6
+ metadata.gz: 139b276a174075928ecd7a495e7ffac36dd554dabf9b1198ca00fb3d5a7c7acd20aca3f03d57b316360e29f5117b7efcb2aa34ae81659b9e825425f10a4c35fc
7
+ data.tar.gz: 583b0a56837a75a046f2950c6187498d4411e6de376e5dc9004fca93b57387179c7cd90a69d8fcf51285456ffd40526592ff83e8f5141066f0b1dba64fa4732c
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 0.1.0
2
+
3
+ Added functionality to search for executables in the PATH environment variable directories.
4
+ If there a collector named 'thing.json', if it cannot find the 'thing' executable locally
5
+ it will search PATH for 'pancollect-thing'.
@@ -20,14 +20,20 @@ class Monitor
20
20
  @bus = EM.spawn { |metric| me.bus_driver(metric) }
21
21
  end
22
22
 
23
+ # Search directories for JSON files
23
24
  def _dirjson (x)
24
25
  x = Pathname.new(x)
25
26
  x.entries.find_all {|f| f.to_s =~ /\.json$/i}.
26
27
  map {|f| x + f}
27
28
  end
28
29
 
29
- def find_collectors; _dirjson(config.collectors_dir); end
30
- def find_plugins; _dirjson(config.plugins_dir); end
30
+ def find_collectors
31
+ _dirjson(config.collectors_dir)
32
+ end
33
+
34
+ def find_plugins
35
+ _dirjson(config.plugins_dir)
36
+ end
31
37
 
32
38
  def load_collectors
33
39
  find_collectors.each {|f|
@@ -42,25 +48,48 @@ class Monitor
42
48
 
43
49
  def _load_collector_config (file)
44
50
  conf = JSON.parse(file.read, {:symbolize_names => true})
45
- base = file.basename.sub(/\.json$/, '').to_s
46
- command = conf[:exec] ||= base
47
- command = file.dirname + base + command unless command =~ /^\//
51
+
52
+ # Determine the command path
53
+ collector_name = file.basename.sub(/\.json$/, '').to_s
54
+ command = Pathname.new(conf[:exec] || collector_name)
55
+ command = file.dirname + collector_name + command \
56
+ unless command.absolute?
57
+
58
+ command = _autodetect_collector_command_path(collector_name) \
59
+ unless command.exist? || !conf[:exec].nil?
60
+
61
+ # TODO - interval/timeout defaults should be configurable
48
62
  return conf.
49
63
  merge({
50
- name: base,
64
+ name: collector_name,
51
65
  interval: (self.config.collector_interval || 99).to_i,
52
66
  timeout: (self.config.collector_timeout || 99).to_i
53
67
  }) {|k,a,b| a}.
54
68
  merge({command: command})
55
69
  end
56
70
 
71
+ # Searches for 'pancollect-' executables in $PATH
72
+ # Returns nil if no command found
73
+ def _autodetect_collector_command_path(name)
74
+ pathdirs = ENV["PATH"].split(":")
75
+ name = 'pancollect-' + name
76
+ pathdirs.each{|basepath|
77
+ path = File.join(basepath, name)
78
+ logger.debug "checking path #{path}"
79
+ return path if File.exists?(path)
80
+ }
81
+ return nil
82
+ end
83
+
57
84
  def _init_collector (conf)
58
85
  name = conf.delete(:name)
59
86
  command = conf.delete(:command)
87
+ full_cmd = [command.to_s] + conf[:args].to_a
88
+ logger.debug "#{name} command: #{full_cmd}"
60
89
  collector = Collector.new(
61
90
  name: name,
62
91
  bus: @bus,
63
- command: [command.to_s] + conf[:args].to_a,
92
+ command: full_cmd,
64
93
  config: conf,
65
94
  )
66
95
  collectors << collector
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2012 Sourcefire, Inc.
2
2
 
3
3
  module Panoptimon
4
- VERSION = "0.0.2"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspec'
4
+ require 'panoptimon'
5
+
6
+ describe "PATH search" do
7
+ before(:each) do
8
+ @test_bin_dir = "/tmp/panoptimon/test_bin/"
9
+ FileUtils.mkdir_p @test_bin_dir
10
+ fakepath = @test_bin_dir + ":/should/not/exist/"
11
+ ENV["PATH"] = fakepath
12
+
13
+ @test_conf_dir = Pathname.new "/tmp/panoptimon/test_conf/"
14
+ FileUtils.mkdir_p @test_conf_dir
15
+
16
+ @test_collector_name = "thing"
17
+ @test_conf_path = @test_conf_dir + "#{@test_collector_name}.json"
18
+ f = File.new(@test_conf_path, "w")
19
+ f.write('{"hey": "yo"}')
20
+ f.close
21
+
22
+ @monitor = Panoptimon::Monitor.new(
23
+ config: Panoptimon.load_options(['-c', '',
24
+ '-o', 'collector_interval=9',
25
+ '-o', 'collector_timeout=12',
26
+ ])
27
+ )
28
+ end
29
+
30
+ it "should return nil if no file is found" do
31
+ expect(@monitor._autodetect_collector_command_path("bad_collector")).to be_nil
32
+
33
+ @monitor._load_collector_config(@test_conf_path).should include(:command => nil)
34
+ end
35
+
36
+ it "should return a path if the command is found" do
37
+ path = File.join(@test_bin_dir, "pancollect-thing")
38
+ f = File.new(path, "w")
39
+ f.close
40
+ expect(@monitor._autodetect_collector_command_path("thing")).to eq(path)
41
+
42
+ @monitor._load_collector_config(@test_conf_path).should include(:command => path)
43
+ end
44
+
45
+ it "should not search PATH if exec is stipulated" do
46
+ path = File.join(@test_bin_dir, "pancollect-thing")
47
+ f = File.new(path, "w")
48
+ f.close
49
+
50
+ # Non-absolute exec path
51
+ f = File.new(@test_conf_path, 'w')
52
+ f.write('{"exec": "something_else"}')
53
+ f.close
54
+ non_abs_exec_path = @test_conf_dir.join(@test_collector_name, "something_else")
55
+
56
+ @monitor._load_collector_config(@test_conf_path).should include(:command => non_abs_exec_path)
57
+
58
+ # Absolute exec path
59
+ f = File.new(@test_conf_path, 'w')
60
+ exec_cmd = Pathname.new('/usr/bin/true')
61
+ f.write("{\"exec\": \"#{exec_cmd}\"}")
62
+ f.close
63
+
64
+ @monitor._load_collector_config(@test_conf_path).should include(:command => exec_cmd)
65
+ end
66
+
67
+ after(:each) do
68
+ FileUtils.rm_rf @test_bin_dir
69
+ FileUtils.rm_rf @test_conf_path
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panoptimon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Wilhelm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
+ - CHANGELOG.md
119
120
  - Gemfile
120
121
  - LICENSE
121
122
  - README.md
@@ -282,6 +283,7 @@ files:
282
283
  - sample_configs/timeout_not/plugins/.exists
283
284
  - spec/collector/config_spec.rb
284
285
  - spec/collector/initialize_spec.rb
286
+ - spec/collector/load_path.rb
285
287
  - spec/collector/metric_spec.rb
286
288
  - spec/passthru_spec.rb
287
289
  - spec/util_spec.rb
@@ -314,6 +316,7 @@ summary: Panoptimon collects and routes system metrics.
314
316
  test_files:
315
317
  - spec/collector/config_spec.rb
316
318
  - spec/collector/initialize_spec.rb
319
+ - spec/collector/load_path.rb
317
320
  - spec/collector/metric_spec.rb
318
321
  - spec/passthru_spec.rb
319
322
  - spec/util_spec.rb