zabbixapi 0.6.6 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +11 -6
- data/README.md +21 -25
- data/lib/zabbixapi.rb +23 -10
- data/lib/zabbixapi/{1.8/basic → basic}/basic_alias.rb +0 -0
- data/lib/zabbixapi/{1.8/basic → basic}/basic_func.rb +3 -3
- data/lib/zabbixapi/{1.8/basic → basic}/basic_init.rb +0 -0
- data/lib/zabbixapi/{2.0/basic → basic}/basic_logic.rb +3 -3
- data/lib/zabbixapi/{1.8/classes → classes}/applications.rb +0 -0
- data/lib/zabbixapi/{1.8/classes → classes}/errors.rb +0 -0
- data/lib/zabbixapi/{1.8/classes → classes}/graphs.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/hostgroups.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/hosts.rb +4 -0
- data/lib/zabbixapi/{2.0/classes → classes}/items.rb +8 -0
- data/lib/zabbixapi/{1.8/classes → classes}/mediatypes.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/proxies.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/screens.rb +1 -19
- data/lib/zabbixapi/{1.8/classes → classes}/server.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/templates.rb +4 -4
- data/lib/zabbixapi/{1.8/classes → classes}/triggers.rb +0 -0
- data/lib/zabbixapi/{1.8/classes → classes}/unusable.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/usergroups.rb +0 -12
- data/lib/zabbixapi/{2.0/classes → classes}/usermacros.rb +0 -0
- data/lib/zabbixapi/{2.0/classes → classes}/users.rb +2 -2
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/application.rb +74 -0
- data/spec/basic_func.rb +4 -0
- data/spec/graph.rb +135 -0
- data/spec/host.rb +136 -0
- data/spec/hostgroup.rb +55 -0
- data/spec/item.rb +132 -0
- data/spec/mediatype.rb +47 -0
- data/spec/query.rb +13 -0
- data/spec/screen.rb +88 -0
- data/spec/server.rb +17 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/template.rb +148 -0
- data/spec/trigger.rb +74 -0
- data/spec/user.rb +99 -0
- data/spec/usergroup.rb +69 -0
- data/zabbixapi.gemspec +3 -3
- metadata +52 -44
- data/lib/zabbixapi/1.8/basic/basic_logic.rb +0 -103
- data/lib/zabbixapi/1.8/classes/hostgroups.rb +0 -26
- data/lib/zabbixapi/1.8/classes/hosts.rb +0 -58
- data/lib/zabbixapi/1.8/classes/items.rb +0 -54
- data/lib/zabbixapi/1.8/classes/screens.rb +0 -101
- data/lib/zabbixapi/1.8/classes/templates.rb +0 -109
- data/lib/zabbixapi/1.8/classes/usergroups.rb +0 -82
- data/lib/zabbixapi/1.8/classes/users.rb +0 -32
- data/lib/zabbixapi/2.0/basic/basic_alias.rb +0 -21
- data/lib/zabbixapi/2.0/basic/basic_func.rb +0 -55
- data/lib/zabbixapi/2.0/basic/basic_init.rb +0 -33
- data/lib/zabbixapi/2.0/classes/applications.rb +0 -45
- data/lib/zabbixapi/2.0/classes/errors.rb +0 -15
- data/lib/zabbixapi/2.0/classes/graphs.rb +0 -66
- data/lib/zabbixapi/2.0/classes/mediatypes.rb +0 -31
- data/lib/zabbixapi/2.0/classes/server.rb +0 -12
- data/lib/zabbixapi/2.0/classes/triggers.rb +0 -67
- data/lib/zabbixapi/2.0/classes/unusable.rb +0 -10
- data/spec/localhost.rb +0 -514
- data/spec/run.rb +0 -486
@@ -1,31 +0,0 @@
|
|
1
|
-
class ZabbixApi
|
2
|
-
class Mediatypes < Basic
|
3
|
-
|
4
|
-
def array_flag
|
5
|
-
true
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_name
|
9
|
-
"mediatype"
|
10
|
-
end
|
11
|
-
|
12
|
-
def indentify
|
13
|
-
"description"
|
14
|
-
end
|
15
|
-
|
16
|
-
def default_options
|
17
|
-
{
|
18
|
-
:description => "", #Name
|
19
|
-
:type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
|
20
|
-
:smtp_server => "",
|
21
|
-
:smtp_helo => "",
|
22
|
-
:smtp_email => "", #Email address of Zabbix server
|
23
|
-
:exec_path => "", #Name of external script
|
24
|
-
:gsm_modem => "", #Serial device name of GSM modem
|
25
|
-
:username => "", #Jabber user name used by Zabbix server
|
26
|
-
:passwd => "" #Jabber password used by Zabbix server
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
class ZabbixApi
|
2
|
-
class Triggers < Basic
|
3
|
-
|
4
|
-
def array_flag
|
5
|
-
true
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_name
|
9
|
-
"trigger"
|
10
|
-
end
|
11
|
-
|
12
|
-
def indentify
|
13
|
-
"description"
|
14
|
-
end
|
15
|
-
|
16
|
-
def dump_by_id(data)
|
17
|
-
log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
|
18
|
-
|
19
|
-
@client.api_request(
|
20
|
-
:method => "trigger.get",
|
21
|
-
:params => {
|
22
|
-
:filter => {
|
23
|
-
key.to_sym => data[key.to_sym]
|
24
|
-
},
|
25
|
-
:output => "extend",
|
26
|
-
:select_items => "extend",
|
27
|
-
:select_functions => "extend"
|
28
|
-
}
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
def safe_update(data)
|
33
|
-
log "[DEBUG] Call update with parametrs: #{data.inspect}"
|
34
|
-
|
35
|
-
dump = {}
|
36
|
-
item_id = data[key.to_sym].to_i
|
37
|
-
dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
|
38
|
-
dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
|
39
|
-
end
|
40
|
-
|
41
|
-
expression = dump[:items][0][:key_]+"."+dump[:functions][0][:function]+"("+dump[:functions][0][:parameter]+")"
|
42
|
-
dump[:expression] = dump[:expression].gsub(/\{(\d*)\}/,"{#{expression}}") #TODO ugly regexp
|
43
|
-
dump.delete(:functions)
|
44
|
-
dump.delete(:items)
|
45
|
-
|
46
|
-
old_expression = data[:expression]
|
47
|
-
data[:expression] = data[:expression].gsub(/\{.*\:/,"{") #TODO ugly regexp
|
48
|
-
data.delete(:templateid)
|
49
|
-
|
50
|
-
log "[DEBUG] expression: #{dump[:expression]}\n data: #{data[:expression]}"
|
51
|
-
|
52
|
-
if hash_equals?(dump, data)
|
53
|
-
log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
|
54
|
-
item_id
|
55
|
-
else
|
56
|
-
data[:expression] = old_expression
|
57
|
-
# disable old trigger
|
58
|
-
log "[DEBUG] disable :" + @client.api_request(:method => "#{method_name}.update", :params => [{:triggerid=> data[:triggerid], :status => "1" }]).inspect
|
59
|
-
# create new trigger
|
60
|
-
data.delete(:triggerid)
|
61
|
-
create(data)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
data/spec/localhost.rb
DELETED
@@ -1,514 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require 'rspec'
|
3
|
-
require 'zabbixapi'
|
4
|
-
|
5
|
-
# settings
|
6
|
-
api_url = 'http://zabbix/api_jsonrpc.php'
|
7
|
-
#api_url = 'http://zabbix/zabbix20/api_jsonrpc.php'
|
8
|
-
|
9
|
-
api_login = 'Admin'
|
10
|
-
api_password = 'zabbix'
|
11
|
-
|
12
|
-
zbx = ZabbixApi.connect(
|
13
|
-
:url => api_url,
|
14
|
-
:user => api_login,
|
15
|
-
:password => api_password,
|
16
|
-
:debug => false
|
17
|
-
)
|
18
|
-
|
19
|
-
hostgroup = "hostgroup______1"
|
20
|
-
template = "template______1"
|
21
|
-
application = "application_____1"
|
22
|
-
item = "item_____1"
|
23
|
-
host = "hostname____1"
|
24
|
-
trigger = "trigger____1" #TODO !saDSASDAS
|
25
|
-
user = "user____1"
|
26
|
-
user2 = "user____2"
|
27
|
-
usergroup = "SomeUserGroup"
|
28
|
-
graph = "graph___a"
|
29
|
-
mediatype = "somemediatype"
|
30
|
-
|
31
|
-
hostgroupid = 0
|
32
|
-
templateid = 0
|
33
|
-
applicationid = 0
|
34
|
-
itemid = 0
|
35
|
-
hostid = 0
|
36
|
-
triggerid = 0
|
37
|
-
userid = 0
|
38
|
-
usergroupid = 0
|
39
|
-
graphid = 0
|
40
|
-
screenid = 0
|
41
|
-
mediatypeid = 0
|
42
|
-
|
43
|
-
|
44
|
-
puts "### Zabbix API server version #{zbx.server.version} ###"
|
45
|
-
|
46
|
-
describe ZabbixApi do
|
47
|
-
|
48
|
-
it "SERVER: Get version api" do
|
49
|
-
zbx.server.version.should be_kind_of(String)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "HOSTGROUP: Create" do
|
53
|
-
hostgroupid = zbx.hostgroups.create(:name => hostgroup)
|
54
|
-
hostgroupid.should be_kind_of(Integer)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "HOSTGROUP: Find" do
|
58
|
-
zbx.hostgroups.get_id(:name => hostgroup).should eq hostgroupid
|
59
|
-
end
|
60
|
-
|
61
|
-
it "HOSTGROUP: Find unknown" do
|
62
|
-
zbx.hostgroups.get_id(:name => "#{hostgroup}______").should be_kind_of(NilClass)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "HOSTGROUP: Create or get" do
|
66
|
-
zbx.hostgroups.get_or_create(:name => hostgroup).should eq hostgroupid
|
67
|
-
end
|
68
|
-
|
69
|
-
it "HOSTGROUP: Create or update" do
|
70
|
-
zbx.hostgroups.create_or_update(:name => hostgroup).should eq hostgroupid
|
71
|
-
end
|
72
|
-
|
73
|
-
it "HOSTGROUP: Get all" do
|
74
|
-
zbx.hostgroups.all.should include(hostgroup=>hostgroupid.to_s)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "TEMPLATE: Create" do
|
78
|
-
templateid = zbx.templates.create(
|
79
|
-
:host => template,
|
80
|
-
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
81
|
-
)
|
82
|
-
templateid.should be_kind_of(Integer)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "TEMPLATE: Get get or create" do
|
86
|
-
zbx.templates.get_or_create(
|
87
|
-
:host => template,
|
88
|
-
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
89
|
-
).should eq templateid
|
90
|
-
end
|
91
|
-
|
92
|
-
it "TEMPLATE: Check full data" do
|
93
|
-
zbx.templates.get_full_data(:host => template)[0].should include("host"=>template)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "TEMPLATE: Find" do
|
97
|
-
zbx.templates.get_id(:host => template).should eq templateid
|
98
|
-
end
|
99
|
-
|
100
|
-
it "TEMPLATE: Find unknown" do
|
101
|
-
zbx.templates.get_id(:host => "#{template}_____").should be_kind_of(NilClass)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "APPLICATION: Create" do
|
105
|
-
applicationid = zbx.applications.create(
|
106
|
-
:name => application,
|
107
|
-
:hostid => zbx.templates.get_id(:host => template)
|
108
|
-
)
|
109
|
-
applicationid.should be_kind_of(Integer)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "APPLICATION: Get or create" do
|
113
|
-
zbx.applications.get_or_create(
|
114
|
-
:name => application,
|
115
|
-
:hostid => zbx.templates.get_id(:host => template)
|
116
|
-
).should eq applicationid
|
117
|
-
end
|
118
|
-
|
119
|
-
it "APPLICATION: Full info check" do
|
120
|
-
zbx.applications.get_full_data(:name => application)[0].should include("name"=>application)
|
121
|
-
end
|
122
|
-
|
123
|
-
it "APPLICATION: Find" do
|
124
|
-
zbx.applications.get_id(:name => application).should eq applicationid
|
125
|
-
end
|
126
|
-
|
127
|
-
it "APPLICATION: Find unknown" do
|
128
|
-
zbx.applications.get_id(:name => "#{application}___").should be_kind_of(NilClass)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "ITEM: Create" do
|
132
|
-
itemid = zbx.items.create(
|
133
|
-
:description => item,
|
134
|
-
:key_ => "proc.num[aaa]",
|
135
|
-
:hostid => zbx.templates.get_id(:host => template),
|
136
|
-
:applications => [zbx.applications.get_id(:name => application)]
|
137
|
-
)
|
138
|
-
itemid.should be_kind_of(Integer)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "ITEM: Full info check" do
|
142
|
-
zbx.items.get_full_data(:description => item)[0].should include("description"=>item)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "ITEM: Find" do
|
146
|
-
zbx.items.get_id(:description => item).should eq itemid
|
147
|
-
end
|
148
|
-
|
149
|
-
it "ITEM: Update" do
|
150
|
-
zbx.items.update(
|
151
|
-
:itemid => zbx.items.get_id(:description => item),
|
152
|
-
:status => 1
|
153
|
-
).should eq itemid
|
154
|
-
end
|
155
|
-
|
156
|
-
it "ITEM: Create or update (update)" do
|
157
|
-
zbx.items.create_or_update(
|
158
|
-
:description => item,
|
159
|
-
:key_ => "proc.num[aaa]",
|
160
|
-
:status => 0,
|
161
|
-
:hostid => zbx.templates.get_id(:host => template),
|
162
|
-
:applications => [zbx.applications.get_id(:name => application)]
|
163
|
-
).should eq itemid
|
164
|
-
end
|
165
|
-
|
166
|
-
it "ITEM: Create or update (create)" do
|
167
|
-
zbx.items.create_or_update(
|
168
|
-
:description => item + "____1",
|
169
|
-
:key_ => "proc.num[aaabb]",
|
170
|
-
:status => 0,
|
171
|
-
:hostid => zbx.templates.get_id(:host => template),
|
172
|
-
:applications => [zbx.applications.get_id(:name => application)]
|
173
|
-
).should eq itemid + 1
|
174
|
-
end
|
175
|
-
|
176
|
-
it "ITEM: Get unknown" do
|
177
|
-
zbx.items.get_id(:description => "#{item}_____").should be_kind_of(NilClass)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "HOST: Create" do
|
181
|
-
hostid = zbx.hosts.create(
|
182
|
-
:host => host,
|
183
|
-
:ip => "10.20.48.88",
|
184
|
-
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
185
|
-
)
|
186
|
-
hostid.should be_kind_of(Integer)
|
187
|
-
end
|
188
|
-
|
189
|
-
it "HOST: Update or create (update)" do
|
190
|
-
zbx.hosts.create_or_update(
|
191
|
-
:host => host,
|
192
|
-
:ip => "10.20.48.89",
|
193
|
-
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
194
|
-
).should eq hostid
|
195
|
-
end
|
196
|
-
|
197
|
-
it "HOST: Find unknown" do
|
198
|
-
zbx.hosts.get_id(:host => "#{host}___").should be_kind_of(NilClass)
|
199
|
-
end
|
200
|
-
|
201
|
-
it "HOST: Find" do
|
202
|
-
zbx.hosts.get_id(:host => host).should eq hostid
|
203
|
-
end
|
204
|
-
|
205
|
-
it "HOST: Update" do
|
206
|
-
zbx.hosts.update(
|
207
|
-
:hostid => zbx.hosts.get_id(:host => host),
|
208
|
-
:status => 0
|
209
|
-
).should eq hostid
|
210
|
-
end
|
211
|
-
|
212
|
-
it "TEMPLATE: Update hosts with templates" do
|
213
|
-
zbx.templates.mass_update(
|
214
|
-
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
215
|
-
:templates_id => [zbx.templates.get_id(:host => template)]
|
216
|
-
).should be_kind_of(TrueClass)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "TEMPLATE: Get all templates linked with host" do
|
220
|
-
tmpl_array = zbx.templates.get_ids_by_host(
|
221
|
-
:hostids => [zbx.hosts.get_id(:host => host)]
|
222
|
-
)
|
223
|
-
tmpl_array.should be_kind_of(Array)
|
224
|
-
tmpl_array.should include templateid.to_s
|
225
|
-
end
|
226
|
-
|
227
|
-
it "TEMPLATE: Linked hosts with templates" do
|
228
|
-
zbx.templates.mass_add(
|
229
|
-
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
230
|
-
:templates_id => [zbx.templates.get_id(:host => template)]
|
231
|
-
).should be_kind_of(TrueClass)
|
232
|
-
end
|
233
|
-
|
234
|
-
it "TEMPLATE: Get all" do
|
235
|
-
zbx.templates.all.should include(template=>templateid.to_s)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "TRIGGER: Create" do
|
239
|
-
triggerid = zbx.triggers.create(
|
240
|
-
:description => trigger,
|
241
|
-
:expression => "{#{template}:proc.num[aaa].last(0)}<1",
|
242
|
-
:comments => "Bla-bla is faulty (disaster)",
|
243
|
-
:priority => 5,
|
244
|
-
:status => 0,
|
245
|
-
:templateid => 0,
|
246
|
-
:type => 0
|
247
|
-
)
|
248
|
-
triggerid.should be_kind_of(Integer)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "TRIGGER: Create or update (not realy update)" do
|
252
|
-
zbx.triggers.create_or_update(
|
253
|
-
:description => trigger,
|
254
|
-
:expression => "{#{template}:proc.num[aaa].last(0)}<1",
|
255
|
-
:comments => "Bla-bla is faulty (disaster)",
|
256
|
-
:priority => 5,
|
257
|
-
:status => 0,
|
258
|
-
:templateid => 0,
|
259
|
-
:type => 0
|
260
|
-
).should eq triggerid + 1
|
261
|
-
end
|
262
|
-
|
263
|
-
|
264
|
-
it "TRIGGER: Create or update (realy update)" do
|
265
|
-
zbx.triggers.create_or_update(
|
266
|
-
:description => trigger,
|
267
|
-
:expression => "{#{template}:proc.num[aaa].last(2)}<1",
|
268
|
-
:comments => "Bla-bla (2) is faulty (disaster)",
|
269
|
-
:priority => 5,
|
270
|
-
:status => 0,
|
271
|
-
:templateid => 0,
|
272
|
-
:type => 0
|
273
|
-
).should eq triggerid + 1
|
274
|
-
end
|
275
|
-
|
276
|
-
it "TRIGGER: Find" do
|
277
|
-
zbx.triggers.get_id(:description => trigger).should eq triggerid + 1 # вау блять
|
278
|
-
end
|
279
|
-
|
280
|
-
it "GRAPH: Create" do
|
281
|
-
gitems = {
|
282
|
-
:itemid => zbx.items.get_id(:description => item),
|
283
|
-
:calc_fnc => "2",
|
284
|
-
:type => "0",
|
285
|
-
:periods_cnt => "5"
|
286
|
-
}
|
287
|
-
graphid = zbx.graphs.create(
|
288
|
-
:gitems => [gitems],
|
289
|
-
:show_triggers => "0",
|
290
|
-
:name => graph,
|
291
|
-
:width => "900",
|
292
|
-
:height => "200"
|
293
|
-
)
|
294
|
-
graphid.should be_kind_of(Integer)
|
295
|
-
end
|
296
|
-
|
297
|
-
it "GRAPH: Create or get" do
|
298
|
-
gitems = {
|
299
|
-
:itemid => zbx.items.get_id(:description => item),
|
300
|
-
:calc_fnc => "2",
|
301
|
-
:type => "0",
|
302
|
-
:periods_cnt => "5"
|
303
|
-
}
|
304
|
-
zbx.graphs.get_or_create(
|
305
|
-
:gitems => [gitems],
|
306
|
-
:show_triggers => "0",
|
307
|
-
:name => graph,
|
308
|
-
:width => "900",
|
309
|
-
:height => "200"
|
310
|
-
).should eq graphid
|
311
|
-
end
|
312
|
-
|
313
|
-
it "GRAPH: Find gititems" do
|
314
|
-
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
315
|
-
end
|
316
|
-
|
317
|
-
it "GRAPH: Find" do
|
318
|
-
zbx.graphs.get_id( :name => graph ).should eq graphid
|
319
|
-
end
|
320
|
-
|
321
|
-
it "GRAPH: get_ids_by_host" do
|
322
|
-
graph_array = zbx.graphs.get_ids_by_host( :host => host )
|
323
|
-
graph_array.should be_kind_of(Array)
|
324
|
-
graph_array.should include(graphid.to_s)
|
325
|
-
end
|
326
|
-
|
327
|
-
it "GRAPH: Update" do
|
328
|
-
zbx.graphs.update(
|
329
|
-
:graphid => zbx.graphs.get_id(
|
330
|
-
:name => graph,
|
331
|
-
:hostid => zbx.hosts.get_id(:host => host)
|
332
|
-
),
|
333
|
-
:ymax_type => 1
|
334
|
-
).should eq graphid
|
335
|
-
end
|
336
|
-
|
337
|
-
it "GRAPH: Create or Update" do
|
338
|
-
gitems = {
|
339
|
-
:itemid => zbx.items.get_id(:description => item),
|
340
|
-
:calc_fnc => "3",
|
341
|
-
:type => "0",
|
342
|
-
:periods_cnt => "5"
|
343
|
-
}
|
344
|
-
zbx.graphs.create_or_update(
|
345
|
-
:gitems => [gitems],
|
346
|
-
:show_triggers => "1",
|
347
|
-
:name => graph,
|
348
|
-
:width => "900",
|
349
|
-
:height => "200"
|
350
|
-
).should eq graphid
|
351
|
-
end
|
352
|
-
|
353
|
-
it "SCREEN: Get or create for host" do
|
354
|
-
screenid = zbx.screens.get_or_create_for_host(
|
355
|
-
:host => host,
|
356
|
-
:graphids => zbx.graphs.get_ids_by_host(:host => host)
|
357
|
-
)
|
358
|
-
screenid.should be_kind_of(Integer)
|
359
|
-
end
|
360
|
-
|
361
|
-
it "TEMPLATE: Unlink hosts from templates" do
|
362
|
-
zbx.templates.mass_remove(
|
363
|
-
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
364
|
-
:templates_id => [zbx.templates.get_id(:host => template)]
|
365
|
-
).should be_kind_of(TrueClass)
|
366
|
-
end
|
367
|
-
|
368
|
-
it "SCREEN: Delete" do
|
369
|
-
zbx.screens.delete(
|
370
|
-
zbx.screens.get_id(:name => "#{host}_graphs")
|
371
|
-
).should eq screenid
|
372
|
-
end
|
373
|
-
|
374
|
-
it "GRAPH: Delete" do
|
375
|
-
zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(TrueClass)
|
376
|
-
end
|
377
|
-
|
378
|
-
it "TRIGGER: Delete" do
|
379
|
-
zbx.triggers.delete( zbx.triggers.get_id(:description => trigger) ).should eq triggerid + 1
|
380
|
-
end
|
381
|
-
|
382
|
-
it "HOST: Delete" do
|
383
|
-
zbx.hosts.delete( zbx.hosts.get_id(:host => host) ).should eq hostid
|
384
|
-
end
|
385
|
-
|
386
|
-
it "ITEM: Delete" do
|
387
|
-
zbx.items.delete(
|
388
|
-
zbx.items.get_id(:description => item)
|
389
|
-
).should eq itemid
|
390
|
-
end
|
391
|
-
|
392
|
-
it "APPLICATION: Delete" do
|
393
|
-
zbx.applications.delete( zbx.applications.get_id(:name => application) ).should eq applicationid
|
394
|
-
end
|
395
|
-
|
396
|
-
it "TEMPLATE: Delete" do
|
397
|
-
zbx.templates.delete(zbx.templates.get_id(:host => template)).should eq templateid
|
398
|
-
end
|
399
|
-
|
400
|
-
it "HOSTGROUP: Delete" do
|
401
|
-
zbx.hostgroups.delete(
|
402
|
-
zbx.hostgroups.get_id(:name => hostgroup)
|
403
|
-
).should eq hostgroupid
|
404
|
-
end
|
405
|
-
|
406
|
-
it "USER: Create" do
|
407
|
-
userid = zbx.users.create(
|
408
|
-
:alias => "Test #{user}",
|
409
|
-
:name => user,
|
410
|
-
:surname => user,
|
411
|
-
:passwd => user
|
412
|
-
)
|
413
|
-
userid.should be_kind_of(Integer)
|
414
|
-
end
|
415
|
-
|
416
|
-
it "USER: Create or update" do
|
417
|
-
zbx.users.create_or_update(
|
418
|
-
:alias => "Test #{user}",
|
419
|
-
:name => user,
|
420
|
-
:surname => user,
|
421
|
-
:passwd => user
|
422
|
-
).should eq userid
|
423
|
-
end
|
424
|
-
|
425
|
-
it "USER: Find" do
|
426
|
-
zbx.users.get_full_data(:name => user)[0]['name'].should be_kind_of(String)
|
427
|
-
end
|
428
|
-
|
429
|
-
it "USER: Update" do
|
430
|
-
zbx.users.update(:userid => zbx.users.get_id(:name => user), :name => user2).should be_kind_of(Integer)
|
431
|
-
end
|
432
|
-
|
433
|
-
it "USER: Find unknown" do
|
434
|
-
zbx.users.get_id(:name => "#{user}_____").should be_kind_of(NilClass)
|
435
|
-
end
|
436
|
-
|
437
|
-
it "USERGROUPS: Create" do
|
438
|
-
usergroupid = zbx.usergroups.create(:name => usergroup)
|
439
|
-
usergroupid.should be_kind_of(Integer)
|
440
|
-
end
|
441
|
-
|
442
|
-
it "USERGROUPS: Create or update" do
|
443
|
-
zbx.usergroups.get_or_create(:name => usergroup).should eq usergroupid
|
444
|
-
end
|
445
|
-
|
446
|
-
it "USERGROUPS: Add user" do
|
447
|
-
zbx.usergroups.add_user(
|
448
|
-
:usrgrpids => [zbx.usergroups.get_id(:name => usergroup)],
|
449
|
-
:userids => [zbx.users.get_id(:name => user2)]
|
450
|
-
).should eq usergroupid
|
451
|
-
end
|
452
|
-
|
453
|
-
it "USERGROUPS: Set UserGroup read & write perm" do
|
454
|
-
zbx.usergroups.set_perms(
|
455
|
-
:usrgrpid => zbx.usergroups.get_or_create(:name => usergroup).to_s,
|
456
|
-
:hostgroupids => zbx.hostgroups.all.values,
|
457
|
-
:permission => 3
|
458
|
-
).should eq usergroupid
|
459
|
-
end
|
460
|
-
|
461
|
-
it "MEDIATYPE: Create" do
|
462
|
-
mediatypeid = zbx.mediatypes.create(
|
463
|
-
:description => mediatype,
|
464
|
-
:type => 0,
|
465
|
-
:smtp_server => "127.0.0.1",
|
466
|
-
:smtp_email => "zabbix@test.com"
|
467
|
-
)
|
468
|
-
mediatypeid.should be_kind_of(Integer)
|
469
|
-
end
|
470
|
-
|
471
|
-
it "MEDIATYPE: Update or create" do
|
472
|
-
zbx.mediatypes.create_or_update(
|
473
|
-
:description => mediatype,
|
474
|
-
:smtp_email => "zabbix2@test.com"
|
475
|
-
).should eq mediatypeid
|
476
|
-
end
|
477
|
-
|
478
|
-
it "USER: Add mediatype" do
|
479
|
-
zbx.users.add_medias(
|
480
|
-
:userids => [zbx.users.get_id(:name => user2)],
|
481
|
-
:media => [
|
482
|
-
{
|
483
|
-
:mediatypeid => zbx.mediatypes.get_id(:description => mediatype),
|
484
|
-
:sendto => "test@test",
|
485
|
-
:active => 0,
|
486
|
-
:period => "1-7,00:00-24:00",
|
487
|
-
:severity => "56"
|
488
|
-
}
|
489
|
-
]
|
490
|
-
).should eq userid
|
491
|
-
end
|
492
|
-
|
493
|
-
it "MEDIATYPE: Delete" do
|
494
|
-
zbx.mediatypes.delete(
|
495
|
-
zbx.mediatypes.get_id(:description => mediatype)
|
496
|
-
).should eq mediatypeid
|
497
|
-
end
|
498
|
-
|
499
|
-
it "USER: Delete" do
|
500
|
-
zbx.users.delete(zbx.users.get_id(:name => user2)).should eq userid
|
501
|
-
end
|
502
|
-
|
503
|
-
it "USERGROUPS: Delete" do
|
504
|
-
zbx.usergroups.delete([zbx.usergroups.get_id(:name => usergroup)]).should eq usergroupid
|
505
|
-
end
|
506
|
-
|
507
|
-
it "QUERY" do
|
508
|
-
zbx.query(
|
509
|
-
:method => "apiinfo.version",
|
510
|
-
:params => {}
|
511
|
-
).should be_kind_of(String)
|
512
|
-
end
|
513
|
-
|
514
|
-
end
|