rubix 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +10 -10
- data/VERSION +1 -1
- data/lib/rubix.rb +40 -1
- data/lib/rubix/associations/belongs_to_host.rb +4 -3
- data/lib/rubix/connection.rb +114 -34
- data/lib/rubix/log.rb +45 -1
- data/lib/rubix/models/model.rb +143 -9
- data/lib/rubix/response.rb +85 -13
- data/lib/rubix/sender.rb +122 -18
- data/spec/requests/application_request_spec.rb +36 -38
- data/spec/requests/host_group_request_spec.rb +40 -22
- data/spec/requests/host_request_spec.rb +55 -49
- data/spec/requests/item_request_spec.rb +49 -53
- data/spec/requests/template_request_spec.rb +34 -34
- data/spec/requests/user_macro_request_spec.rb +33 -27
- data/spec/spec_helper.rb +1 -13
- data/spec/support/integration_helper.rb +34 -1
- data/spec/test.yml +11 -3
- metadata +22 -8
@@ -1,63 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Hosts" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
7
|
-
ensure_save(
|
8
|
-
|
9
|
-
@hg2 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2')
|
10
|
-
ensure_save(@hg2)
|
11
|
-
|
12
|
-
@t1 = Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@hg1])
|
13
|
-
ensure_save(@t1)
|
14
|
-
|
15
|
-
@t2 = Rubix::Template.new(:name => 'rubix_spec_template_2', :host_groups => [@hg2])
|
16
|
-
ensure_save(@t2)
|
6
|
+
integration_test
|
7
|
+
@host_group_1 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1'))
|
17
8
|
|
18
|
-
@um1 = Rubix::UserMacro.new(:name => 'rubix_spec_macro_1', :value => 'rubix_spec_value_1')
|
19
|
-
|
20
9
|
end
|
21
10
|
|
22
11
|
after do
|
23
|
-
|
12
|
+
truncate_all_tables
|
24
13
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
14
|
+
|
15
|
+
describe "when not existing" do
|
16
|
+
|
17
|
+
it "returns nil on find" do
|
18
|
+
Rubix::Host.find(:name => 'rubix_spec_host_1').should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can be created" do
|
22
|
+
host = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group_1])
|
23
|
+
host.save.should be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when existing" do
|
28
|
+
before do
|
29
|
+
@host_group_2 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2'))
|
30
|
+
@host = ensure_save(Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group_1]))
|
31
|
+
@template_1 = ensure_save(Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@host_group_2]))
|
32
|
+
@template_2 = ensure_save(Rubix::Template.new(:name => 'rubix_spec_template_2', :host_groups => [@host_group_2]))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can have its name changed" do
|
36
|
+
@host.name = 'rubix_spec_host_2'
|
37
|
+
@host.save
|
38
|
+
|
39
|
+
Rubix::Host.find(:name => 'rubix_spec_host_1').should be_nil
|
40
|
+
Rubix::Host.find(:name => 'rubix_spec_host_2').should_not be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can change its host groups" do
|
44
|
+
@host.host_groups = [@host_group_1, @host_group_2]
|
45
|
+
@host.save
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
new_host = Rubix::Host.find(:name => 'rubix_spec_host_1')
|
48
|
+
new_host.should_not be_nil
|
49
|
+
new_host.host_groups.size.should == 2
|
50
|
+
new_host.host_groups.map(&:name).should include('rubix_spec_host_group_1', 'rubix_spec_host_group_2')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can change its templates" do
|
54
|
+
@host.templates = [@template_1, @template_2]
|
55
|
+
@host.save
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
h2.user_macros.size.should == 1
|
55
|
-
h2.user_macros.first.name.should == 'RUBIX_SPEC_MACRO_1'
|
56
|
-
h2.user_macros.first.value.should == 'rubix_spec_value_1'
|
57
|
-
|
58
|
-
h1.destroy
|
59
|
-
Rubix::Host.find(:id => id).should be_nil
|
57
|
+
new_host = Rubix::Host.find(:name => 'rubix_spec_host_1')
|
58
|
+
new_host.should_not be_nil
|
59
|
+
new_host.templates.size.should == 2
|
60
|
+
new_host.templates.map(&:name).should include('rubix_spec_template_1', 'rubix_spec_template_2')
|
60
61
|
end
|
61
|
-
|
62
|
+
|
63
|
+
it "can be destroyed" do
|
64
|
+
@host.destroy
|
65
|
+
Rubix::Host.find(:name => 'rubix_spec_host_1').should be_nil
|
66
|
+
end
|
67
|
+
|
62
68
|
end
|
63
69
|
end
|
@@ -1,65 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Items" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
7
|
-
ensure_save(
|
8
|
-
|
9
|
-
@
|
10
|
-
ensure_save(@
|
11
|
-
|
12
|
-
@h2 = Rubix::Host.new(:name => 'rubix_spec_host_2', :host_groups => [@hg1])
|
13
|
-
ensure_save(@h2)
|
14
|
-
|
15
|
-
@a1 = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @h1.id)
|
16
|
-
ensure_save(@a1)
|
17
|
-
|
18
|
-
@a2 = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @h2.id)
|
19
|
-
ensure_save(@a2)
|
6
|
+
integration_test
|
7
|
+
@host_group = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1'))
|
8
|
+
@host_1 = ensure_save(Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group]))
|
9
|
+
@host_2 = ensure_save(Rubix::Host.new(:name => 'rubix_spec_host_2', :host_groups => [@host_group]))
|
10
|
+
@app_1 = ensure_save(Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @host_1.id))
|
11
|
+
@app_2 = ensure_save(Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @host_2.id))
|
20
12
|
end
|
21
13
|
|
22
14
|
after do
|
23
|
-
|
15
|
+
truncate_all_tables
|
24
16
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
|
18
|
+
describe "when not existing" do
|
19
|
+
|
20
|
+
it "returns nil on find" do
|
21
|
+
Rubix::Item.find(:key => 'rubix.spec1', :host_id => @host_1.id).should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can be created" do
|
25
|
+
item = Rubix::Item.new(:key => 'rubix.spec1', :description => 'rubix item description 1', :host_id => @host_1.id, :value_type => :character, :applications => [@app_1])
|
26
|
+
item.save.should be_true
|
27
|
+
item.host.name.should == @host_1.name
|
28
|
+
item.applications.map(&:name).should include(@app_1.name)
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Rubix::Item.find(:
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when existing" do
|
34
|
+
|
35
|
+
before do
|
36
|
+
@item = ensure_save(Rubix::Item.new(:key => 'rubix.spec1', :description => 'rubix item description 1', :host_id => @host_1.id, :value_type => :character, :applications => [@app_1]))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can have its host, application, and properties updated" do
|
40
|
+
@item.key = 'rubix.spec2'
|
41
|
+
@item.description = 'rubix item description 2'
|
42
|
+
@item.value_type = :unsigned_int
|
43
|
+
@item.host_id = @host_2.id
|
44
|
+
@item.applications = [@app_2]
|
45
|
+
@item.save.should be_true
|
46
|
+
|
47
|
+
Rubix::Item.find(:key => 'rubix.spec1', :host_id => @host_1.id).should be_nil
|
48
|
+
|
49
|
+
new_item = Rubix::Item.find(:key => 'rubix.spec2', :host_id => @host_2.id)
|
50
|
+
new_item.should_not be_nil
|
51
|
+
new_item.host.name.should == @host_2.name
|
52
|
+
new_item.applications.map(&:name).should include(@app_2.name)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can be destroyed" do
|
56
|
+
@item.destroy
|
57
|
+
Rubix::Item.find(:key => 'rubix.spec1', :host_id => @host_1.id).should be_nil
|
63
58
|
end
|
64
59
|
end
|
65
60
|
end
|
61
|
+
|
@@ -1,51 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Templates" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
7
|
-
ensure_save(
|
8
|
-
|
9
|
-
@hg2 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2')
|
10
|
-
ensure_save(@hg2)
|
6
|
+
integration_test
|
7
|
+
@host_group_1 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1'))
|
8
|
+
@host_group_2 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2'))
|
11
9
|
end
|
12
10
|
|
13
11
|
after do
|
14
|
-
|
12
|
+
truncate_all_tables
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
describe "when not existing" do
|
16
|
+
|
17
|
+
it "returns nil on find" do
|
18
|
+
Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can be created" do
|
22
|
+
template = Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@host_group_1])
|
23
|
+
template.save.should be_true
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
t1.save.should be_true
|
36
|
-
|
37
|
-
t2 = Rubix::Template.find(:id => id)
|
38
|
-
t2.name.should == 'rubix_spec_template_2'
|
39
|
-
t2.host_group_ids.should_not include(@hg1.id)
|
40
|
-
t2.host_group_ids.should include(@hg2.id)
|
41
|
-
|
42
|
-
t1.destroy
|
43
|
-
Rubix::Template.find(:id => id).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "when existing" do
|
29
|
+
|
30
|
+
before do
|
31
|
+
@template = ensure_save(Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@host_group_1]))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can have its name changed" do
|
35
|
+
@template.name = 'rubix_spec_template_2'
|
36
|
+
@template.save
|
37
|
+
Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil
|
38
|
+
Rubix::Template.find(:name => 'rubix_spec_template_2').should_not be_nil
|
44
39
|
end
|
40
|
+
|
41
|
+
it "can be destroyed" do
|
42
|
+
@template.destroy
|
43
|
+
Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil
|
44
|
+
end
|
45
|
+
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should be able to import and export a template" do
|
48
|
-
integration_test
|
49
49
|
pending "Learning how to import/export XML via the API"
|
50
50
|
end
|
51
51
|
|
@@ -1,43 +1,49 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "User Macros" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
7
|
-
ensure_save(
|
8
|
-
|
9
|
-
@h1 = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@hg1])
|
10
|
-
ensure_save(@h1)
|
6
|
+
integration_test
|
7
|
+
@host_group = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1'))
|
8
|
+
@host = ensure_save(Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group]))
|
11
9
|
end
|
12
10
|
|
13
11
|
after do
|
14
|
-
|
12
|
+
truncate_all_tables
|
15
13
|
end
|
16
|
-
|
17
|
-
it "should be able to create, update, and destroy a host" do
|
18
|
-
integration_test
|
19
|
-
|
20
|
-
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @h1.id).should be_nil
|
21
|
-
|
22
|
-
um1 = Rubix::UserMacro.new(:name => 'rubix_spec_macro_1', :value => 'rubix_spec_value_1', :host_id => @h1.id)
|
23
|
-
um1.save.should be_true
|
24
14
|
|
25
|
-
|
26
|
-
id.should_not be_nil
|
15
|
+
describe "when not existing" do
|
27
16
|
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
it "returns nil on find" do
|
18
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @host.id).should be_nil
|
19
|
+
end
|
31
20
|
|
32
|
-
|
33
|
-
|
21
|
+
it "can be created" do
|
22
|
+
um = Rubix::UserMacro.new(:name => 'rubix_spec_macro_1', :value => 'rubix_spec_value_1', :host_id => @host.id)
|
23
|
+
um.save.should be_true
|
24
|
+
end
|
34
25
|
|
35
|
-
|
36
|
-
um2.should_not be_nil
|
37
|
-
um2.value.should == 'rubix_spec_value_2'
|
26
|
+
end
|
38
27
|
|
39
|
-
|
40
|
-
|
28
|
+
describe "when existing" do
|
29
|
+
|
30
|
+
before do
|
31
|
+
@macro = ensure_save(Rubix::UserMacro.new(:name => 'rubix_spec_macro_1', :value => 'rubix_spec_value_1', :host_id => @host.id))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can have its value changed" do
|
35
|
+
@macro.value = 'rubix_spec_value_2'
|
36
|
+
@macro.save
|
37
|
+
|
38
|
+
new_macro = Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @host.id)
|
39
|
+
new_macro.should_not be_nil
|
40
|
+
new_macro.value.should == 'rubix_spec_value_2'
|
41
41
|
end
|
42
|
+
|
43
|
+
it "can be destroyed" do
|
44
|
+
@macro.destroy
|
45
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @host.id).should be_nil
|
46
|
+
end
|
47
|
+
|
42
48
|
end
|
43
49
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,17 +15,5 @@ RSpec.configure do |config|
|
|
15
15
|
config.include Rubix::IntegrationHelper
|
16
16
|
config.include Rubix::ConfigliereHelper
|
17
17
|
|
18
|
-
|
19
|
-
if File.exist?(test_yml_path)
|
20
|
-
require 'yaml'
|
21
|
-
test_data = YAML.load(open(test_yml_path))
|
22
|
-
if test_data['disable_integration_tests']
|
23
|
-
$RUBIX_INTEGRATION_TEST = false
|
24
|
-
else
|
25
|
-
Rubix.connect(test_data['url'], test_data['username'], test_data['password'])
|
26
|
-
$RUBIX_INTEGRATION_TEST = true
|
27
|
-
end
|
28
|
-
else
|
29
|
-
$RUBIX_INTEGRATION_TEST = false
|
30
|
-
end
|
18
|
+
Rubix::IntegrationHelper.setup_integration_tests(File.expand_path('../test.yml', __FILE__))
|
31
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Rubix
|
2
2
|
module IntegrationHelper
|
3
|
-
|
3
|
+
|
4
4
|
def integration_test
|
5
5
|
pending("A live Zabbix API to test against") unless $RUBIX_INTEGRATION_TEST
|
6
6
|
end
|
@@ -8,6 +8,7 @@ module Rubix
|
|
8
8
|
def ensure_save(obj)
|
9
9
|
begin
|
10
10
|
raise Rubix::Error.new(Rubix.connection.last_response.error_message) unless obj.save
|
11
|
+
obj
|
11
12
|
rescue => e
|
12
13
|
puts "#{e.class} -- #{e.message}"
|
13
14
|
puts e.backtrace
|
@@ -41,6 +42,38 @@ module Rubix
|
|
41
42
|
raise e
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
def self.setup_integration_tests test_yml_path
|
47
|
+
return unless File.exist?(test_yml_path)
|
48
|
+
|
49
|
+
require 'yaml'
|
50
|
+
test_data = YAML.load(open(test_yml_path))
|
51
|
+
return if test_data['disable_integration_tests']
|
52
|
+
|
53
|
+
api_connection = test_data['api']
|
54
|
+
mysql_connection = test_data['mysql']
|
55
|
+
return unless api_connection && mysql_connection
|
56
|
+
|
57
|
+
Rubix.connect(api_connection['url'], api_connection['username'], api_connection['password'])
|
58
|
+
|
59
|
+
require 'mysql2'
|
60
|
+
$RUBIX_MYSQL_CLIENT = Mysql2::Client.new(:host => mysql_connection['host'], :username => mysql_connection['username'], :password => mysql_connection['password'], :database => mysql_connection['database'])
|
61
|
+
|
62
|
+
truncate_all_tables
|
63
|
+
|
64
|
+
$RUBIX_INTEGRATION_TEST = true
|
65
|
+
end
|
66
|
+
|
67
|
+
RUBIX_TABLES_TO_TRUNCATE = %w[applications groups hostmacro hosts hosts_groups hosts_profiles hosts_profiles_ext hosts_templates items items_applications profiles triggers]
|
68
|
+
|
69
|
+
def self.truncate_all_tables
|
70
|
+
return unless $RUBIX_INTEGRATION_TEST
|
71
|
+
RUBIX_TABLES_TO_TRUNCATE.each { |table| $RUBIX_MYSQL_CLIENT.query("TRUNCATE TABLE #{table}") }
|
72
|
+
end
|
73
|
+
|
74
|
+
def truncate_all_tables
|
75
|
+
IntegrationHelper.truncate_all_tables
|
76
|
+
end
|
44
77
|
|
45
78
|
end
|
46
79
|
end
|