fuey_client 0.6.0 → 0.7.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: f079db9962809a0e42b00bd385b9184a132ee771
4
- data.tar.gz: d86dfd426a5db986e654829d8f7877693bf8c8c6
3
+ metadata.gz: 495dc67e99ddd7c14963c64ab490cfb1c6852731
4
+ data.tar.gz: d3bc7df65ad943b288a1346c815ec207729fefaf
5
5
  SHA512:
6
- metadata.gz: 25383482a7ffc6050a40a19dca2618195e2fa1f2418215a6b758c9d3ebddd9a530fecd945248dd01009a290f3834e75e43ce45146aa322edd186d2f48b604d55
7
- data.tar.gz: c92968edaffae7143578e0dbacfcc14303e41438acb063ef90b9bbb43e02de4ffeb111e5c7003161c5adee2cbbca48e0bbc09f5c3d97833553e96ce473881326
6
+ metadata.gz: 33b22f4767a69e9b8960fd51143e4ae0c41fc0eabdec71ef7130322418e6fc25113009b460d9cc29356c5dfe7bf9c40b73f9462ee9c4ed3020ad401a48790ebe
7
+ data.tar.gz: 53e23f3935bf6a51b51af9f17026fa750e3c73938fb7347afa5841b59bae5193aa10c6ffc8efcf3e03bbe0eb73e91d04a442af9705f801068e6f1637e686a4d8
@@ -4,6 +4,7 @@ require "fuey_client/fuey/null_object"
4
4
  require "fuey_client/fuey/trace"
5
5
  require "fuey_client/fuey/inspections"
6
6
  require "fuey_client/fuey/reporters"
7
+ require "fuey_client/fuey/trace_repository"
7
8
 
8
9
  require "active_support"
9
10
 
@@ -17,12 +18,12 @@ module Fuey
17
18
  end
18
19
 
19
20
  def reporter
20
- @_reporter ||= Reporters::Redis.new
21
+ @_reporter ||= Reporters::NotificationQueue.new(Fuey::Redis.instance)
21
22
  end
22
23
 
23
24
  def run
24
- Trace.all.each do |trace|
25
- trace.add_observer reporter
25
+ TraceRepository.new.all.each do |trace|
26
+ trace.receiver = reporter
26
27
  output = trace.run
27
28
  Log.write %([#{trace.name}] #{output})
28
29
  end
@@ -1,6 +1,7 @@
1
1
  require "observer"
2
2
  require "stately"
3
3
  require "fuey_client/fuey/model_initializer"
4
+ require "fuey_client/fuey/inspections/support/status"
4
5
 
5
6
  module Fuey
6
7
  module Inspections
@@ -13,17 +14,30 @@ module Fuey
13
14
  stately :start => :pending, :attr => :state do
14
15
  state :executed, :action => :execute do
15
16
  before_transition :do => :notify
16
- after_transition :do => :notify
17
- after_transition :do => :_execute
17
+ after_transition :do => :notify
18
+ after_transition :do => :_execute
18
19
  end
19
20
  state :passed, :action => :pass do
20
- after_transition :do => :notify
21
+ after_transition :do => :notify
21
22
  end
22
23
  state :failed, :action => :fail do
23
- after_transition :do => :notify
24
+ after_transition :do => :notify
24
25
  end
25
26
  end
26
27
 
28
+ def status
29
+ Support::Status.new(
30
+ :type => self.class.to_s.split('::').last,
31
+ :name => name,
32
+ :status => state,
33
+ :settings => settings, # defined in child class
34
+ :status_message => status_message # defined in child class
35
+ )
36
+ end
37
+
38
+ def settings; end
39
+ def status_message; end
40
+
27
41
  def passed?
28
42
  state == 'passed'
29
43
  end
@@ -37,14 +51,6 @@ module Fuey
37
51
  notify_observers status
38
52
  end
39
53
 
40
- def status
41
- {
42
- :type => self.class.to_s.split('::').last,
43
- :name => name,
44
- :status => self.state
45
- }
46
- end
47
-
48
54
  end
49
55
  end
50
56
  end
@@ -18,12 +18,14 @@ module Fuey
18
18
  %(Ping #{name} #{host})
19
19
  end
20
20
 
21
- def status
22
- {
23
- :settings => host || "",
24
- :statusMessage => %(#{state} ping for #{host}),
25
- }.merge(super)
21
+ def settings
22
+ host || ""
26
23
  end
24
+
25
+ def status_message
26
+ %(#{state} ping for #{host})
27
+ end
28
+
27
29
  end
28
30
  end
29
31
  end
@@ -23,11 +23,8 @@ module Fuey
23
23
  %(RFCPing #{state} for #{ashost}.)
24
24
  end
25
25
 
26
- def status
27
- {
28
- :settings => config.reject{|k,v| k == 'passwd'},
29
- :statusMessage => status_message
30
- }.merge(super)
26
+ def settings
27
+ config.reject{|k,v| k == 'passwd'}
31
28
  end
32
29
 
33
30
  def config
@@ -27,11 +27,8 @@ module Fuey
27
27
  %(SNMPWalk #{state}. #{response})
28
28
  end
29
29
 
30
- def status
31
- {
32
- :settings => snmp_walk_command,
33
- :statusMessage => status_message
34
- }.merge(super)
30
+ def settings
31
+ snmp_walk_command || ""
35
32
  end
36
33
 
37
34
  def to_s
@@ -0,0 +1,33 @@
1
+ require "fuey_client/fuey/model_initializer"
2
+
3
+ module Fuey
4
+ module Inspections
5
+ module Support
6
+ class Status
7
+ include ModelInitializer
8
+ include Comparable
9
+
10
+ attr_accessor :type, :name, :status, :settings, :status_message
11
+
12
+ def passed?
13
+ status == 'passed'
14
+ end
15
+
16
+ def failed?
17
+ status == 'failed'
18
+ end
19
+
20
+ def attributes
21
+ [:type, :name, :status, :settings, :status_message].inject(Hash.new) do |memo, attr|
22
+ memo[attr] = self.send(attr)
23
+ memo
24
+ end
25
+ end
26
+
27
+ def <=>(another)
28
+ attributes.hash <=> another.attributes.hash
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require "redis"
2
+
3
+ module Fuey
4
+ class Redis
5
+ def self.instance
6
+ @@redis ||= ::Redis.new(
7
+ :host => Config::Redis.host,
8
+ :port => Config::Redis.port )
9
+ end
10
+ end
11
+ end
@@ -1,2 +1,2 @@
1
- require "fuey_client/fuey/reporters/redis"
1
+ require "fuey_client/fuey/reporters/notification_queue"
2
2
  require "fuey_client/fuey/reporters/error_logger"
@@ -4,8 +4,8 @@ module Fuey
4
4
  module Reporters
5
5
  class ErrorLogger
6
6
  def update(status)
7
- if status[:status] == 'failed'
8
- Log.alert "#{status[:name]} failed. #{status[:statusMessage]}"
7
+ if status.failed?
8
+ Log.alert "#{status.name} failed. #{status.status_message}"
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,47 @@
1
+ require "json"
2
+ require "fuey_client/fuey/redis"
3
+
4
+ module Fuey
5
+ module Reporters
6
+ class NotificationQueue
7
+ def initialize(redis)
8
+ @_redis = redis
9
+ end
10
+
11
+ def update(type, *args)
12
+ self.send("publish_#{type}", args)
13
+ true
14
+ end
15
+
16
+ def publish_update(args)
17
+ trace_name, statuses = args[0], args[1]
18
+ status = statuses.first
19
+ message = [ trace_name, status.attributes ]
20
+ @_redis.publish "fuey.trace.update", message.to_json
21
+ end
22
+
23
+ def publish_complete(args)
24
+ trace = args.first
25
+ message = {
26
+ :time => Time.now.strftime("%Y%m%d%H%M%S"),
27
+ :name => trace.name,
28
+ :status => trace.status,
29
+ :status_message => trace.status_message,
30
+ :steps => trace.steps.map(&:status).map(&:attributes)
31
+ }
32
+ @_redis.lpush trace.name.downcase, message.to_json
33
+ end
34
+
35
+ def publish_new(args)
36
+ trace_name, statuses = args[0], args[1]
37
+ message = {
38
+ :name => trace_name,
39
+ :status => "executed",
40
+ :status_message => "",
41
+ :steps => statuses.map(&:attributes)
42
+ }
43
+ @_redis.publish "fuey.trace.new", message.to_json
44
+ end
45
+ end
46
+ end
47
+ end
@@ -3,36 +3,36 @@ require "fuey_client/fuey/reporters"
3
3
  require "active_support"
4
4
  require "observer"
5
5
 
6
-
7
6
  module Fuey
8
7
  class Trace
9
8
  include ModelInitializer
10
9
  include Observable
11
10
 
12
- attr_accessor :name, :steps
11
+ attr_accessor :name
13
12
 
14
13
  def initialize(args)
15
14
  super(args)
16
- @steps ||= Array.new
17
15
  end
18
16
 
19
- def self.all
20
- Config::Fuey.traces.keys.map do |trace_name|
21
- trace = Trace.new :name => trace_name
22
- Config::Fuey.traces.send(trace_name).each do |step|
23
- inspection_class = ActiveSupport::Inflector.constantize %(Fuey::Inspections::#{step.keys.first})
24
- inspection = inspection_class.new(step.values.first)
25
- inspection.add_observer(trace)
26
- inspection.add_observer(error_logger)
27
- trace.steps.push inspection
28
- end
29
- trace
30
- end
17
+ def receiver=(observer)
18
+ add_observer observer
19
+ end
20
+
21
+ def add_step(inspection)
22
+ inspection.add_observer(self)
23
+ inspection.add_observer(error_logger)
24
+ steps.push inspection
25
+ inspection
26
+ end
27
+
28
+ def steps
29
+ @_steps ||= Array.new
31
30
  end
32
31
 
33
- def self.error_logger
34
- @@error_logger ||= Fuey::Reporters::ErrorLogger.new
32
+ def error_logger
33
+ @_error_logger ||= Fuey::Reporters::ErrorLogger.new
35
34
  end
35
+ private :error_logger
36
36
 
37
37
  def to_s
38
38
  %(#{name}: [#{steps.join(', ')}])
@@ -41,42 +41,40 @@ module Fuey
41
41
  # Handle updates from inpsections via observation
42
42
  def update(status)
43
43
  changed
44
- notify_observers(
45
- "fuey.trace.update",
46
- {
47
- :name => name,
48
- :status => status[:status],
49
- :statusMessage => status[:statusMessage],
50
- :steps => [ status ]
51
- })
44
+ notify_observers :update, name, [status]
45
+ true
46
+ end
47
+
48
+ def status
49
+ @_current ? @_current.state : "pending"
50
+ end
51
+
52
+ def status_message
53
+ @_current.failed? ? @_current.status_message : ""
52
54
  end
53
55
 
54
56
  def run
55
57
  changed
56
- notify_observers(
57
- "fuey.trace.new",
58
- {
59
- :name => name,
60
- :status => "executed",
61
- :statusMessage => "",
62
- :steps => steps.map(&:status)
63
- }
64
- )
58
+ notify_observers :new, name, steps.map(&:status)
59
+
65
60
  ActiveSupport::Notifications.instrument("run.trace", {:trace => self.to_s}) do
66
- run, failed, current = 0, 0, ""
61
+ run, failed, @_current = 0, 0, nil
67
62
  steps.each do |step|
68
63
  run += 1
69
- current = step.name
64
+ @_current = step
70
65
  step.execute
71
66
  if step.failed?
72
67
  failed += 1
73
68
  break
74
69
  end
75
70
  end
71
+
72
+ changed
73
+ notify_observers :complete, self
76
74
  if failed == 0
77
75
  %(#{name} passed. #{steps.size} steps, #{run} executed, #{failed} failed.)
78
76
  else
79
- %(#{name} failed on #{current}. #{steps.size} steps, #{run} executed, #{failed} failed.)
77
+ %(#{name} failed on #{@_current.name}. #{steps.size} steps, #{run} executed, #{failed} failed.)
80
78
  end
81
79
  end
82
80
  end
@@ -0,0 +1,21 @@
1
+ require "fuey_client/fuey/trace"
2
+
3
+ module Fuey
4
+ class TraceRepository
5
+ def all
6
+ traces ||= Config::Fuey.traces.keys.map do |trace_name|
7
+ fetch trace_name
8
+ end
9
+ end
10
+
11
+ def fetch(trace_name)
12
+ trace = Trace.new :name => trace_name
13
+ Config::Fuey.traces.send(trace_name).each do |step|
14
+ inspection_class = ActiveSupport::Inflector.constantize %(Fuey::Inspections::#{step.keys.first})
15
+ inspection = inspection_class.new(step.values.first)
16
+ trace.add_step inspection
17
+ end
18
+ trace
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module FueyClient
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -29,11 +29,14 @@ describe Fuey::Inspections::Inspection do
29
29
  def expects_notification_of(*states)
30
30
  states.each do |state|
31
31
  self.should_receive(:update).
32
- with({
33
- :type => @inspection.class.to_s,
34
- :name => @inspection.name,
35
- :status => state
36
- })
32
+ with(Fuey::Inspections::Support::Status.new(
33
+ :type => @inspection.class.to_s,
34
+ :name => @inspection.name,
35
+ :status => state,
36
+ :settings => nil,
37
+ :status_message => nil
38
+ )
39
+ )
37
40
  end
38
41
  end
39
42
  end
@@ -16,7 +16,7 @@ describe Fuey::Inspections::RFCPing do
16
16
  Given (:rfc_ping) { Fuey::Inspections::RFCPing.new config }
17
17
 
18
18
  describe "status" do
19
- Then { expect( rfc_ping.status[:settings] ).to_not include('passwd') }
19
+ Then { expect( rfc_ping.status.settings ).to_not include('passwd') }
20
20
  end
21
21
 
22
22
  context "when the ping fails" do
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fuey::Inspections::Support::Status do
4
+
5
+ describe "attributes" do
6
+ Then { expect( subject ).to respond_to(:type) }
7
+ Then { expect( subject ).to respond_to(:name) }
8
+ Then { expect( subject ).to respond_to(:status) }
9
+ Then { expect( subject ).to respond_to(:settings) }
10
+ Then { expect( subject ).to respond_to(:status_message) }
11
+ end
12
+
13
+ describe "passed?" do
14
+ Given (:status) { Fuey::Inspections::Support::Status.new :status => 'passed' }
15
+ Then { expect( status ).to be_passed }
16
+ Then { expect( status ).to_not be_failed }
17
+ end
18
+
19
+ describe "failed?" do
20
+ Given (:status) { Fuey::Inspections::Support::Status.new :status => 'failed' }
21
+ Then { expect( status ).to_not be_passed }
22
+ Then { expect( status ).to be_failed }
23
+ end
24
+
25
+ describe "equality" do
26
+ Given (:attributes) { { :name => "Status 1", :status => "pending", :type => "Inspection" } }
27
+
28
+ context "when both have same attributes" do
29
+ Given (:status1) { Fuey::Inspections::Support::Status.new attributes.clone }
30
+ Given (:status2) { Fuey::Inspections::Support::Status.new attributes.clone }
31
+ Then { expect( status1 ).to eq( status2 ) }
32
+ end
33
+
34
+ context "when both have same values, but one has additional key with a nil value" do
35
+ Given (:status1) { Fuey::Inspections::Support::Status.new attributes.clone }
36
+ Given (:status2) { Fuey::Inspections::Support::Status.new attributes.clone.merge({:settings => nil}) }
37
+ Then { expect( status1 ).to eq( status2 ) }
38
+ end
39
+
40
+ context "when both only have a different status" do
41
+ Given (:status1) { Fuey::Inspections::Support::Status.new attributes.clone }
42
+ Given (:status2) { Fuey::Inspections::Support::Status.new attributes.clone.merge({:status => 'failed'}) }
43
+ Then { expect( status1 ).to_not eq( status2 ) }
44
+ end
45
+
46
+ context "when both only have a different name" do
47
+ Given (:status1) { Fuey::Inspections::Support::Status.new attributes.clone }
48
+ Given (:status2) { Fuey::Inspections::Support::Status.new attributes.clone.merge({:name => 'Status X'}) }
49
+ Then { expect( status1 ).to_not eq( status2 ) }
50
+ end
51
+ end
52
+
53
+
54
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Fuey::Reporters::NotificationQueue do
4
+ Given (:redis) { double "Redis" }
5
+ Given (:q) { Fuey::Reporters::NotificationQueue.new redis }
6
+
7
+ describe "receiving updates for new traces" do
8
+ Given (:statuses) { [create_status("Ping 1"), create_status("Ping 2")] }
9
+ Given (:json_string) { {
10
+ :name => "QA Alpha Trace",
11
+ :status => "executed",
12
+ :status_message => "",
13
+ :steps => statuses.map(&:attributes)
14
+ }.to_json }
15
+ Given { redis.should_receive(:publish).with("fuey.trace.new", json_string) }
16
+ When (:result) { q.update :new, "QA Alpha Trace", statuses }
17
+ Then { expect( result ).to be_true, "and publish to Redis" }
18
+ end
19
+
20
+ describe "receiving updates for existing traces" do
21
+ Given (:statuses) { [create_status("Ping 1")] }
22
+ Given (:json_string) {
23
+ ["QA Alpha Trace", statuses.first.attributes].to_json
24
+ }
25
+ Given { redis.should_receive(:publish).with("fuey.trace.update", json_string) }
26
+ When (:result) { q.update :update, "QA Alpha Trace", statuses }
27
+ Then { expect( result ).to be_true, "and publish to Redis" }
28
+ end
29
+
30
+ def create_status(name)
31
+ Fuey::Inspections::Support::Status.new :name => name
32
+ end
33
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fuey::TraceRepository do
4
+ after(:each) { Fuey::Config::Fuey.reload_configuration }
5
+
6
+ describe "retrieving all configured traces" do
7
+ context "when configured for no traces" do
8
+ Given { Fuey::Config::Fuey.test_with(no_traces) }
9
+ When (:result) { Fuey::TraceRepository.new.all }
10
+ Then { expect( result ).to be_empty }
11
+ end
12
+
13
+ context "when configured with one trace" do
14
+ Given { Fuey::Config::Fuey.test_with(two_pings) }
15
+ When (:result) { Fuey::TraceRepository.new.all }
16
+ Then { expect( result ).to have(1).items }
17
+ And { expect( result.first ).to be_a(Fuey::Trace) }
18
+ And { expect( result.first ).to have(2).steps }
19
+ And { expect( result.first.steps[0] ).to ping("Google").at("8.8.8.8") }
20
+ And { expect( result.first.steps[1] ).to ping("Self").at("172.0.0.1") }
21
+ end
22
+ end
23
+
24
+ RSpec::Matchers.define :ping do |name|
25
+ match do |actual|
26
+ (actual.name == name) && (actual.host == @host)
27
+ end
28
+
29
+ chain :at do |host|
30
+ @host = host
31
+ end
32
+
33
+ failure_message_for_should do
34
+ %(should have pinged #{name} at #{@host}, but was #{actual.name} and #{actual.host})
35
+ end
36
+
37
+ failure_message_for_should_not do
38
+ %(should not have pinged #{actual.host})
39
+ end
40
+
41
+ description do
42
+ %(should ping #{name} at #{@host})
43
+ end
44
+ end
45
+
46
+ def two_pings
47
+ {
48
+ "traces" => {
49
+ "two_pings" =>
50
+ [
51
+ {
52
+ "Ping" => {
53
+ "name" => "Google",
54
+ "host" => "8.8.8.8"
55
+ }
56
+ },
57
+ {
58
+ "Ping" => {
59
+ "name" => "Self",
60
+ "host" => "172.0.0.1"
61
+ }
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ end
67
+
68
+ def no_traces
69
+ {
70
+ "traces" => {}
71
+ }
72
+ end
73
+ end
@@ -1,90 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Fuey::Trace do
4
- after(:each) { Fuey::Config::Fuey.reload_configuration }
5
-
6
- describe "retrieving all configured traces" do
7
- context "when configured for no traces" do
8
- Given { Fuey::Config::Fuey.test_with(no_traces) }
9
- When (:result) { Fuey::Trace.all }
10
- Then { expect( result ).to be_empty }
11
- end
12
-
13
- context "when configured with one trace" do
14
- Given { Fuey::Config::Fuey.test_with(two_pings) }
15
- When (:result) { Fuey::Trace.all }
16
- Then { expect( result ).to have(1).items }
17
- And { expect( result.first ).to be_a(Fuey::Trace) }
18
- And { expect( result.first ).to have(2).steps }
19
- And { expect( result.first.steps[0] ).to ping("Google").at("8.8.8.8") }
20
- And { expect( result.first.steps[1] ).to ping("Self").at("172.0.0.1") }
21
- end
22
- end
23
-
24
4
  describe "running a trace" do
25
5
  context "when the first step fails" do
26
- Given (:step1) { double(Fuey::Inspections::Ping, :name => "step1", :execute => nil, :failed? => true, :status => {}) }
27
- Given (:step2) { double(Fuey::Inspections::Ping, :status => {}) }
28
- Given { step2.should_not_receive(:execute) }
29
- When (:result) { Fuey::Trace.new(:name => "trace1", :steps => [step1, step2]).run }
30
- Then { expect( result ).to eql(%[trace1 failed on step1. 2 steps, 1 executed, 1 failed.]) }
6
+ Given (:trace) { Fuey::Trace.new :name => "trace1" }
7
+ Given! (:step1) { trace.add_step failed_inspection.new :name => "step1" }
8
+ Given! (:step2) { trace.add_step successful_inspection.new :name => "step2" }
9
+ Given { step2.should_not_receive(:execute) }
10
+ When (:result) { trace.run }
11
+ Then { expect( result ).to eql(%[trace1 failed on step1. 2 steps, 1 executed, 1 failed.]) }
31
12
  end
32
13
 
33
14
  context "when all steps pass" do
34
- Given (:step1) { double(Fuey::Inspections::Ping, :name => "step1", :execute => nil, :failed? => false, :status => {}) }
35
- Given (:step2) { double(Fuey::Inspections::Ping, :name => "step2", :execute => nil, :failed? => false, :status => {}) }
36
- When (:result) { Fuey::Trace.new(:name => "trace1", :steps => [step1, step2]).run }
37
- Then { expect( result ).to eql(%[trace1 passed. 2 steps, 2 executed, 0 failed.]) }
15
+ Given (:trace) { Fuey::Trace.new :name => "trace1" }
16
+ Given! (:step1) { trace.add_step successful_inspection.new :name => "step1" }
17
+ Given! (:step2) { trace.add_step successful_inspection.new :name => "step2" }
18
+ When (:result){ trace.run }
19
+ Then { expect( result ).to eql(%[trace1 passed. 2 steps, 2 executed, 0 failed.]) }
38
20
  end
39
21
  end
40
22
 
41
- RSpec::Matchers.define :ping do |name|
42
- match do |actual|
43
- (actual.name == name) && (actual.host == @host)
44
- end
45
-
46
- chain :at do |host|
47
- @host = host
48
- end
23
+ def successful_inspection
24
+ Class.new(Fuey::Inspections::Inspection) do
25
+ def _execute
26
+ self.pass
27
+ end
49
28
 
50
- failure_message_for_should do
51
- %(should have pinged #{name} at #{@host}, but was #{actual.name} and #{actual.host})
29
+ def add_observer(observer)
30
+ # dont observe
31
+ end
52
32
  end
33
+ end
53
34
 
54
- failure_message_for_should_not do
55
- %(should not have pinged #{actual.host})
56
- end
35
+ def failed_inspection
36
+ Class.new(Fuey::Inspections::Inspection) do
37
+ def _execute
38
+ self.fail
39
+ end
57
40
 
58
- description do
59
- %(should ping #{name} at #{@host})
41
+ def add_observer(observer)
42
+ # dont observe
43
+ end
60
44
  end
61
45
  end
62
46
 
63
- def two_pings
64
- {
65
- "traces" => {
66
- "two_pings" =>
67
- [
68
- {
69
- "Ping" => {
70
- "name" => "Google",
71
- "host" => "8.8.8.8"
72
- }
73
- },
74
- {
75
- "Ping" => {
76
- "name" => "Self",
77
- "host" => "172.0.0.1"
78
- }
79
- }
80
- ]
81
- }
82
- }
83
- end
84
-
85
- def no_traces
86
- {
87
- "traces" => {}
88
- }
89
- end
90
47
  end
@@ -17,11 +17,11 @@ shared_examples "an inspection" do
17
17
 
18
18
  describe "and have specific pieces of information" do
19
19
  When (:status) { described_class.new({:name => 'descriptive'}).status }
20
- Then { expect( status[:type] ).to eql(described_class.to_s.split('::').last) }
21
- And { expect( status[:name] ).to eql('descriptive') }
22
- And { expect( status[:settings] ).to_not be_nil }
23
- And { expect( status[:status] ).to eql("pending") }
24
- And { expect( status[:statusMessage] ).to_not be_nil }
20
+ Then { expect( status.type ).to eql(described_class.to_s.split('::').last) }
21
+ And { expect( status.name ).to eql('descriptive') }
22
+ And { expect( status.settings ).to_not be_nil }
23
+ And { expect( status.status ).to eql("pending") }
24
+ And { expect( status.status_message ).to_not be_nil }
25
25
  end
26
26
 
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuey_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configurethis
@@ -141,20 +141,25 @@ files:
141
141
  - lib/fuey_client/fuey/inspections/snmp_walk.rb
142
142
  - lib/fuey_client/fuey/inspections/support/sap.rb
143
143
  - lib/fuey_client/fuey/inspections/support/shell_command.rb
144
+ - lib/fuey_client/fuey/inspections/support/status.rb
144
145
  - lib/fuey_client/fuey/log.rb
145
146
  - lib/fuey_client/fuey/model_initializer.rb
146
147
  - lib/fuey_client/fuey/null_object.rb
148
+ - lib/fuey_client/fuey/redis.rb
147
149
  - lib/fuey_client/fuey/reporters.rb
148
150
  - lib/fuey_client/fuey/reporters/error_logger.rb
149
- - lib/fuey_client/fuey/reporters/redis.rb
151
+ - lib/fuey_client/fuey/reporters/notification_queue.rb
150
152
  - lib/fuey_client/fuey/trace.rb
153
+ - lib/fuey_client/fuey/trace_repository.rb
151
154
  - lib/fuey_client/version.rb
152
- - spec/fuey_client/fuey/#trace_spec.rb#
153
155
  - spec/fuey_client/fuey/client_spec.rb
154
156
  - spec/fuey_client/fuey/inspections/inspection_spec.rb
155
157
  - spec/fuey_client/fuey/inspections/ping_spec.rb
156
158
  - spec/fuey_client/fuey/inspections/rfc_ping_spec.rb
157
159
  - spec/fuey_client/fuey/inspections/snmpwalk_spec.rb
160
+ - spec/fuey_client/fuey/inspections/support/status_spec.rb
161
+ - spec/fuey_client/fuey/reporters/notification_queue_spec.rb
162
+ - spec/fuey_client/fuey/trace_repository_spec.rb
158
163
  - spec/fuey_client/fuey/trace_spec.rb
159
164
  - spec/matchers/inspection_shared_examples.rb
160
165
  - spec/matchers/pass_fail.rb
@@ -187,12 +192,14 @@ specification_version: 4
187
192
  summary: Client for inspecting server state and reports it back to Fuey. Requires
188
193
  the Fuey web app to have any value.
189
194
  test_files:
190
- - spec/fuey_client/fuey/#trace_spec.rb#
191
195
  - spec/fuey_client/fuey/client_spec.rb
192
196
  - spec/fuey_client/fuey/inspections/inspection_spec.rb
193
197
  - spec/fuey_client/fuey/inspections/ping_spec.rb
194
198
  - spec/fuey_client/fuey/inspections/rfc_ping_spec.rb
195
199
  - spec/fuey_client/fuey/inspections/snmpwalk_spec.rb
200
+ - spec/fuey_client/fuey/inspections/support/status_spec.rb
201
+ - spec/fuey_client/fuey/reporters/notification_queue_spec.rb
202
+ - spec/fuey_client/fuey/trace_repository_spec.rb
196
203
  - spec/fuey_client/fuey/trace_spec.rb
197
204
  - spec/matchers/inspection_shared_examples.rb
198
205
  - spec/matchers/pass_fail.rb
@@ -1,20 +0,0 @@
1
- require "redis"
2
- require "json"
3
-
4
- module Fuey
5
- module Reporters
6
- class Redis
7
- def redis
8
- @@redis ||= ::Redis.new(
9
- :host => Config::Redis.host,
10
- :port => Config::Redis.port )
11
- end
12
- private :redis
13
-
14
- # Handles update from observable
15
- def update(channel, message)
16
- redis.publish channel, message.to_json
17
- end
18
- end
19
- end
20
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fuey::Trace do
4
- after(:each) { Fuey::Config.reload_configuration }
5
-
6
- describe "retrieving all configured traces" do
7
- context "when configured for no traces" do
8
- Given { Fuey::Config.test_with(no_traces) }
9
- When (:result) { Fuey::Trace.all }
10
- Then { expect( result ).to be_empty }
11
- end
12
-
13
- context "when configured with one trace" do
14
- Given { Fuey::Config.test_with(two_pings) }
15
- When (:result) { Fuey::Trace.all }
16
- Then { expect( result ).to have(1).items }
17
- And { expect( result.first ).to be_a(Fuey::Trace) }
18
- And { expect( result.first ).to have(2).steps }
19
- And { expect( result.first.steps[0] ).to ping("Google").at("8.8.8.8") }
20
- And { expect( result.first.steps[1] ).to ping("Self").at("172.0.0.1") }
21
- end
22
- end
23
-
24
- describe "running a trace" do
25
- context "when the first step fails" do
26
- Given (:step1) { double(Fuey::Inspections::Ping, :name => "step1", :execute => false) }
27
- Given (:step2) { double(Fuey::Inspections::Ping) }
28
- Given { step2.should_not_receive(:execute) }
29
- When (:result) { Fuey::Trace.new(:name => "trace1", :steps => [step1, step2]).run }
30
- Then { expect( result ).to eql(%[trace1 failed on step1. 2 steps, 1 executed, 1 failed.]) }
31
- end
32
-
33
- context "when all steps pass" do
34
- Given (:step1) { double(Fuey::Inspections::Ping, :name => "step1", :execute => true) }
35
- Given (:step2) { double(Fuey::Inspections::Ping, :name => "step2", :execute => true) }
36
- When (:result) { Fuey::Trace.new(:name => "trace1", :steps => [step1, step2]).run }
37
- Then { expect( result ).to eql(%[trace1 passed. 2 steps, 2 executed, 0 failed.]) }
38
- end
39
- end
40
-
41
- RSpec::Matchers.define :ping do |name|
42
- match do |actual|
43
- (actual.name == name) && (actual.host == @host)
44
- end
45
-
46
- chain :at do |host|
47
- @host = host
48
- end
49
-
50
- failure_message_for_should do
51
- %(should have pinged #{name} at #{@host}, but was #{actual.name} and #{actual.host})
52
- end
53
-
54
- failure_message_for_should_not do
55
- %(should not have pinged #{actual.host})
56
- end
57
-
58
- description do
59
- %(should ping #{name} at #{@host})
60
- end
61
- end
62
-
63
- def two_pings
64
- {
65
- "traces" => {
66
- "two_pings" =>
67
- [
68
- {
69
- "Ping" => {
70
- "name" => "Google",
71
- "host" => "8.8.8.8"
72
- }
73
- },
74
- {
75
- "Ping" => {
76
- "name" => "Self",
77
- "host" => "172.0.0.1"
78
- }
79
- }
80
- ]
81
- }
82
- }
83
- end
84
-
85
- def no_traces
86
- {
87
- "traces" => {}
88
- }
89
- end
90
- end