icinga 0.0.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icinga/responder.rb +32 -0
- data/lib/icinga/server.rb +6 -7
- data/lib/icinga/version.rb +1 -1
- data/lib/icinga.rb +1 -0
- data/test/icinga/responder_spec.rb +24 -0
- data/test/icinga/server_spec.rb +14 -0
- metadata +11 -8
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Icinga
|
5
|
+
class Responder
|
6
|
+
def initialize(server, request)
|
7
|
+
@server = server
|
8
|
+
@request = request
|
9
|
+
end
|
10
|
+
|
11
|
+
def response
|
12
|
+
begin
|
13
|
+
@response ||= @server.connection.request(@request)
|
14
|
+
rescue Exception => e
|
15
|
+
e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
if response.kind_of? Net::HTTPSuccess
|
21
|
+
{:data => JSON.parse(response)} if @server.options[:format] == "json"
|
22
|
+
{:data => CSV.parse(response)} if @server.options[:format] == "csv"
|
23
|
+
else
|
24
|
+
{:error => response.message}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
data[:data] || ""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/icinga/server.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'net/http'
|
2
|
-
require 'json'
|
3
2
|
|
4
3
|
module Icinga
|
5
4
|
class Server
|
@@ -8,6 +7,8 @@ module Icinga
|
|
8
7
|
@@default_options = {
|
9
8
|
:host => "localhost",
|
10
9
|
:port => 80,
|
10
|
+
:remote_path => "/icinga/cgi-bin/status.cgi",
|
11
|
+
:format => "json",
|
11
12
|
}
|
12
13
|
|
13
14
|
def connection
|
@@ -15,22 +16,20 @@ module Icinga
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def new_request(path)
|
18
|
-
req = Net::HTTP::Get.new(path)
|
19
|
+
req = Net::HTTP::Get.new(@options[:remote_path] + path + "&" + @options[:format] + "output")
|
19
20
|
req.basic_auth @options[:user], @options[:password] if @options[:user]
|
20
21
|
req
|
21
22
|
end
|
22
23
|
|
23
24
|
def hosts
|
24
|
-
|
25
|
-
JSON.parse(resp.body)
|
25
|
+
Responder.new(self, new_request("?hostgroup=all&style=hostdetail"))
|
26
26
|
end
|
27
27
|
|
28
28
|
def services
|
29
|
-
|
30
|
-
JSON.parse(resp.body)
|
29
|
+
Responder.new(self, new_request("?host=all&style=servicedetail"))
|
31
30
|
end
|
32
31
|
|
33
|
-
def initialize(options={})
|
32
|
+
def initialize(options = {})
|
34
33
|
@options = @@default_options.merge(options)
|
35
34
|
end
|
36
35
|
end
|
data/lib/icinga/version.rb
CHANGED
data/lib/icinga.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'icinga'
|
2
|
+
|
3
|
+
describe Icinga::Responder do
|
4
|
+
before do
|
5
|
+
@server = Icinga::Server.new
|
6
|
+
@responder = Icinga::Responder.new(@server, @server.new_request(""))
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should create a response" do
|
10
|
+
@responder.response.should respond_to(:message)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond to data with parsed data" do
|
14
|
+
@responder.data.should be_kind_of(Hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should respond to data with error info" do
|
18
|
+
@responder.data[:error].should be_kind_of(String)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should respond with empty string for bad connection/request" do
|
22
|
+
@responder.to_s.should match(/^$/)
|
23
|
+
end
|
24
|
+
end
|
data/test/icinga/server_spec.rb
CHANGED
@@ -12,6 +12,20 @@ describe Icinga::Server do
|
|
12
12
|
it "should set the default host" do
|
13
13
|
@icinga.options[:host].should match("localhost")
|
14
14
|
end
|
15
|
+
it "should set the default remote path" do
|
16
|
+
@icinga.options[:remote_path].should match("/icinga/cgi-bin/status.cgi")
|
17
|
+
end
|
18
|
+
it "should set the default format" do
|
19
|
+
@icinga.options[:format].should match("json")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create a responder for hosts" do
|
24
|
+
@icinga.hosts.should be_kind_of(Icinga::Responder)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a responder for services" do
|
28
|
+
@icinga.services.should be_kind_of(Icinga::Responder)
|
15
29
|
end
|
16
30
|
|
17
31
|
it "should create a connection" do
|
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.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &13055080 !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: *
|
24
|
+
version_requirements: *13055080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &13054220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *13054220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &13053380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *13053380
|
47
47
|
description: Facilitates communication with Icinga servers.
|
48
48
|
email:
|
49
49
|
- jbussdieker@gmail.com
|
@@ -58,8 +58,10 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- icinga.gemspec
|
60
60
|
- lib/icinga.rb
|
61
|
+
- lib/icinga/responder.rb
|
61
62
|
- lib/icinga/server.rb
|
62
63
|
- lib/icinga/version.rb
|
64
|
+
- test/icinga/responder_spec.rb
|
63
65
|
- test/icinga/server_spec.rb
|
64
66
|
- test/icinga_spec.rb
|
65
67
|
homepage: http://github.com/jbussdieker/icinga
|
@@ -87,5 +89,6 @@ signing_key:
|
|
87
89
|
specification_version: 3
|
88
90
|
summary: Icinga API tools
|
89
91
|
test_files:
|
92
|
+
- test/icinga/responder_spec.rb
|
90
93
|
- test/icinga/server_spec.rb
|
91
94
|
- test/icinga_spec.rb
|