zapix 0.1.0 → 0.1.1
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/lib/zapix/proxies/actions.rb +21 -0
- data/lib/zapix/proxies/usergroups.rb +29 -0
- data/lib/zapix/proxies/users.rb +32 -0
- data/lib/zapix/version.rb +1 -1
- data/lib/zapix.rb +12 -0
- data/spec/zapix_specs.rb +159 -4
- metadata +7 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative 'basic'
|
|
2
|
+
|
|
3
|
+
class Actions < Basic
|
|
4
|
+
def exists?(options)
|
|
5
|
+
@client.action_exists(options)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def create(options)
|
|
9
|
+
@client.action_create(options) unless exists?(options)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get_id(options)
|
|
13
|
+
result = @client.action_get({
|
|
14
|
+
'filter' => {'name' => options['name']}})
|
|
15
|
+
result.first['actionid']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def delete(*action_ids)
|
|
19
|
+
@client.action_delete(action_ids)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'basic'
|
|
2
|
+
|
|
3
|
+
class Usergroups < Basic
|
|
4
|
+
|
|
5
|
+
def create(options)
|
|
6
|
+
@client.usergroup_create(options) unless exists?(options)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def exists?(options)
|
|
10
|
+
@client.usergroup_exists(options)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_id(options)
|
|
14
|
+
if(exists?(options))
|
|
15
|
+
result = @client.usergroup_get({
|
|
16
|
+
'filter' => {'name' => options['name']}})
|
|
17
|
+
result.first['usrgrpid']
|
|
18
|
+
else
|
|
19
|
+
raise NonExistingUsergroup, "Usergroup #{options['name']} does not exist !"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def delete(*group_ids)
|
|
24
|
+
@client.usergroup_delete(group_ids)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class NonExistingUsergroup < StandardError; end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative 'basic'
|
|
2
|
+
|
|
3
|
+
class Users < Basic
|
|
4
|
+
def create(options)
|
|
5
|
+
@client.user_create(options) unless exists?(options)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def exists?(options)
|
|
9
|
+
result = @client.user_get({'filter' => {'alias' => options['alias']}})
|
|
10
|
+
if result.empty?
|
|
11
|
+
false
|
|
12
|
+
else
|
|
13
|
+
true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_id(options)
|
|
18
|
+
if(exists?(options))
|
|
19
|
+
@client.user_get({'filter' => {'alias' => options['alias']}}).first['userid']
|
|
20
|
+
else
|
|
21
|
+
raise NonExistingUser, "User #{options['alias']} does not exist !"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def delete(usergroup_ids)
|
|
26
|
+
@client.user_delete(usergroup_ids)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class NonExistingUser < StandardError; end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
data/lib/zapix/version.rb
CHANGED
data/lib/zapix.rb
CHANGED
|
@@ -42,4 +42,16 @@ class ZabbixAPI
|
|
|
42
42
|
@hostinterfaces ||= Hostinterfaces.new(@client)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def actions
|
|
46
|
+
@actions ||= Actions.new(@client)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def usergroups
|
|
50
|
+
@usergroups ||= Usergroups.new(@client)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def users
|
|
54
|
+
@users ||= Users.new(@client)
|
|
55
|
+
end
|
|
56
|
+
|
|
45
57
|
end
|
data/spec/zapix_specs.rb
CHANGED
|
@@ -18,6 +18,15 @@ scenario = 'scenario'
|
|
|
18
18
|
trigger_description = 'Webpage failed on {HOST.NAME}'
|
|
19
19
|
trigger_expression = "{#{host}:web.test.fail[#{scenario}].max(#3)}#0"
|
|
20
20
|
non_existing_trigger_expression = '{vfs.file.cksum[/etc/passwd].diff(0)}>0'
|
|
21
|
+
existing_action_name = 'Report problems to Zabbix administrators'
|
|
22
|
+
non_existing_action_name = 'No action defined'
|
|
23
|
+
test_usergroup = 'Operation managers test'
|
|
24
|
+
existing_usergroup = 'Admins'
|
|
25
|
+
non_existing_usergroup = 'Smurfs'
|
|
26
|
+
existing_user = 'Admin'
|
|
27
|
+
non_existing_user = 'Tweegle'
|
|
28
|
+
test_user = 'Jim'
|
|
29
|
+
test_action = 'Test Action'
|
|
21
30
|
|
|
22
31
|
describe ZabbixAPI do
|
|
23
32
|
|
|
@@ -69,7 +78,7 @@ describe ZabbixAPI do
|
|
|
69
78
|
(zrc.hostgroups.get_all).should include(hostgroup, another_hostgroup)
|
|
70
79
|
end
|
|
71
80
|
end
|
|
72
|
-
|
|
81
|
+
existing_action_name
|
|
73
82
|
context 'complex hostgroup consisting hosts' do
|
|
74
83
|
before(:each) do
|
|
75
84
|
zrc.hostgroups.create(hostgroup_with_hosts)
|
|
@@ -121,7 +130,7 @@ describe ZabbixAPI do
|
|
|
121
130
|
options = {}
|
|
122
131
|
options['description'] = trigger_description
|
|
123
132
|
options['expression'] = trigger_expression
|
|
124
|
-
options['priority'] =
|
|
133
|
+
options['priority'] = 2 # 2 means Warning
|
|
125
134
|
zrc.triggers.create(options)
|
|
126
135
|
|
|
127
136
|
end
|
|
@@ -252,7 +261,7 @@ describe ZabbixAPI do
|
|
|
252
261
|
end
|
|
253
262
|
|
|
254
263
|
it 'deletes a web scenario' do
|
|
255
|
-
pending 'Not
|
|
264
|
+
pending 'Not implemended'
|
|
256
265
|
options = {}
|
|
257
266
|
options['name'] = scenario
|
|
258
267
|
options['hostid'] = zrc.hosts.get_id(host)
|
|
@@ -325,6 +334,152 @@ describe ZabbixAPI do
|
|
|
325
334
|
pending 'Not implemented'
|
|
326
335
|
end
|
|
327
336
|
end
|
|
337
|
+
|
|
338
|
+
describe 'actions' do
|
|
339
|
+
before(:each) do
|
|
340
|
+
options = {}
|
|
341
|
+
usergroup_options = {}
|
|
342
|
+
usergroup_options['name'] = existing_usergroup
|
|
343
|
+
options['name'] = test_action
|
|
344
|
+
options['eventsource'] = 0
|
|
345
|
+
options['evaltype'] = 1 # AND
|
|
346
|
+
options['status'] = 1 # Disabled
|
|
347
|
+
options['esc_period'] = 3600
|
|
348
|
+
options['def_shortdata'] = '{TRIGGER.NAME}: {TRIGGER.STATUS}'
|
|
349
|
+
options['def_longdata'] = "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}"
|
|
350
|
+
options['conditions'] = [{
|
|
351
|
+
'conditiontype' => 0, # Hostgroup
|
|
352
|
+
'operator' => 0, # =
|
|
353
|
+
'value' => zrc.hostgroups.get_id('Templates')
|
|
354
|
+
},
|
|
355
|
+
# not in maintenance
|
|
356
|
+
{
|
|
357
|
+
'conditiontype' => 16, # Maintenance
|
|
358
|
+
'operator' => 7, # not in
|
|
359
|
+
'value' => 'maintenance'
|
|
360
|
+
}]
|
|
361
|
+
options['operations'] = [{
|
|
362
|
+
'operationtype' => 0,
|
|
363
|
+
'esc_period' => 0,
|
|
364
|
+
'esc_step_from' => 1,
|
|
365
|
+
'esc_step_to' => 1,
|
|
366
|
+
'evaltype' => 0,
|
|
367
|
+
'opmessage_grp' => [{
|
|
368
|
+
'usrgrpid' => zrc.usergroups.get_id(usergroup_options)
|
|
369
|
+
}],
|
|
370
|
+
'opmessage' => {
|
|
371
|
+
'default_msg' => 1,
|
|
372
|
+
'mediatypeid' => 1
|
|
373
|
+
}
|
|
374
|
+
}]
|
|
375
|
+
zrc.actions.create(options)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
after(:each) do
|
|
379
|
+
options = {}
|
|
380
|
+
options['name'] = test_action
|
|
381
|
+
action_id = zrc.actions.get_id(options)
|
|
382
|
+
zrc.actions.delete(action_id)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it 'checks if an action exists' do
|
|
386
|
+
options = {}
|
|
387
|
+
options['name'] = existing_action_name
|
|
388
|
+
zrc.actions.exists?(options).should be_true
|
|
389
|
+
options['name'] = non_existing_action_name
|
|
390
|
+
zrc.actions.exists?(options).should be_false
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it 'gets an id of an action' do
|
|
394
|
+
options = {}
|
|
395
|
+
options['name'] = test_action
|
|
396
|
+
result = zrc.actions.get_id(options)
|
|
397
|
+
(result.to_i).should >= 0
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
describe 'usergroups' do
|
|
402
|
+
before(:each) do
|
|
403
|
+
options = {}
|
|
404
|
+
options['name'] = test_usergroup
|
|
405
|
+
options['rights'] = {
|
|
406
|
+
'permission' => 3,
|
|
407
|
+
'id' => zrc.hostgroups.get_id(hostgroup_with_hosts)
|
|
408
|
+
}
|
|
409
|
+
zrc.usergroups.create(options)
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
after(:each) do
|
|
413
|
+
options = {}
|
|
414
|
+
options['name'] = test_usergroup
|
|
415
|
+
usergroup_id = zrc.usergroups.get_id(options)
|
|
416
|
+
zrc.usergroups.delete(usergroup_id)
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
it 'checks if a usergroup exists' do
|
|
420
|
+
options = {}
|
|
421
|
+
options['name'] = existing_usergroup
|
|
422
|
+
zrc.usergroups.exists?(options).should be_true
|
|
423
|
+
options['name'] = non_existing_usergroup
|
|
424
|
+
zrc.usergroups.exists?(options).should be_false
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
it 'gets the id of a usergroup by name' do
|
|
428
|
+
options = {}
|
|
429
|
+
options['name'] = test_usergroup
|
|
430
|
+
result = zrc.usergroups.get_id(options)
|
|
431
|
+
(result.to_i).should >= 0
|
|
432
|
+
options['name'] = non_existing_usergroup
|
|
433
|
+
expect { zrc.usergroups.get_id(options) }.to raise_error(Usergroups::NonExistingUsergroup)
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
describe 'user' do
|
|
438
|
+
before(:each) do
|
|
439
|
+
user_options = {}
|
|
440
|
+
group_options = {}
|
|
441
|
+
group_options['name'] = existing_usergroup
|
|
442
|
+
group_id = zrc.usergroups.get_id(group_options)
|
|
443
|
+
user_options['alias'] = test_user
|
|
444
|
+
user_options['passwd'] = random_string
|
|
445
|
+
user_options['usrgrps'] = [{
|
|
446
|
+
'usrgrpid' => group_id
|
|
447
|
+
}]
|
|
448
|
+
|
|
449
|
+
user_options['user_medias'] = [{
|
|
450
|
+
'mediatypeid' => 1,
|
|
451
|
+
'sendto' => 'support@company.com',
|
|
452
|
+
'active' => 0,
|
|
453
|
+
'severity' => 63,
|
|
454
|
+
'period' => '1-7,00:00-24:00'
|
|
455
|
+
}]
|
|
456
|
+
zrc.users.create(user_options)
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
after(:each) do
|
|
460
|
+
user_options = {}
|
|
461
|
+
user_options['alias'] = test_user
|
|
462
|
+
user_options['userid'] = zrc.users.get_id(user_options)
|
|
463
|
+
zrc.users.delete(user_options)
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
it 'checks if a user exists' do
|
|
467
|
+
options = {}
|
|
468
|
+
options['alias'] = test_user
|
|
469
|
+
zrc.users.exists?(options).should be_true
|
|
470
|
+
options['alias'] = non_existing_user
|
|
471
|
+
zrc.users.exists?(options).should be_false
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
it 'gets the id of a user' do
|
|
475
|
+
options = {}
|
|
476
|
+
options['alias'] = test_user
|
|
477
|
+
result = zrc.users.get_id(options)
|
|
478
|
+
(result.to_i).should >= 0
|
|
479
|
+
options['alias'] = non_existing_user
|
|
480
|
+
expect { zrc.users.get_id(options) }.to raise_error(Users::NonExistingUser)
|
|
481
|
+
end
|
|
482
|
+
end
|
|
328
483
|
end
|
|
329
484
|
|
|
330
485
|
def create_interface
|
|
@@ -338,7 +493,7 @@ describe ZabbixAPI do
|
|
|
338
493
|
'ip' => random_local_ip,
|
|
339
494
|
'dns' => random_domain,
|
|
340
495
|
'type' => 4, # JMX
|
|
341
|
-
'main' => 1, #
|
|
496
|
+
'main' => 1, # default jmx interface
|
|
342
497
|
'port' => 9003)
|
|
343
498
|
end
|
|
344
499
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zapix
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-07-
|
|
12
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -105,6 +105,7 @@ files:
|
|
|
105
105
|
- README.md
|
|
106
106
|
- Rakefile
|
|
107
107
|
- lib/zapix.rb
|
|
108
|
+
- lib/zapix/proxies/actions.rb
|
|
108
109
|
- lib/zapix/proxies/applications.rb
|
|
109
110
|
- lib/zapix/proxies/basic.rb
|
|
110
111
|
- lib/zapix/proxies/hostgroups.rb
|
|
@@ -113,6 +114,8 @@ files:
|
|
|
113
114
|
- lib/zapix/proxies/scenarios.rb
|
|
114
115
|
- lib/zapix/proxies/templates.rb
|
|
115
116
|
- lib/zapix/proxies/triggers.rb
|
|
117
|
+
- lib/zapix/proxies/usergroups.rb
|
|
118
|
+
- lib/zapix/proxies/users.rb
|
|
116
119
|
- lib/zapix/version.rb
|
|
117
120
|
- lib/zapix/zabbix_classes/host.rb
|
|
118
121
|
- lib/zapix/zabbix_classes/interface.rb
|
|
@@ -135,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
135
138
|
version: '0'
|
|
136
139
|
segments:
|
|
137
140
|
- 0
|
|
138
|
-
hash:
|
|
141
|
+
hash: 531610970119711934
|
|
139
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
143
|
none: false
|
|
141
144
|
requirements:
|
|
@@ -144,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
147
|
version: '0'
|
|
145
148
|
segments:
|
|
146
149
|
- 0
|
|
147
|
-
hash:
|
|
150
|
+
hash: 531610970119711934
|
|
148
151
|
requirements: []
|
|
149
152
|
rubyforge_project:
|
|
150
153
|
rubygems_version: 1.8.24
|