zapix3 0.1.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 +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +55 -0
- data/LICENSE +22 -0
- data/README.md +383 -0
- data/Rakefile +1 -0
- data/lib/zapix/proxies/actions.rb +26 -0
- data/lib/zapix/proxies/applications.rb +30 -0
- data/lib/zapix/proxies/base.rb +7 -0
- data/lib/zapix/proxies/hostgroups.rb +98 -0
- data/lib/zapix/proxies/hostinterfaces.rb +21 -0
- data/lib/zapix/proxies/hosts.rb +77 -0
- data/lib/zapix/proxies/scenarios.rb +34 -0
- data/lib/zapix/proxies/templates.rb +30 -0
- data/lib/zapix/proxies/triggers.rb +40 -0
- data/lib/zapix/proxies/usergroups.rb +35 -0
- data/lib/zapix/proxies/users.rb +28 -0
- data/lib/zapix/version.rb +3 -0
- data/lib/zapix/zabbix_classes/host.rb +47 -0
- data/lib/zapix/zabbix_classes/interface.rb +42 -0
- data/lib/zapix/zabbix_rpc_client.rb +58 -0
- data/lib/zapix.rb +57 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/zapix_specs.rb +520 -0
- data/zapix.gemspec +27 -0
- metadata +141 -0
data/spec/zapix_specs.rb
ADDED
@@ -0,0 +1,520 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
zrc = ZabbixAPI.connect(
|
4
|
+
:service_url => ENV['ZABBIX_API_URL'],
|
5
|
+
:username => ENV['ZABBIX_API_LOGIN'],
|
6
|
+
:password => ENV['ZABBIX_API_PASSWORD'],
|
7
|
+
:debug => true
|
8
|
+
)
|
9
|
+
|
10
|
+
hostgroup = 'hostgroup123'
|
11
|
+
another_hostgroup = 'anotherhostgroup'
|
12
|
+
hostgroup_with_hosts = 'withhosts'
|
13
|
+
template_1 = 'Template OS Linux'
|
14
|
+
template_2 = 'Template App POP Service'
|
15
|
+
templates_hostgroup = 'Templates'
|
16
|
+
application = 'web scenarios'
|
17
|
+
host = 'hostname'
|
18
|
+
scenario = 'scenario'
|
19
|
+
trigger_description = 'Webpage failed on {HOST.NAME}'
|
20
|
+
#trigger_expression = "{#{host}:web.test.fail[#{scenario}].max(#3)}#0"
|
21
|
+
trigger_expression = "{#{host}:system.cpu.load[percpu,avg1].last()}>5"
|
22
|
+
non_existing_trigger_expression = '{vfs.file.cksum[/etc/passwd].diff(0)}>0'
|
23
|
+
existing_action_name = 'Report problems to Zabbix administrators'
|
24
|
+
non_existing_action_name = 'No action defined'
|
25
|
+
test_usergroup = 'Operation managers test'
|
26
|
+
existing_usergroup = 'Zabbix administrators'
|
27
|
+
non_existing_usergroup = 'Smurfs'
|
28
|
+
existing_user = 'Admin'
|
29
|
+
non_existing_user = 'Tweegle'
|
30
|
+
test_user = 'Jim'
|
31
|
+
test_action = 'Test Action'
|
32
|
+
|
33
|
+
describe ZabbixAPI do
|
34
|
+
|
35
|
+
context 'hostgroup' do
|
36
|
+
before(:all) do
|
37
|
+
zrc.hostgroups.create(hostgroup)
|
38
|
+
zrc.hostgroups.create(another_hostgroup)
|
39
|
+
end
|
40
|
+
|
41
|
+
after(:all) do
|
42
|
+
zrc.hostgroups.delete(hostgroup)
|
43
|
+
zrc.hostgroups.delete(another_hostgroup)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'creates or updates a hostgroup' do
|
47
|
+
zrc.hostgroups.create_or_update(hostgroup)
|
48
|
+
result = zrc.hostgroups.create_or_update(hostgroup)
|
49
|
+
result.should include('groupids')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns false if hostgroup does not exist' do
|
53
|
+
result = zrc.hostgroups.exists?('nonexisting')
|
54
|
+
result.should be false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'succeeds if a hostgroup exist' do
|
58
|
+
result = zrc.hostgroups.exists?(hostgroup)
|
59
|
+
result.should be true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns hostgroup id' do
|
63
|
+
result = zrc.hostgroups.get_id(hostgroup)
|
64
|
+
(result.to_i).should >= 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'throws exception if hostgroup id does not exist' do
|
68
|
+
expect { zrc.hostgroups.get_id('nonexisting') }.to raise_error(HostGroups::NonExistingHostgroup)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'throws exception if someone checks for attached hosts of nonexisting group' do
|
72
|
+
expect { zrc.hostgroups.any_hosts?('nonexisting') }.to raise_error(HostGroups::NonExistingHostgroup)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns false if a hostgroup has no attached hosts' do
|
76
|
+
zrc.hostgroups.any_hosts?(hostgroup).should be false
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns all hostgroups' do
|
80
|
+
(zrc.hostgroups.get_all).should include(hostgroup, another_hostgroup)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
context 'complex hostgroup consisting hosts' do
|
85
|
+
before(:each) do
|
86
|
+
zrc.hostgroups.create(hostgroup_with_hosts)
|
87
|
+
hostgroup_id = zrc.hostgroups.get_id(hostgroup_with_hosts)
|
88
|
+
example_host = Host.new
|
89
|
+
example_host.add_name(host)
|
90
|
+
example_host.add_interfaces(create_interface.to_hash)
|
91
|
+
example_host.add_group_ids(hostgroup_id)
|
92
|
+
example_host.add_template_ids(zrc.templates.get_id(template_1), zrc.templates.get_id(template_2))
|
93
|
+
example_host.add_macros({'macro' => '{$TESTMACRO}', 'value' => 'test123'})
|
94
|
+
zrc.hosts.create_or_update(example_host.to_hash)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'deletes a hostgroup with attached hosts' do
|
98
|
+
zrc.hosts.exists?(host).should be true
|
99
|
+
zrc.hostgroups.delete(hostgroup_with_hosts)
|
100
|
+
zrc.hostgroups.exists?(hostgroup_with_hosts).should be false
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'complex hostgroup' do
|
106
|
+
before(:each) do
|
107
|
+
zrc.hostgroups.create(hostgroup_with_hosts)
|
108
|
+
hostgroup_id = zrc.hostgroups.get_id(hostgroup_with_hosts)
|
109
|
+
example_host = Host.new
|
110
|
+
example_host.add_name(host)
|
111
|
+
example_host.add_interfaces(create_interface.to_hash)
|
112
|
+
example_host.add_macros({'macro' => '{$TESTMACRO}', 'value' => 'test123'})
|
113
|
+
example_host.add_group_ids(hostgroup_id)
|
114
|
+
example_host.add_template_ids(zrc.templates.get_id(template_1), zrc.templates.get_id(template_2))
|
115
|
+
zrc.hosts.create_or_update(example_host.to_hash)
|
116
|
+
|
117
|
+
# create application for the host
|
118
|
+
application_options = {}
|
119
|
+
application_options['name'] = application
|
120
|
+
application_options['hostid'] = zrc.hosts.get_id(host)
|
121
|
+
zrc.applications.create(application_options)
|
122
|
+
|
123
|
+
# creates web scenarios for host
|
124
|
+
webcheck_options = {}
|
125
|
+
webcheck_options['hostid'] = zrc.hosts.get_id(host)
|
126
|
+
webcheck_options['name'] = scenario
|
127
|
+
webcheck_options['applicationid'] = zrc.applications.get_id(application_options)
|
128
|
+
webcheck_options['steps'] = [{'name' => 'Homepage', 'url' => 'm.test.de', 'status_codes' => 200, 'no' => 1}]
|
129
|
+
zrc.scenarios.create(webcheck_options)
|
130
|
+
|
131
|
+
# creates a trigger
|
132
|
+
options = {}
|
133
|
+
options['description'] = trigger_description
|
134
|
+
options['expression'] = trigger_expression
|
135
|
+
options['priority'] = 2 # 2 means Warning
|
136
|
+
zrc.triggers.create(options)
|
137
|
+
end
|
138
|
+
|
139
|
+
after(:each) do
|
140
|
+
zrc.hostgroups.delete(hostgroup_with_hosts)
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'hosts' do
|
144
|
+
|
145
|
+
it 'returns true if a hostgroup has attached hosts' do
|
146
|
+
zrc.hostgroups.any_hosts?(hostgroup_with_hosts).should be true
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns all the host ids of a hosts belonging to a hostgroup' do
|
150
|
+
host_id = zrc.hosts.get_id(host)
|
151
|
+
zrc.hostgroups.get_host_ids_of(hostgroup_with_hosts).should include(host_id)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'gets the right template id for host' do
|
155
|
+
result = zrc.templates.get_templates_for_host(zrc.hosts.get_id(host))
|
156
|
+
result.should include(zrc.templates.get_id(template_1))
|
157
|
+
result.should include(zrc.templates.get_id(template_2))
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'unlinks all templates for host' do
|
161
|
+
host_id = zrc.hosts.get_id(host)
|
162
|
+
options = {}
|
163
|
+
options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
|
164
|
+
options['host_id'] = host_id
|
165
|
+
result = zrc.hosts.unlink_and_clear_templates(options)
|
166
|
+
result.should_not include(zrc.templates.get_id(template_1))
|
167
|
+
result.should_not include(zrc.templates.get_id(template_2))
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'throws an exception if updating a host without specifying the hostname' do
|
171
|
+
example_host = Host.new
|
172
|
+
example_host.add_interfaces(create_interface.to_hash)
|
173
|
+
expect { zrc.hosts.create_or_update(example_host.to_hash) }.to raise_error(Hosts::EmptyHostname)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "updates host's interface after unlinking all belonging templates" do
|
177
|
+
# unlinking all items
|
178
|
+
host_id = zrc.hosts.get_id(host)
|
179
|
+
options = {}
|
180
|
+
zrc.templates.get_templates_for_host(host_id)
|
181
|
+
options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
|
182
|
+
options['host_id'] = host_id
|
183
|
+
result = zrc.hosts.unlink_and_clear_templates(options)
|
184
|
+
# now it should be safe to update the interface of the host
|
185
|
+
example_host = Host.new
|
186
|
+
example_host.add_interfaces(create_interface.to_hash)
|
187
|
+
example_host.add_name(host)
|
188
|
+
zrc.hosts.create_or_update(example_host.to_hash)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "updates host's templates" do
|
192
|
+
host_id = zrc.hosts.get_id(host)
|
193
|
+
options = {}
|
194
|
+
options['host_id'] = host_id
|
195
|
+
template_id = zrc.templates.get_id('Template App FTP Service')
|
196
|
+
options['template_ids'] = [template_id]
|
197
|
+
zrc.hosts.update_templates(options)
|
198
|
+
zrc.templates.get_templates_for_host(host_id).should include(template_id)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "updates host's macro" do
|
202
|
+
host_id = zrc.hosts.get_id(host)
|
203
|
+
options = {}
|
204
|
+
options['host_id'] = host_id
|
205
|
+
options['macros'] = [{'macro' => '{$TESTMACRO}', 'value' => 'this is only a test macro'}]
|
206
|
+
zrc.hosts.update_macros(options)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'creates a template' do
|
210
|
+
template_name = 'Template Tomcat'
|
211
|
+
options = {'host' => template_name}
|
212
|
+
options['groups'] = zrc.hostgroups.get_id(templates_hostgroup)
|
213
|
+
zrc.templates.create(options)
|
214
|
+
zrc.templates.exists?(template_name).should be true
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe 'applications' do
|
219
|
+
it 'returns false if an application does not exist' do
|
220
|
+
options = {}
|
221
|
+
options['name'] = 'nonexisting'
|
222
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
223
|
+
zrc.applications.exists?(options).should be false
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'returns true if an application exists' do
|
227
|
+
options = {}
|
228
|
+
options['name'] = application
|
229
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
230
|
+
zrc.applications.exists?(options).should be true
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'get an application id by application name and host' do
|
234
|
+
options = {}
|
235
|
+
options['name'] = application
|
236
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
237
|
+
result = zrc.applications.get_id(options)
|
238
|
+
(result.to_i).should >= 0
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'throws exception on non existing application' do
|
242
|
+
options = {}
|
243
|
+
options['name'] = "nonexisting"
|
244
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
245
|
+
expect { zrc.applications.get_id(options) }.to raise_error(Applications::NonExistingApplication)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe 'web scenarios' do
|
250
|
+
it 'returns true if web scenarios exists' do
|
251
|
+
options = {}
|
252
|
+
options['name'] = scenario
|
253
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
254
|
+
zrc.scenarios.exists?(options).should be true
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns all web scenarios' do
|
258
|
+
options = {}
|
259
|
+
(zrc.scenarios.get_all).should include(scenario)
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'gets the id of a web scenario' do
|
263
|
+
options = {}
|
264
|
+
options['name'] = scenario
|
265
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
266
|
+
zrc.scenarios.exists?(options).should be true
|
267
|
+
result = zrc.scenarios.get_id(options)
|
268
|
+
(result['result'].to_i).should >= 0
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'returns false if a web scenario does not exist' do
|
272
|
+
options = {}
|
273
|
+
options['name'] = "nonexisting"
|
274
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
275
|
+
zrc.scenarios.exists?(options).should be false
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'deletes a web scenario' do
|
279
|
+
options = {}
|
280
|
+
options['name'] = scenario
|
281
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
282
|
+
scenario_id = zrc.scenarios.get_id(options)
|
283
|
+
zrc.scenarios.delete([scenario_id])
|
284
|
+
zrc.scenarios.exists?(options).should be false
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe 'triggers' do
|
289
|
+
it 'deletes a trigger' do
|
290
|
+
options = {}
|
291
|
+
options['expression'] = trigger_expression
|
292
|
+
zrc.triggers.get_id(options).to_i.should >= 0
|
293
|
+
id = zrc.triggers.get_id(options)
|
294
|
+
zrc.triggers.delete(id)
|
295
|
+
expect { zrc.triggers.get_id(options) }.to raise_error(Triggers::NonExistingTrigger)
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'gets an id of a trigger' do
|
299
|
+
options = {}
|
300
|
+
options['expression'] = trigger_expression
|
301
|
+
zrc.triggers.get_id(options).to_i >= 0
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'throws exception if trying to get id of a non-existing trigger' do
|
305
|
+
options = {}
|
306
|
+
options['expression'] = non_existing_trigger_expression
|
307
|
+
expect { zrc.triggers.get_id(options) }.to raise_error(Triggers::NonExistingTrigger)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe 'hostinterfaces' do
|
312
|
+
it 'creates jmx interface for host' do
|
313
|
+
jmx_iface = create_jmx_interface
|
314
|
+
jmx_iface_hash = jmx_iface.to_hash
|
315
|
+
jmx_iface_hash['hostid'] = zrc.hosts.get_id(host)
|
316
|
+
zrc.hostinterfaces.create(jmx_iface_hash)
|
317
|
+
zrc.hostinterfaces.exists?(jmx_iface_hash).should be true
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'check if interface exists for host' do
|
321
|
+
options = {}
|
322
|
+
options['hostid'] = zrc.hosts.get_id(host)
|
323
|
+
options['port'] = 10050
|
324
|
+
options['type'] = 1
|
325
|
+
zrc.hostinterfaces.exists?(options).should be true
|
326
|
+
|
327
|
+
options['port'] = 9003
|
328
|
+
options['type'] = 4
|
329
|
+
zrc.hostinterfaces.exists?(options).should be false
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'gets interface id' do
|
333
|
+
pending 'Not implemented'
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'deletes an interface' do
|
337
|
+
pending 'Not implemented'
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
describe 'actions' do
|
342
|
+
before(:each) do
|
343
|
+
options = {}
|
344
|
+
usergroup_options = {}
|
345
|
+
usergroup_options['name'] = existing_usergroup
|
346
|
+
options['name'] = test_action
|
347
|
+
options['eventsource'] = 0
|
348
|
+
options['evaltype'] = 1 # AND
|
349
|
+
options['status'] = 1 # Disabled
|
350
|
+
options['esc_period'] = 3600
|
351
|
+
options['def_shortdata'] = '{TRIGGER.NAME}: {TRIGGER.STATUS}'
|
352
|
+
options['def_longdata'] = "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}"
|
353
|
+
options['conditions'] = [{
|
354
|
+
'conditiontype' => 0, # Hostgroup
|
355
|
+
'operator' => 0, # =
|
356
|
+
'value' => zrc.hostgroups.get_id('Templates')
|
357
|
+
},
|
358
|
+
# not in maintenance
|
359
|
+
{
|
360
|
+
'conditiontype' => 16, # Maintenance
|
361
|
+
'operator' => 7, # not in
|
362
|
+
'value' => 'maintenance'
|
363
|
+
}]
|
364
|
+
options['operations'] = [{
|
365
|
+
'operationtype' => 0,
|
366
|
+
'esc_period' => 0,
|
367
|
+
'esc_step_from' => 1,
|
368
|
+
'esc_step_to' => 1,
|
369
|
+
'evaltype' => 0,
|
370
|
+
'opmessage_grp' => [{
|
371
|
+
'usrgrpid' => zrc.usergroups.get_id(usergroup_options)
|
372
|
+
}],
|
373
|
+
'opmessage' => {
|
374
|
+
'default_msg' => 1,
|
375
|
+
'mediatypeid' => 1
|
376
|
+
}
|
377
|
+
}]
|
378
|
+
zrc.actions.create(options)
|
379
|
+
end
|
380
|
+
|
381
|
+
after(:each) do
|
382
|
+
options = {}
|
383
|
+
options['name'] = test_action
|
384
|
+
action_id = zrc.actions.get_id(options)
|
385
|
+
zrc.actions.delete(action_id)
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'checks if an action exists' do
|
389
|
+
options = {}
|
390
|
+
options['name'] = existing_action_name
|
391
|
+
zrc.actions.exists?(options).should be true
|
392
|
+
options['name'] = non_existing_action_name
|
393
|
+
zrc.actions.exists?(options).should be false
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'gets an id of an action' do
|
397
|
+
options = {}
|
398
|
+
options['name'] = test_action
|
399
|
+
result = zrc.actions.get_id(options)
|
400
|
+
(result.to_i).should >= 0
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe 'usergroups' do
|
405
|
+
before(:each) do
|
406
|
+
options = {}
|
407
|
+
options['name'] = test_usergroup
|
408
|
+
options['rights'] = {
|
409
|
+
'permission' => 3,
|
410
|
+
'id' => zrc.hostgroups.get_id(hostgroup_with_hosts)
|
411
|
+
}
|
412
|
+
zrc.usergroups.create(options)
|
413
|
+
end
|
414
|
+
|
415
|
+
after(:each) do
|
416
|
+
options = {}
|
417
|
+
options['name'] = test_usergroup
|
418
|
+
usergroup_id = zrc.usergroups.get_id(options)
|
419
|
+
zrc.usergroups.delete(usergroup_id)
|
420
|
+
end
|
421
|
+
|
422
|
+
it 'checks if a usergroup exists' do
|
423
|
+
options = {}
|
424
|
+
options['name'] = existing_usergroup
|
425
|
+
zrc.usergroups.exists?(options).should be true
|
426
|
+
options['name'] = non_existing_usergroup
|
427
|
+
zrc.usergroups.exists?(options).should be false
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'gets the id of a usergroup by name' do
|
431
|
+
options = {}
|
432
|
+
options['name'] = test_usergroup
|
433
|
+
result = zrc.usergroups.get_id(options)
|
434
|
+
(result.to_i).should >= 0
|
435
|
+
options['name'] = non_existing_usergroup
|
436
|
+
expect { zrc.usergroups.get_id(options) }.to raise_error(Usergroups::NonExistingUsergroup)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe 'user' do
|
441
|
+
before(:each) do
|
442
|
+
user_options = {}
|
443
|
+
group_options = {}
|
444
|
+
group_options['name'] = existing_usergroup
|
445
|
+
group_id = zrc.usergroups.get_id(group_options)
|
446
|
+
user_options['alias'] = test_user
|
447
|
+
user_options['passwd'] = random_string
|
448
|
+
user_options['usrgrps'] = [{
|
449
|
+
'usrgrpid' => group_id
|
450
|
+
}]
|
451
|
+
|
452
|
+
user_options['user_medias'] = [{
|
453
|
+
'mediatypeid' => 1,
|
454
|
+
'sendto' => 'support@company.com',
|
455
|
+
'active' => 0,
|
456
|
+
'severity' => 63,
|
457
|
+
'period' => '1-7,00:00-24:00'
|
458
|
+
}]
|
459
|
+
zrc.users.create(user_options)
|
460
|
+
end
|
461
|
+
|
462
|
+
after(:each) do
|
463
|
+
user_options = {}
|
464
|
+
user_options['alias'] = test_user
|
465
|
+
user_options['userid'] = zrc.users.get_id(user_options)
|
466
|
+
zrc.users.delete([user_options['userid']])
|
467
|
+
end
|
468
|
+
|
469
|
+
it 'checks if a user exists' do
|
470
|
+
options = {}
|
471
|
+
options['alias'] = test_user
|
472
|
+
zrc.users.exists?(options).should be true
|
473
|
+
options['alias'] = non_existing_user
|
474
|
+
zrc.users.exists?(options).should be false
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'gets the id of a user' do
|
478
|
+
options = {}
|
479
|
+
options['alias'] = test_user
|
480
|
+
result = zrc.users.get_id(options)
|
481
|
+
(result.to_i).should >= 0
|
482
|
+
options['alias'] = non_existing_user
|
483
|
+
expect { zrc.users.get_id(options) }.to raise_error(Users::NonExistingUser)
|
484
|
+
end
|
485
|
+
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def create_interface
|
490
|
+
Interface.new(
|
491
|
+
'ip' => random_local_ip,
|
492
|
+
'dns' => random_domain)
|
493
|
+
end
|
494
|
+
|
495
|
+
def create_jmx_interface
|
496
|
+
Interface.new(
|
497
|
+
'ip' => random_local_ip,
|
498
|
+
'dns' => random_domain,
|
499
|
+
'type' => 4, # JMX
|
500
|
+
'main' => 1, # default jmx interface
|
501
|
+
'port' => 9003)
|
502
|
+
end
|
503
|
+
|
504
|
+
def random_string
|
505
|
+
rand(36**7...36**8).to_s(36)
|
506
|
+
end
|
507
|
+
|
508
|
+
def random_int
|
509
|
+
rand(64)
|
510
|
+
end
|
511
|
+
|
512
|
+
def random_local_ip
|
513
|
+
"127.0.0.#{random_int}"
|
514
|
+
end
|
515
|
+
|
516
|
+
def random_domain
|
517
|
+
"#{random_string}.our-cloud.de"
|
518
|
+
end
|
519
|
+
|
520
|
+
end
|
data/zapix.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zapix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zapix3"
|
8
|
+
spec.version = Zapix::VERSION
|
9
|
+
spec.authors = ["stoyan"]
|
10
|
+
spec.email = ["stoyanoff.s@gmail.com"]
|
11
|
+
spec.description = %q{Communication with the Zabbix API made easy. This version is compatible with zabbix 3.0}
|
12
|
+
spec.summary = %q{A cool gem}
|
13
|
+
spec.homepage = "https://github.com/mrsn/zapix3"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "json"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "activerecord"
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zapix3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- stoyan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Communication with the Zabbix API made easy. This version is compatible
|
84
|
+
with zabbix 3.0
|
85
|
+
email:
|
86
|
+
- stoyanoff.s@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/zapix.rb
|
97
|
+
- lib/zapix/proxies/actions.rb
|
98
|
+
- lib/zapix/proxies/applications.rb
|
99
|
+
- lib/zapix/proxies/base.rb
|
100
|
+
- lib/zapix/proxies/hostgroups.rb
|
101
|
+
- lib/zapix/proxies/hostinterfaces.rb
|
102
|
+
- lib/zapix/proxies/hosts.rb
|
103
|
+
- lib/zapix/proxies/scenarios.rb
|
104
|
+
- lib/zapix/proxies/templates.rb
|
105
|
+
- lib/zapix/proxies/triggers.rb
|
106
|
+
- lib/zapix/proxies/usergroups.rb
|
107
|
+
- lib/zapix/proxies/users.rb
|
108
|
+
- lib/zapix/version.rb
|
109
|
+
- lib/zapix/zabbix_classes/host.rb
|
110
|
+
- lib/zapix/zabbix_classes/interface.rb
|
111
|
+
- lib/zapix/zabbix_rpc_client.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/zapix_specs.rb
|
114
|
+
- zapix.gemspec
|
115
|
+
homepage: https://github.com/mrsn/zapix3
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A cool gem
|
139
|
+
test_files:
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/zapix_specs.rb
|