icinga 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,12 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ `````
22
+ require 'icinga'
23
+
24
+ server = Icinga::Server.new(:host => "mon.example.com")
25
+ puts server.hosts
26
+ `````
22
27
 
23
28
  ## Contributing
24
29
 
data/icinga.gemspec CHANGED
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency 'rake'
21
21
  gem.add_development_dependency 'rspec'
22
+
23
+ gem.add_runtime_dependency 'json'
22
24
  end
data/lib/icinga/server.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'json'
2
3
 
3
4
  module Icinga
4
5
  class Server
@@ -10,11 +11,23 @@ module Icinga
10
11
  }
11
12
 
12
13
  def connection
13
- @conn ||= Net::HTTP.new(@host, @port)
14
+ @conn ||= Net::HTTP.new(@options[:host], @options[:port])
14
15
  end
15
16
 
16
17
  def new_request(path)
17
- Net::HTTP::Get.new(path)
18
+ req = Net::HTTP::Get.new(path)
19
+ req.basic_auth @options[:user], @options[:password] if @options[:user]
20
+ req
21
+ end
22
+
23
+ def hosts
24
+ resp = connection.request(new_request("/icinga/cgi-bin/status.cgi?hostgroup=all&style=hostdetail&jsonoutput"))
25
+ JSON.parse(resp.body)
26
+ end
27
+
28
+ def services
29
+ resp = connection.request(new_request("/icinga/cgi-bin/status.cgi?host=all&style=servicedetail&jsonoutput"))
30
+ JSON.parse(resp.body)
18
31
  end
19
32
 
20
33
  def initialize(options={})
@@ -1,3 +1,3 @@
1
1
  module Icinga
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,4 +21,9 @@ describe Icinga::Server do
21
21
  it "should create a request" do
22
22
  @icinga.new_request("/").should be_kind_of(Net::HTTP::Get)
23
23
  end
24
+
25
+ it "should set basic auth" do
26
+ @icinga.options[:user] = "Foo"
27
+ @icinga.new_request("/").get_fields("Authorization").first.should match(/^Basic\s.*/)
28
+ end
24
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icinga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-12-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &8358620 !ruby/object:Gem::Requirement
16
+ requirement: &20152660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *8358620
24
+ version_requirements: *20152660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &8358040 !ruby/object:Gem::Requirement
27
+ requirement: &20152040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *8358040
35
+ version_requirements: *20152040
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &20151460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *20151460
36
47
  description: Facilitates communication with Icinga servers.
37
48
  email:
38
49
  - jbussdieker@gmail.com