Skip to content

Commit

Permalink
Added support for maintenance management + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AviIsraeli committed Jan 19, 2016
1 parent 49d00e5 commit 15a417b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/zabbixapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require "zabbixapi/classes/errors"
require "zabbixapi/classes/graphs"
require "zabbixapi/classes/hostgroups"
require "zabbixapi/classes/maintenance"
require "zabbixapi/classes/hosts"
require "zabbixapi/classes/items"
require "zabbixapi/classes/mediatypes"
Expand Down Expand Up @@ -72,6 +73,10 @@ def hostgroups
@hostgroups ||= HostGroups.new(@client)
end

def maintenance
@maintenance ||= Maintenance.new(@client)
end

def triggers
@triggers ||= Triggers.new(@client)
end
Expand Down
13 changes: 13 additions & 0 deletions lib/zabbixapi/classes/maintenance.rb
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
81 changes: 81 additions & 0 deletions spec/maintenance.rb
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

0 comments on commit 15a417b

Please sign in to comment.