-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for maintenance management + tests
- Loading branch information
1 parent
49d00e5
commit 15a417b
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ZabbixApi | ||
class Maintenance < Basic | ||
|
||
def method_name | ||
"maintenance" | ||
end | ||
|
||
def indentify | ||
"name" | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe 'maintenance' do | ||
context 'when not exists' do | ||
before :all do | ||
@hostgroupid = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}") | ||
end | ||
|
||
describe 'create' do | ||
it "should return integer id after creation" do | ||
maintenanceid = zbx.maintenance.create(:name => "maintenance_#{rand(1_000_000)}", | ||
:groupids => [ @hostgroupid ], | ||
:active_since => 1358844540, | ||
:active_till => 1390466940, | ||
:timeperiods => [ :timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64800, :period => 3600 ] | ||
) | ||
expect(maintenanceid).to be_kind_of(Integer) | ||
zbx.maintenance.delete(maintenanceid) | ||
end | ||
end | ||
|
||
after :all do | ||
zbx.hostgroups.delete(@hostgroupid) | ||
end | ||
|
||
end | ||
|
||
context 'when exists' do | ||
before :all do | ||
@hostgroupid_when_exists = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}") | ||
@maintenance = gen_name('maintenance') | ||
@maintenanceid = zbx.maintenance.create(:name => @maintenance, | ||
:groupids => [ @hostgroupid_when_exists ], | ||
:active_since => 1358844540, | ||
:active_till => 1390466940, | ||
:timeperiods => [ :timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64800, :period => 3600 ] | ||
) | ||
end | ||
|
||
describe 'get_id' do | ||
it "should return id" do | ||
zbx.maintenance.get_id(:name => @maintenance).should eq @maintenanceid | ||
end | ||
|
||
it "should return nil for not existing group" do | ||
zbx.maintenance.get_id(:name => "#{@maintenance}______").should be_kind_of(NilClass) | ||
end | ||
end | ||
|
||
describe 'get_or_create' do | ||
it "should return id of existing maintenance" do | ||
zbx.maintenance.get_or_create(:name => @maintenance).should eq @maintenanceid | ||
end | ||
end | ||
|
||
describe 'create_or_update' do | ||
it "should return id of maintenance" do | ||
zbx.maintenance.create_or_update(:name => @maintenance).should eq @maintenanceid | ||
end | ||
end | ||
|
||
describe 'all' do | ||
it "should contains created maintenance" do | ||
zbx.maintenance.all.should include(@maintenance => @maintenanceid.to_s) | ||
end | ||
end | ||
|
||
describe "delete" do | ||
it "shold return id" do | ||
zbx.maintenance.delete(@maintenanceid).should eq @maintenanceid | ||
end | ||
end | ||
|
||
after :all do | ||
zbx.hostgroups.delete(@hostgroupid_when_exists) | ||
end | ||
|
||
end | ||
end |