zabbixapi 0.5.0b2 → 0.5.0b3
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.md +3 -2
- data/lib/zabbixapi.rb +50 -29
- data/lib/zabbixapi/applications.rb +10 -31
- data/lib/zabbixapi/basic.rb +109 -0
- data/lib/zabbixapi/client.rb +3 -3
- data/lib/zabbixapi/graphs.rb +9 -14
- data/lib/zabbixapi/hostgroups.rb +12 -46
- data/lib/zabbixapi/hosts.rb +13 -31
- data/lib/zabbixapi/items.rb +14 -33
- data/lib/zabbixapi/mediatypes.rb +15 -88
- data/lib/zabbixapi/screens.rb +9 -60
- data/lib/zabbixapi/server.rb +3 -3
- data/lib/zabbixapi/templates.rb +10 -63
- data/lib/zabbixapi/triggers.rb +10 -34
- data/lib/zabbixapi/usergroups.rb +8 -90
- data/lib/zabbixapi/users.rb +7 -43
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/localhost.rb +102 -75
- data/spec/run.rb +102 -75
- metadata +4 -3
data/spec/run.rb
CHANGED
@@ -33,11 +33,12 @@ describe ZabbixApi, "test_api" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "HOSTGROUP: Create" do
|
36
|
-
zbx.hostgroups.create(:name => hostgroup)
|
36
|
+
$hostgroup_id_real = zbx.hostgroups.create(:name => hostgroup)
|
37
|
+
$hostgroup_id_real.should be_kind_of(Integer)
|
37
38
|
end
|
38
39
|
|
39
40
|
it "HOSTGROUP: Find" do
|
40
|
-
zbx.hostgroups.get_id(:name => hostgroup).should
|
41
|
+
zbx.hostgroups.get_id(:name => hostgroup).should equal $hostgroup_id_real
|
41
42
|
end
|
42
43
|
|
43
44
|
it "HOSTGROUP: Find unknown" do
|
@@ -45,59 +46,61 @@ describe ZabbixApi, "test_api" do
|
|
45
46
|
end
|
46
47
|
|
47
48
|
it "HOSTGROUP: Create or get" do
|
48
|
-
zbx.hostgroups.get_or_create(:name => hostgroup).should
|
49
|
+
zbx.hostgroups.get_or_create(:name => hostgroup).should equal $hostgroup_id_real
|
49
50
|
end
|
50
51
|
|
51
52
|
it "HOSTGROUP: Get all" do
|
52
|
-
zbx.hostgroups.all.should
|
53
|
+
zbx.hostgroups.all.should include(hostgroup => $hostgroup_id_real.to_s)
|
53
54
|
end
|
54
55
|
|
55
56
|
it "TEMPLATE: Create" do
|
56
|
-
zbx.templates.create(
|
57
|
+
$template_id_real = zbx.templates.create(
|
57
58
|
:host => template,
|
58
59
|
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
59
|
-
)
|
60
|
+
)
|
61
|
+
$template_id_real.should be_kind_of(Integer)
|
60
62
|
end
|
61
63
|
|
62
64
|
it "TEMPLATE: Get get or create" do
|
63
65
|
zbx.templates.get_or_create(
|
64
66
|
:host => template,
|
65
67
|
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
66
|
-
).should
|
67
|
-
end
|
68
|
-
|
69
|
-
it "TEMPLATE: Check full data" do
|
70
|
-
zbx.templates.get_full_data(:host => template)[0]['host'].should be_kind_of(String)
|
68
|
+
).should equal $template_id_real
|
71
69
|
end
|
72
70
|
|
73
71
|
it "TEMPLATE: Find" do
|
74
|
-
zbx.templates.get_id(:host => template).should
|
72
|
+
zbx.templates.get_id(:host => template).should equal $template_id_real
|
75
73
|
end
|
76
74
|
|
77
75
|
it "TEMPLATE: Find unknown" do
|
78
76
|
zbx.templates.get_id(:host => "#{template}_____").should be_kind_of(NilClass)
|
79
77
|
end
|
80
78
|
|
79
|
+
it "TEMPLATE: Get all" do
|
80
|
+
zbx.templates.all.should include(template => $template_id_real.to_s)
|
81
|
+
end
|
82
|
+
|
81
83
|
it "APPLICATION: Create" do
|
82
|
-
zbx.applications.create(
|
84
|
+
$application_id_real = zbx.applications.create(
|
83
85
|
:name => application,
|
84
86
|
:hostid => zbx.templates.get_id(:host => template)
|
85
87
|
)
|
88
|
+
$application_id_real.should be_kind_of(Integer)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "APPLICATION: Get all" do
|
92
|
+
zbx.applications.all.should include(application => $application_id_real.to_s)
|
86
93
|
end
|
87
94
|
|
88
95
|
it "APPLICATION: Get or create" do
|
89
96
|
zbx.applications.get_or_create(
|
90
97
|
:name => application,
|
91
98
|
:hostid => zbx.templates.get_id(:host => template)
|
92
|
-
)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "APPLICATION: Full info check" do
|
96
|
-
zbx.applications.get_full_data(:name => application)[0]['applicationid'].should be_kind_of(String)
|
99
|
+
).should equal $application_id_real
|
97
100
|
end
|
98
101
|
|
99
102
|
it "APPLICATION: Find" do
|
100
|
-
zbx.applications.get_id(:name => application).should
|
103
|
+
zbx.applications.get_id(:name => application).should equal $application_id_real
|
101
104
|
end
|
102
105
|
|
103
106
|
it "APPLICATION: Find unknown" do
|
@@ -105,27 +108,28 @@ describe ZabbixApi, "test_api" do
|
|
105
108
|
end
|
106
109
|
|
107
110
|
it "ITEM: Create" do
|
108
|
-
zbx.items.create(
|
111
|
+
$item_id_real = zbx.items.create(
|
109
112
|
:description => item,
|
110
113
|
:key_ => "proc.num[aaa]",
|
111
114
|
:hostid => zbx.templates.get_id(:host => template),
|
112
115
|
:applications => [zbx.applications.get_id(:name => application)]
|
113
|
-
)
|
116
|
+
)
|
117
|
+
$item_id_real.should be_kind_of(Integer)
|
114
118
|
end
|
115
119
|
|
116
|
-
it "ITEM:
|
117
|
-
zbx.items.
|
120
|
+
it "ITEM: Find" do
|
121
|
+
zbx.items.get_id(:description => item).should equal $item_id_real
|
118
122
|
end
|
119
123
|
|
120
|
-
it "ITEM:
|
121
|
-
zbx.items.
|
124
|
+
it "ITEM: Get all" do
|
125
|
+
zbx.items.all.should include(item => $item_id_real.to_s)
|
122
126
|
end
|
123
127
|
|
124
128
|
it "ITEM: Update" do
|
125
129
|
zbx.items.update(
|
126
130
|
:itemid => zbx.items.get_id(:description => item),
|
127
131
|
:status => 0
|
128
|
-
).should
|
132
|
+
).should equal $item_id_real
|
129
133
|
end
|
130
134
|
|
131
135
|
it "ITEM: Create or update" do
|
@@ -135,19 +139,20 @@ describe ZabbixApi, "test_api" do
|
|
135
139
|
:type => 6,
|
136
140
|
:hostid => zbx.templates.get_id(:host => template),
|
137
141
|
:applications => [zbx.applications.get_id(:name => application)]
|
138
|
-
).should
|
142
|
+
).should equal $item_id_real
|
139
143
|
end
|
140
144
|
|
141
145
|
it "ITEM: Get unknown" do
|
142
|
-
zbx.items.get_id(:description => "#{item}_____")
|
146
|
+
zbx.items.get_id(:description => "#{item}_____").should be_kind_of(NilClass)
|
143
147
|
end
|
144
148
|
|
145
149
|
it "HOST: Create" do
|
146
|
-
zbx.hosts.create(
|
150
|
+
$host_id_real = zbx.hosts.create(
|
147
151
|
:host => host,
|
148
152
|
:ip => "10.20.48.88",
|
149
153
|
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
150
|
-
)
|
154
|
+
)
|
155
|
+
$host_id_real.should be_kind_of(Integer)
|
151
156
|
end
|
152
157
|
|
153
158
|
it "HOST: Update or create" do
|
@@ -155,7 +160,7 @@ describe ZabbixApi, "test_api" do
|
|
155
160
|
:host => host,
|
156
161
|
:ip => "10.20.48.89",
|
157
162
|
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
158
|
-
).should
|
163
|
+
).should equal $host_id_real
|
159
164
|
end
|
160
165
|
|
161
166
|
it "HOST: Find unknown" do
|
@@ -163,20 +168,18 @@ describe ZabbixApi, "test_api" do
|
|
163
168
|
end
|
164
169
|
|
165
170
|
it "HOST: Find" do
|
166
|
-
zbx.hosts.get_id(:host => host).should
|
171
|
+
zbx.hosts.get_id(:host => host).should equal $host_id_real
|
167
172
|
end
|
168
173
|
|
169
174
|
it "HOST: Update" do
|
170
175
|
zbx.hosts.update(
|
171
176
|
:hostid => zbx.hosts.get_id(:host => host),
|
172
177
|
:status => 0
|
173
|
-
)
|
178
|
+
).should equal $host_id_real
|
174
179
|
end
|
175
180
|
|
176
|
-
it "
|
177
|
-
zbx.
|
178
|
-
:hostids => [zbx.hosts.get_id(:host => host)]
|
179
|
-
).should be_kind_of(Array)
|
181
|
+
it "HOST: Get all" do
|
182
|
+
zbx.hosts.all.should include(host => $host_id_real.to_s)
|
180
183
|
end
|
181
184
|
|
182
185
|
it "TEMPLATE: Linked hosts with templates" do
|
@@ -193,12 +196,18 @@ describe ZabbixApi, "test_api" do
|
|
193
196
|
).should be_kind_of(TrueClass)
|
194
197
|
end
|
195
198
|
|
199
|
+
it "TEMPLATE: Get all templates linked with host" do
|
200
|
+
zbx.templates.get_ids_by_host(
|
201
|
+
:hostids => [zbx.hosts.get_id(:host => host)]
|
202
|
+
).should include($template_id_real.to_s)
|
203
|
+
end
|
204
|
+
|
196
205
|
it "TEMPLATE: Get all" do
|
197
|
-
zbx.templates.all.should
|
206
|
+
zbx.templates.all.should include(template => $template_id_real.to_s)
|
198
207
|
end
|
199
208
|
|
200
209
|
it "TRIGGER: Create" do
|
201
|
-
zbx.triggers.create(
|
210
|
+
$trigger_id_real = zbx.triggers.create(
|
202
211
|
:description => trigger,
|
203
212
|
:expression => "{#{template}:proc.num[aaa].last(0)}<1",
|
204
213
|
:comments => "Bla-bla is faulty (disaster)",
|
@@ -206,13 +215,22 @@ describe ZabbixApi, "test_api" do
|
|
206
215
|
:status => 0,
|
207
216
|
:templateid => 0,
|
208
217
|
:type => 0
|
209
|
-
)
|
218
|
+
)
|
219
|
+
$trigger_id_real.should be_kind_of(Integer)
|
210
220
|
end
|
211
221
|
|
212
222
|
it "TRIGGER: Find" do
|
213
223
|
zbx.triggers.get_id(:description => trigger).should be_kind_of(Integer)
|
214
224
|
end
|
215
225
|
|
226
|
+
it "TRIGGER: Find unknown" do
|
227
|
+
zbx.triggers.get_id(:description => "#{trigger}____").should be_kind_of(NilClass)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "TRIGGER: Get all" do
|
231
|
+
zbx.triggers.all.should be_kind_of(Hash)
|
232
|
+
end
|
233
|
+
|
216
234
|
it "GRAPH: Create" do
|
217
235
|
gitems = {
|
218
236
|
:itemid => zbx.items.get_id(:description => item),
|
@@ -220,13 +238,14 @@ describe ZabbixApi, "test_api" do
|
|
220
238
|
:type => "0",
|
221
239
|
:periods_cnt => "5"
|
222
240
|
}
|
223
|
-
zbx.graphs.create(
|
241
|
+
$graph_id_real = zbx.graphs.create(
|
224
242
|
:gitems => [gitems],
|
225
243
|
:show_triggers => "0",
|
226
244
|
:name => graph,
|
227
245
|
:width => "900",
|
228
246
|
:height => "200"
|
229
|
-
)
|
247
|
+
)
|
248
|
+
$graph_id_real.should be_kind_of(Integer)
|
230
249
|
end
|
231
250
|
|
232
251
|
it "GRAPH: Create or get" do
|
@@ -242,21 +261,25 @@ describe ZabbixApi, "test_api" do
|
|
242
261
|
:name => graph,
|
243
262
|
:width => "900",
|
244
263
|
:height => "200"
|
245
|
-
).should
|
264
|
+
).should equal $graph_id_real
|
246
265
|
end
|
247
266
|
|
248
267
|
it "GRAPH: Find gititems" do
|
249
|
-
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
268
|
+
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) ).should be_kind_of(Array)
|
250
269
|
end
|
251
270
|
|
252
271
|
it "GRAPH: Find" do
|
253
|
-
zbx.graphs.get_id( :name => graph ).should
|
272
|
+
zbx.graphs.get_id( :name => graph ).should equal $graph_id_real
|
254
273
|
end
|
255
274
|
|
256
275
|
it "GRAPH: get_ids_by_host" do
|
257
276
|
zbx.graphs.get_ids_by_host( :host => host ).should be_kind_of(Array)
|
258
277
|
end
|
259
278
|
|
279
|
+
it "GRAPH: Get all" do
|
280
|
+
zbx.graphs.all.should include(graph => $graph_id_real.to_s)
|
281
|
+
end
|
282
|
+
|
260
283
|
it "GRAPH: Update" do
|
261
284
|
zbx.graphs.update(
|
262
285
|
:graphid => zbx.graphs.get_id(
|
@@ -264,7 +287,7 @@ describe ZabbixApi, "test_api" do
|
|
264
287
|
:hostid => zbx.hosts.get_id(:host => host)
|
265
288
|
),
|
266
289
|
:ymax_type => 1
|
267
|
-
).should
|
290
|
+
).should equal $graph_id_real
|
268
291
|
end
|
269
292
|
|
270
293
|
it "GRAPH: Create or Update" do
|
@@ -280,14 +303,15 @@ describe ZabbixApi, "test_api" do
|
|
280
303
|
:name => graph,
|
281
304
|
:width => "900",
|
282
305
|
:height => "200"
|
283
|
-
).should
|
306
|
+
).should equal $graph_id_real
|
284
307
|
end
|
285
308
|
|
286
309
|
it "SCREEN: Get or create for host" do
|
287
|
-
zbx.screens.get_or_create_for_host(
|
310
|
+
$screen_id_real = zbx.screens.get_or_create_for_host(
|
288
311
|
:host => host,
|
289
312
|
:graphids => zbx.graphs.get_ids_by_host(:host => host)
|
290
|
-
)
|
313
|
+
)
|
314
|
+
$screen_id_real.should be_kind_of(Integer)
|
291
315
|
end
|
292
316
|
|
293
317
|
it "TEMPLATE: Unlink hosts from templates" do
|
@@ -297,10 +321,14 @@ describe ZabbixApi, "test_api" do
|
|
297
321
|
).should be_kind_of(TrueClass)
|
298
322
|
end
|
299
323
|
|
324
|
+
it "SCREEN: Get all" do
|
325
|
+
zbx.screens.all.should be_kind_of(Hash)
|
326
|
+
end
|
327
|
+
|
300
328
|
it "SCREEN: Delete" do
|
301
329
|
zbx.screens.delete(
|
302
330
|
[zbx.screens.get_id(:name => "#{host}_graphs")]
|
303
|
-
).should
|
331
|
+
).should equal $screen_id_real
|
304
332
|
end
|
305
333
|
|
306
334
|
it "GRAPH: Delete" do
|
@@ -312,36 +340,37 @@ describe ZabbixApi, "test_api" do
|
|
312
340
|
end
|
313
341
|
|
314
342
|
it "HOST: Delete" do
|
315
|
-
zbx.hosts.delete( zbx.hosts.get_id(:host => host) ).should
|
343
|
+
zbx.hosts.delete( zbx.hosts.get_id(:host => host) ).should equal $host_id_real
|
316
344
|
end
|
317
345
|
|
318
346
|
it "ITEM: Delete" do
|
319
347
|
zbx.items.delete(
|
320
348
|
zbx.items.get_id(:description => item)
|
321
|
-
).should
|
349
|
+
).should equal $item_id_real
|
322
350
|
end
|
323
351
|
|
324
352
|
it "APPLICATION: Delete" do
|
325
|
-
zbx.applications.delete( zbx.applications.get_id(:name => application) )
|
353
|
+
zbx.applications.delete( zbx.applications.get_id(:name => application) ).should equal $application_id_real
|
326
354
|
end
|
327
355
|
|
328
356
|
it "TEMPLATE: Delete" do
|
329
|
-
zbx.templates.delete(zbx.templates.get_id(:host => template))
|
357
|
+
zbx.templates.delete(zbx.templates.get_id(:host => template)).should equal $template_id_real
|
330
358
|
end
|
331
359
|
|
332
360
|
it "HOSTGROUP: Delete" do
|
333
361
|
zbx.hostgroups.delete(
|
334
362
|
zbx.hostgroups.get_id(:name => hostgroup)
|
335
|
-
).should
|
363
|
+
).should equal $hostgroup_id_real
|
336
364
|
end
|
337
365
|
|
338
366
|
it "USER: Create" do
|
339
|
-
zbx.users.create(
|
367
|
+
$user_id_real = zbx.users.create(
|
340
368
|
:alias => "Test #{user}",
|
341
369
|
:name => user,
|
342
370
|
:surname => user,
|
343
371
|
:passwd => user
|
344
|
-
)
|
372
|
+
)
|
373
|
+
$user_id_real.should be_kind_of(Integer)
|
345
374
|
end
|
346
375
|
|
347
376
|
it "USER: Create or update" do
|
@@ -350,34 +379,31 @@ describe ZabbixApi, "test_api" do
|
|
350
379
|
:name => user,
|
351
380
|
:surname => user,
|
352
381
|
:passwd => user
|
353
|
-
).should
|
354
|
-
end
|
355
|
-
|
356
|
-
it "USER: Find" do
|
357
|
-
zbx.users.get_full_data(:name => user)[0]['name'].should be_kind_of(String)
|
382
|
+
).should equal $user_id_real
|
358
383
|
end
|
359
384
|
|
360
385
|
it "USER: Update" do
|
361
|
-
zbx.users.update(:userid => zbx.users.get_id(:name => user), :name => user2).should
|
386
|
+
zbx.users.update(:userid => zbx.users.get_id(:name => user), :name => user2).should equal $user_id_real
|
362
387
|
end
|
363
388
|
|
364
389
|
it "USER: Find unknown" do
|
365
|
-
zbx.users.get_id(:name => "#{user}_____")
|
390
|
+
zbx.users.get_id(:name => "#{user}_____").should be_kind_of(NilClass)
|
366
391
|
end
|
367
392
|
|
368
393
|
it "USERGROUPS: Create" do
|
369
|
-
zbx.usergroups.create(:name => usergroup)
|
394
|
+
$usergrp_id_real = zbx.usergroups.create(:name => usergroup)
|
395
|
+
$usergrp_id_real.should be_kind_of(Integer)
|
370
396
|
end
|
371
397
|
|
372
398
|
it "USERGROUPS: Create or update" do
|
373
|
-
zbx.usergroups.get_or_create(:name => usergroup).should
|
399
|
+
zbx.usergroups.get_or_create(:name => usergroup).should equal $usergrp_id_real
|
374
400
|
end
|
375
401
|
|
376
402
|
it "USERGROUPS: Add user" do
|
377
403
|
zbx.usergroups.add_user(
|
378
404
|
:usrgrpids => [zbx.usergroups.get_id(:name => usergroup)],
|
379
405
|
:userids => [zbx.users.get_id(:name => user2)]
|
380
|
-
).should
|
406
|
+
).should equal $usergrp_id_real
|
381
407
|
end
|
382
408
|
|
383
409
|
it "USERGROUPS: Set UserGroup read & write perm" do
|
@@ -385,23 +411,24 @@ describe ZabbixApi, "test_api" do
|
|
385
411
|
:usrgrpid => zbx.usergroups.get_or_create(:name => usergroup).to_s,
|
386
412
|
:hostgroupids => zbx.hostgroups.all.values,
|
387
413
|
:permission => 3
|
388
|
-
).should
|
414
|
+
).should equal $usergrp_id_real
|
389
415
|
end
|
390
416
|
|
391
417
|
it "MEDIATYPE: Create" do
|
392
|
-
zbx.mediatypes.create(
|
418
|
+
$meditype_id_real = zbx.mediatypes.create(
|
393
419
|
:description => mediatype,
|
394
420
|
:type => 0,
|
395
421
|
:smtp_server => "127.0.0.1",
|
396
422
|
:smtp_email => "zabbix@test.com"
|
397
|
-
)
|
423
|
+
)
|
424
|
+
$meditype_id_real.should be_kind_of(Integer)
|
398
425
|
end
|
399
426
|
|
400
427
|
it "MEDIATYPE: Update or create" do
|
401
428
|
zbx.mediatypes.create_or_update(
|
402
429
|
:description => mediatype,
|
403
430
|
:smtp_email => "zabbix2@test.com"
|
404
|
-
).should
|
431
|
+
).should equal $meditype_id_real
|
405
432
|
end
|
406
433
|
|
407
434
|
it "USER: Add mediatype" do
|
@@ -416,21 +443,21 @@ describe ZabbixApi, "test_api" do
|
|
416
443
|
:severity => "56"
|
417
444
|
}
|
418
445
|
]
|
419
|
-
).should
|
446
|
+
).should equal $user_id_real
|
420
447
|
end
|
421
448
|
|
422
449
|
it "MEDIATYPE: Delete" do
|
423
450
|
zbx.mediatypes.delete(
|
424
451
|
zbx.mediatypes.get_id(:description => mediatype)
|
425
|
-
).should
|
452
|
+
).should equal $meditype_id_real
|
426
453
|
end
|
427
454
|
|
428
455
|
it "USER: Delete" do
|
429
|
-
zbx.users.delete(zbx.users.get_id(:name => user2)).should
|
456
|
+
zbx.users.delete(zbx.users.get_id(:name => user2)).should equal $user_id_real
|
430
457
|
end
|
431
458
|
|
432
459
|
it "USERGROUPS: Delete" do
|
433
|
-
zbx.usergroups.delete([zbx.usergroups.get_id(:name => usergroup)]).should
|
460
|
+
zbx.usergroups.delete([zbx.usergroups.get_id(:name => usergroup)]).should equal $usergrp_id_real
|
434
461
|
end
|
435
462
|
|
436
463
|
it "QUERY" do
|