hinoki 1.1.0 → 1.2.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: 132ed86ba9f3e9114eed5124c1fe6c5d5c175a14
4
- data.tar.gz: 1c14203f306d34c1214a2d90b2c1a83ad4f015b0
3
+ metadata.gz: 8446fd8cc41684f7bd2063be59ab013aa7b6b9ab
4
+ data.tar.gz: c1137cfa77ed25ad24454e1f029fa7c911ab1573
5
5
  SHA512:
6
- metadata.gz: 67b55f8fd4457a099761493f53bcd3aa337097cc6399d0f3bb10ddf776637524a6df6a10ec1d09539b29f403c7c0b88e967dbd16b2328cb00fe58e05dca7b40a
7
- data.tar.gz: 74b9bb76222c203d73b9027bb73b98d1dde3b1e6b309a1adf9d58de781dfba1d84fc1695bf6be2c179cd77c3b4711d31f55fc51340e1a8a7865decb3fc9a585e
6
+ metadata.gz: c02c402318119a587eab2dca2bc7bbb414138ddefa4989364d8fc061bb2cb9cfcc858c2fdf219a49b8a036bee9dfd647b7834e7205604e442f317a5c4b5d69ab
7
+ data.tar.gz: 37fcd0ad903e100fd9c1537267770a15dfe1edf28f5b2a7820493c1931e74df5f9d7971f20d6e1c9593e0f5b6a9e2e1ca85fe8821d7a4ac01d7fe23719076dc8
@@ -5,15 +5,13 @@ require 'hinoki/connection'
5
5
  class Hinoki
6
6
  module Aggregates
7
7
 
8
- @conn = Hinoki::Connection.new
9
-
10
8
  # Return a list of all aggregates
11
9
  def self.all(limit=nil, offset=nil)
12
10
  url = "/aggregates"
13
11
  if limit then url.append("?limit=#{limit}") end
14
12
  if offset then url.append("&offset=#{offset}") end
15
13
 
16
- return @conn.get(url)
14
+ return Hinoki.conn.get(url)
17
15
  end
18
16
 
19
17
  # Return a specific aggregate check
@@ -21,12 +19,12 @@ class Hinoki
21
19
  url = "/aggregates/#{name}"
22
20
  if age then url.append("?age=#{age}") end
23
21
 
24
- return @conn.get(url)
22
+ return Hinoki.conn.get(url)
25
23
  end
26
24
 
27
25
  # Delete an aggregate check
28
26
  def self.delete(name)
29
- return @conn.delete("/aggregates/#{name}")
27
+ return Hinoki.conn.delete("/aggregates/#{name}")
30
28
  end
31
29
 
32
30
  # Returns the list of aggregates
@@ -40,7 +38,7 @@ class Hinoki
40
38
  url.append("?results=#{results}")
41
39
  end
42
40
 
43
- return @conn.get(url)
41
+ return Hinoki.conn.get(url)
44
42
  end
45
43
 
46
44
  end
data/lib/hinoki/base.rb CHANGED
@@ -10,8 +10,8 @@ require 'hinoki/stashes'
10
10
  class Hinoki
11
11
  attr_accessor(:aggregates, :clients, :checks, :events, :stashes)
12
12
 
13
- def initialize
14
- @conn = Hinoki::Connection.new
13
+ def initialize(host=nil, port=nil)
14
+ @@conn = Hinoki::Connection.new(host, port)
15
15
  @aggregates = Hinoki::Aggregates
16
16
  @checks = Hinoki::Checks
17
17
  @clients = Hinoki::Clients
@@ -19,14 +19,18 @@ class Hinoki
19
19
  @stashes = Hinoki::Stashes
20
20
  end
21
21
 
22
+ # Helper for modules to grab onto the connection
23
+ def self.conn
24
+ @@conn
25
+ end
26
+
22
27
  # Delivers information about Sensu and RabbitMQ performance
23
28
  def health(consumers=1, messages=1)
24
- return @conn.get("/health?consumers=#{consumers}&messages=#{messages}")
29
+ return self.conn.get("/health?consumers=#{consumers}&messages=#{messages}")
25
30
  end
26
31
 
27
32
  # Metadata about the Sensu installation
28
33
  def info
29
- return @conn.get('/info')
34
+ return self.conn.get('/info')
30
35
  end
31
-
32
36
  end
data/lib/hinoki/checks.rb CHANGED
@@ -5,23 +5,21 @@ require 'hinoki/connection'
5
5
  class Hinoki
6
6
  module Checks
7
7
 
8
- @conn = Hinoki::Connection.new
9
-
10
8
  # Lists all checks
11
9
  def self.all
12
- return @conn.get('/checks')
10
+ return Hinoki.conn.get('/checks')
13
11
  end
14
12
 
15
13
  # Returns info about a specific check
16
14
  def self.by_name(check)
17
- return @conn.get("/checks/#{check}")
15
+ return Hinoki.conn.get("/checks/#{check}")
18
16
  end
19
17
 
20
18
  # Request a check to be run
21
19
  def self.request(check, subscribers=[])
22
20
  payload = JSON.generate({check: check, subscribers: subscribers})
23
21
 
24
- return @conn.post("/checks", payload)
22
+ return Hinoki.conn.post("/checks", payload)
25
23
  end
26
24
 
27
25
  end
@@ -5,30 +5,28 @@ require 'hinoki/connection'
5
5
  class Hinoki
6
6
  module Clients
7
7
 
8
- @conn = Hinoki::Connection.new
9
-
10
8
  # Retrieves list of all clients
11
9
  def self.all(limit=nil, offset=nil)
12
10
  url = "/clients"
13
11
  if limit then url.append("?limit=#{limit}") end
14
12
  if offset then url.append("&offset=#{offset}") end
15
13
 
16
- return @conn.get(url)
14
+ return Hinoki.conn.get(url)
17
15
  end
18
16
 
19
17
  # Gets info about a specific client
20
18
  def self.by_name(client)
21
- return @conn.get("/clients/#{client}")
19
+ return Hinoki.conn.get("/clients/#{client}")
22
20
  end
23
21
 
24
22
  # Deletes a client (and resolves its events)
25
23
  def self.delete(client)
26
- return @conn.delete("/clients/#{client}")
24
+ return Hinoki.conn.delete("/clients/#{client}")
27
25
  end
28
26
 
29
27
  # Gets recent history of this client's status
30
28
  def self.history(client)
31
- return @conn.get("/clients/#{client}/history")
29
+ return Hinoki.conn.get("/clients/#{client}/history")
32
30
  end
33
31
 
34
32
  end
@@ -7,9 +7,9 @@ require 'hinoki/config'
7
7
  class Hinoki
8
8
  class Connection
9
9
 
10
- def initialize
10
+ def initialize(host=nil, port=nil)
11
11
  @config = Hinoki::Config.new
12
- @http = Net::HTTP.new(@config.host, @config.port)
12
+ @http = Net::HTTP.new(host || @config.host, port || @config.port)
13
13
  end
14
14
 
15
15
  # Wrapper around Net::HTTP.get
data/lib/hinoki/events.rb CHANGED
@@ -5,21 +5,19 @@ require 'hinoki/connection'
5
5
  class Hinoki
6
6
  module Events
7
7
 
8
- @conn = Hinoki::Connection.new
9
-
10
8
  # Lists all events
11
9
  def self.all
12
- return @conn.get('/events')
10
+ return Hinoki.conn.get('/events')
13
11
  end
14
12
 
15
13
  # Returns events associated with the given client
16
14
  def self.for_client(client)
17
- return @conn.get("/events/#{client}")
15
+ return Hinoki.conn.get("/events/#{client}")
18
16
  end
19
17
 
20
18
  # Clears an event from Sensu
21
19
  def self.resolve(client, check)
22
- return @conn.delete("/events/#{client}/#{check}")
20
+ return Hinoki.conn.delete("/events/#{client}/#{check}")
23
21
  end
24
22
 
25
23
  end
@@ -6,15 +6,13 @@ require 'hinoki/connection'
6
6
  class Hinoki
7
7
  module Stashes
8
8
 
9
- @conn = Hinoki::Connection.new
10
-
11
9
  # Lists all stashes
12
10
  def self.all(limit=nil, offset=nil)
13
11
  url = "/stashes"
14
12
  if limit then url.append("?limit=#{limit}") end
15
13
  if offset then url.append("&offset=#{offset}") end
16
14
 
17
- return @conn.get(url)
15
+ return Hinoki.conn.get(url)
18
16
  end
19
17
 
20
18
  # Add a new stash (JSON formatted)
@@ -25,17 +23,17 @@ class Hinoki
25
23
  post = Net::HTTP::Post.new('/stashes')
26
24
  post.body=JSON.generate(hash)
27
25
 
28
- return @conn.request(post)
26
+ return Hinoki.conn.request(post)
29
27
  end
30
28
 
31
29
  # Get information about a specific stash
32
30
  def self.by_name(stash)
33
- return @conn.get("/stashes/#{stash}")
31
+ return Hinoki.conn.get("/stashes/#{stash}")
34
32
  end
35
33
 
36
34
  # Remove a stash
37
35
  def self.delete(stash)
38
- return @conn.delete("/stashes/#{stash}")
36
+ return Hinoki.conn.delete("/stashes/#{stash}")
39
37
  end
40
38
 
41
39
  end
@@ -1,5 +1,5 @@
1
1
  # hinoki/version.rb
2
2
 
3
3
  class Hinoki
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Hinoki::Clients do
5
+ before do
6
+ @hinoki = Hinoki.new(host: 'hinoki.test', port: 4567)
7
+ end
8
+
9
+ describe '#all' do
10
+ it 'should return a list of all clients' do
11
+ stub_request(:get, "http://hinoki.test:4567/clients")
12
+
13
+ @hinoki.clients.all.should be_a(Array)
14
+ end
15
+ end
16
+
17
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hinoki do
4
+ end
@@ -0,0 +1,2 @@
1
+ require 'hinoki'
2
+ require 'webmock/rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hinoki
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-25 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A programmatic CLI utility for interacting with the Sensu API
14
14
  email: jake.davis5989@gmail.com
@@ -29,6 +29,14 @@ files:
29
29
  - lib/hinoki/events.rb
30
30
  - lib/hinoki/stashes.rb
31
31
  - lib/hinoki/version.rb
32
+ - spec/hinoki/aggregates_spec.rb
33
+ - spec/hinoki/checks_spec.rb
34
+ - spec/hinoki/clients_spec.rb
35
+ - spec/hinoki/events_spec.rb
36
+ - spec/hinoki/generic_spec.rb
37
+ - spec/hinoki/stashes_spec.rb
38
+ - spec/hinoki_spec.rb
39
+ - spec/spec_helper.rb
32
40
  homepage: http://github.com/jakedavis/hinoki
33
41
  licenses:
34
42
  - Apache 2.0