ams-zapix3 0.2.6
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 +34 -0
- data/LICENSE +22 -0
- data/README.md +350 -0
- data/Rakefile +1 -0
- data/lib/zapix.rb +72 -0
- data/lib/zapix/proxies/actions.rb +26 -0
- data/lib/zapix/proxies/applications.rb +27 -0
- data/lib/zapix/proxies/base.rb +7 -0
- data/lib/zapix/proxies/graphs.rb +18 -0
- data/lib/zapix/proxies/hostgroups.rb +97 -0
- data/lib/zapix/proxies/hostinterfaces.rb +20 -0
- data/lib/zapix/proxies/hosts.rb +80 -0
- data/lib/zapix/proxies/proxies.rb +9 -0
- data/lib/zapix/proxies/scenarios.rb +32 -0
- data/lib/zapix/proxies/screenitems.rb +11 -0
- data/lib/zapix/proxies/screens.rb +26 -0
- data/lib/zapix/proxies/templates.rb +29 -0
- data/lib/zapix/proxies/triggers.rb +50 -0
- data/lib/zapix/proxies/usergroups.rb +32 -0
- data/lib/zapix/proxies/users.rb +26 -0
- data/lib/zapix/version.rb +3 -0
- data/lib/zapix/zabbix_classes/host.rb +51 -0
- data/lib/zapix/zabbix_classes/interface.rb +28 -0
- data/lib/zapix/zabbix_rpc_client.rb +64 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/zapix_specs.rb +516 -0
- data/zapix.gemspec +25 -0
- metadata +131 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Actions < Base
|
4
|
+
def exists?(options)
|
5
|
+
result = client.action_get('filter' => { 'name' => options['name'] })
|
6
|
+
if result.nil? || result.empty?
|
7
|
+
return false
|
8
|
+
else
|
9
|
+
return true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(options)
|
14
|
+
client.action_create(options) unless exists?(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_id(options)
|
18
|
+
result = client.action_get('filter' => { 'name' => options['name'] })
|
19
|
+
|
20
|
+
result.first['actionid']
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(*action_ids)
|
24
|
+
client.action_delete(action_ids)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Applications < Base
|
4
|
+
def create(options)
|
5
|
+
client.application_create(options) unless exists?(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def exists?(options)
|
9
|
+
result = client.application_get('filter' => { 'name' => options['name'] })
|
10
|
+
if result.nil? || result.empty?
|
11
|
+
false
|
12
|
+
else
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_id(options)
|
18
|
+
if exists?(options)
|
19
|
+
client.application_get('filter' => { 'name' => options['name'],
|
20
|
+
'hostid' => options['hostid'] }).first['applicationid']
|
21
|
+
else
|
22
|
+
raise NonExistingApplication, "Application #{options['name']} does not exist !"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class NonExistingApplication < StandardError; end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Graphs < Base
|
4
|
+
def get_all_graph_ids_for(options)
|
5
|
+
graphs_with_names_and_ids = []
|
6
|
+
graphs = client.graph_get(options)
|
7
|
+
|
8
|
+
graphs.each do |g|
|
9
|
+
graphs_with_names_and_ids <<
|
10
|
+
{
|
11
|
+
'name' => g['name'],
|
12
|
+
'id' => g['graphid']
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
graphs_with_names_and_ids
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class HostGroups < Base
|
4
|
+
def mass_create(*names)
|
5
|
+
names.each do |group_name|
|
6
|
+
create(group_name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(name)
|
11
|
+
client.hostgroup_create('name' => name) unless exists?(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_or_update(name)
|
15
|
+
if exists?(name)
|
16
|
+
id = get_id(name)
|
17
|
+
client.hostgroup_update('groupid' => id, 'name' => name)
|
18
|
+
else
|
19
|
+
create(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def exists?(name)
|
24
|
+
result = client.hostgroup_get('filter' => { 'name' => [name] })
|
25
|
+
if result.nil? || result.empty?
|
26
|
+
return false
|
27
|
+
else
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_id(name)
|
33
|
+
if exists?(name)
|
34
|
+
result = client.hostgroup_get('filter' => { 'name' => [name] })
|
35
|
+
result[0]['groupid']
|
36
|
+
else
|
37
|
+
raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def mass_delete(*names)
|
42
|
+
names.each do |group_name|
|
43
|
+
delete(group_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_host_ids_of(hostgroup)
|
48
|
+
result = client.hostgroup_get('filter' => { 'name' => [hostgroup] }, 'selectHosts' => 'refer')
|
49
|
+
extract_host_ids(result)
|
50
|
+
end
|
51
|
+
|
52
|
+
def any_hosts?(hostgroup)
|
53
|
+
raise NonExistingHostgroup, "Hostgroup #{hostgroup} does not exist !" unless exists?(hostgroup)
|
54
|
+
result = client.hostgroup_get('filter' => { 'name' => [hostgroup] }, 'selectHosts' => 'count').first['hosts'].to_i
|
55
|
+
# result = client.hostgroup_get('countOutput' => 'true', 'filter' => {'name' => [hostgroup]}, 'selectHosts' => 'count').to_i
|
56
|
+
result >= 1 ? true : false
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(name)
|
60
|
+
if exists?(name)
|
61
|
+
# host cannot exist without a hostgroup, so we need to delete
|
62
|
+
# the attached hosts also
|
63
|
+
if any_hosts?(name)
|
64
|
+
# delete all hosts attached to a hostgroup
|
65
|
+
host_ids = get_host_ids_of(name)
|
66
|
+
host_ids.each do |id|
|
67
|
+
client.host_delete([id])
|
68
|
+
end
|
69
|
+
# now it is ok to delete the group
|
70
|
+
client.hostgroup_delete([get_id(name)])
|
71
|
+
else
|
72
|
+
client.hostgroup_delete([get_id(name)])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_all
|
80
|
+
# the fucking API also returns the ids and that's
|
81
|
+
# why we need to extract the names
|
82
|
+
host_groups_with_ids = client.hostgroup_get('output' => ['name'])
|
83
|
+
extract_host_groups(host_groups_with_ids)
|
84
|
+
end
|
85
|
+
|
86
|
+
def extract_host_ids(query_result)
|
87
|
+
query_result.first['hosts'].map { |host| host['hostid'] }
|
88
|
+
end
|
89
|
+
|
90
|
+
def extract_host_groups(group_names_and_ids)
|
91
|
+
group_names_and_ids.map do |hostgroup|
|
92
|
+
hostgroup['name']
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class NonExistingHostgroup < StandardError; end
|
97
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Hostinterfaces < Base
|
4
|
+
def create(options)
|
5
|
+
client.hostinterface_create(options) unless exists?(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def exists?(options)
|
9
|
+
get(options).empty? ? false : true
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(options)
|
13
|
+
client.hostinterface_get(
|
14
|
+
'filter' => { 'hostid' => options['hostid'],
|
15
|
+
'port' => options['port'],
|
16
|
+
'type' => options['type'] },
|
17
|
+
'output' => 'extend'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
class Hosts < Base
|
3
|
+
def get_id(name)
|
4
|
+
if exists?(name)
|
5
|
+
client.host_get('filter' => { 'host' => name }).first['hostid']
|
6
|
+
else
|
7
|
+
raise NonExistingHost, "Host #{name} does not exist !"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_hosts_for_hostgroup(group_id)
|
12
|
+
client.host_get('groupids' => [group_id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(options = {})
|
16
|
+
client.host_create(options) unless exists?(options['host'])
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_or_update(options = {})
|
20
|
+
raise EmptyHostname, 'Host name cannot be empty !' if options['host'].nil?
|
21
|
+
if exists?(options['host'])
|
22
|
+
id = get_id(options['host'])
|
23
|
+
options['hostid'] = id
|
24
|
+
client.host_update(options)
|
25
|
+
else
|
26
|
+
create(options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def unlink_and_clear_templates(options = {})
|
31
|
+
template_ids = options['template_ids'].map { |id| { 'templateid' => id } }
|
32
|
+
client.host_update('hostid' => options['host_id'], 'templates_clear' => template_ids)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_templates(options = {})
|
36
|
+
template_ids = options['template_ids'].map { |id| { 'templateid' => id } }
|
37
|
+
client.host_update('hostid' => options['host_id'], 'templates' => template_ids)
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_macros(options = {})
|
41
|
+
client.host_update('hostid' => options['host_id'], 'macros' => options['macros'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def exists?(name)
|
45
|
+
result = client.host_get('filter' => { 'host' => name })
|
46
|
+
if result.nil? || result.empty?
|
47
|
+
false
|
48
|
+
else
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_all
|
54
|
+
host_names_and_ids = client.host_get('output' => ['name'])
|
55
|
+
|
56
|
+
# the fucking api ALWAYS returns the ids and that's
|
57
|
+
# why we need to extract the names separately
|
58
|
+
|
59
|
+
extract_host_names(host_names_and_ids)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(name)
|
63
|
+
if exists?(name)
|
64
|
+
client.host_delete([get_id(name)])
|
65
|
+
else
|
66
|
+
raise NonExistingHost, "Host #{name} cannot be deleted because it does not exist !"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class NonExistingHost < StandardError; end
|
71
|
+
class EmptyHostname < StandardError; end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def extract_host_names(hosts_and_ids)
|
76
|
+
hosts_and_ids.map do |current_host|
|
77
|
+
current_host['name']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Scenarios < Base
|
4
|
+
def create(options)
|
5
|
+
client.httptest_create(options) unless exists?(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_id(options)
|
9
|
+
client.httptest_get('filter' => { 'name' => options['name'], 'hostid' => options['hostid'] }).first['httptestid']
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(options)
|
13
|
+
client.httptest_delete(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def exists?(options)
|
17
|
+
result = client.httptest_get('countOutput' => true,
|
18
|
+
'filter' => { 'name' => options['name'],
|
19
|
+
'hostid' => options['hostid'] })
|
20
|
+
|
21
|
+
result.to_i >= 1 ? true : false
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_all
|
25
|
+
scenarios = client.httptest_get('output' => 'extend')
|
26
|
+
names = extract_names(scenarios)
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_names(scenarios)
|
30
|
+
scenarios.map { |scenario| scenario['name'] }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class Screens < Base
|
4
|
+
def get_id(options)
|
5
|
+
result = client.screen_get('filter' => { 'name' => options['name'] })
|
6
|
+
|
7
|
+
result.first['screenid']
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(options)
|
11
|
+
client.screen_create(options) unless exists?(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete(*screen_ids)
|
15
|
+
client.screen_delete(screen_ids)
|
16
|
+
end
|
17
|
+
|
18
|
+
def exists?(options)
|
19
|
+
result = client.screen_get('filter' => { 'name' => options['name'] })
|
20
|
+
if result.nil? || result.empty?
|
21
|
+
false
|
22
|
+
else
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
class Templates < Base
|
3
|
+
def exists?(name)
|
4
|
+
result = client.template_get('filter' => { 'name' => name })
|
5
|
+
if result.nil? || result.empty?
|
6
|
+
false
|
7
|
+
else
|
8
|
+
true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(options)
|
13
|
+
client.template_create(options) unless exists?(options['host'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_id(name)
|
17
|
+
if exists?(name)
|
18
|
+
client.template_get('filter' => { 'name' => name }).first['templateid']
|
19
|
+
else
|
20
|
+
raise NonExistingTemplate, "Template #{name} does not exist !"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_templates_for_host(id)
|
25
|
+
client.template_get('hostids' => [id]).map { |result_set| result_set['templateid'] }
|
26
|
+
end
|
27
|
+
|
28
|
+
class NonExistingTemplate < StandardError; end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
class Triggers < Base
|
3
|
+
def create(options)
|
4
|
+
client.trigger_create(options) unless exists?(options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def delete(*trigger_ids)
|
8
|
+
client.trigger_delete(trigger_ids)
|
9
|
+
end
|
10
|
+
|
11
|
+
# this is very unefficient
|
12
|
+
# but there is no other way to verify that a trigger exists..
|
13
|
+
def exists?(options)
|
14
|
+
result = client.trigger_get('output' => 'extend',
|
15
|
+
'expandExpression' => true)
|
16
|
+
|
17
|
+
id = extract_id(result, options['expression'])
|
18
|
+
if id.nil?
|
19
|
+
false
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_id(options)
|
26
|
+
result = client.trigger_get('output' => 'extend',
|
27
|
+
'expandExpression' => true)
|
28
|
+
id = extract_id(result, options['expression'])
|
29
|
+
if id.nil?
|
30
|
+
raise NonExistingTrigger, "Trigger with expression #{options['expression']} not found."
|
31
|
+
else
|
32
|
+
id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class NonExistingTrigger < StandardError; end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def extract_id(triggers, expression)
|
41
|
+
result = nil
|
42
|
+
triggers.each do |trigger|
|
43
|
+
if trigger['expression'] == expression
|
44
|
+
result = trigger['triggerid']
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|