forked from markt-de/zabbixapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.rb
More file actions
148 lines (131 loc) · 3.73 KB
/
template.rb
File metadata and controls
148 lines (131 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#encoding: utf-8
require "spec_helper"
describe "template" do
before :all do
@hostgroup = gen_name "hostgroup"
@hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
end
context "when name not exists" do
before do
@template = gen_name "template"
end
describe "create" do
it "should return integer id" do
templateid = zbx.templates.create(
:host => @template,
:groups => [:groupid => @hostgroupid]
)
templateid.should be_kind_of(Integer)
end
end
describe "get_id" do
it "should return nil" do
expect(zbx.templates.get_id(:host => @template)).to be_kind_of(NilClass)
end
end
end
context "when name exists" do
before :all do
@template = gen_name "template"
@templateid = zbx.templates.create(
:host => @template,
:groups => [:groupid => @hostgroupid]
)
end
describe "get_or_create" do
it "should return id of template" do
expect(zbx.templates.get_or_create(
:host => @template,
:groups => [:groupid => @hostgroupid]
)).to eq @templateid
end
end
describe "get_full_data" do
it "should contains created template" do
expect(zbx.templates.get_full_data(:host => @template)[0]).to include("host" => @template)
end
end
describe "get_id" do
it "should return id of template" do
expect(zbx.templates.get_id(:host => @template)).to eq @templateid
end
end
describe "all" do
it "should contains template" do
zbx.templates.all.should include(@template => @templateid.to_s)
end
end
describe "delete" do
it "should return id" do
template = gen_name "template"
templateid = zbx.templates.create(
:host => template,
:groups => [:groupid => @hostgroupid]
)
zbx.templates.delete(templateid).should eq templateid
end
end
context "host related operations" do
before :all do
@host = gen_name 'host'
@hostid = zbx.hosts.create(
:host => @host,
:interfaces => [
{
:type => 1,
:main => 1,
:ip => "10.20.48.88",
:dns => "",
:port => 10050,
:useip => 1
}
],
:groups => [:groupid => @hostgroupid]
)
end
context "not linked with host" do
describe "mass_update" do
it "should return true" do
zbx.templates.mass_update(
:hosts_id => [@hostid],
:templates_id => [@templateid]
).should be_true
end
end
end
context "linked with host" do
before :all do
zbx.templates.mass_update(
:hosts_id => [@hostid],
:templates_id => [@templateid]
)
end
describe "get_ids_by_host" do
it "should contains id of linked template" do
tmpl_array = zbx.templates.get_ids_by_host(
:hostids => [@hostid]
)
tmpl_array.should be_kind_of(Array)
tmpl_array.should include @templateid.to_s
end
end
describe "mass_add" do
it "should return true" do
zbx.templates.mass_add(
:hosts_id => [@hostid],
:templates_id => [@templateid]
).should be_kind_of(TrueClass)
end
end
describe "mass_remove" do
it "should return true" do
zbx.templates.mass_remove(
:hosts_id => [@hostid],
:templates_id => [@templateid]
).should be_true
end
end
end
end
end
end