zabbixapi 3.1.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +5 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +53 -569
- data/lib/zabbixapi.rb +102 -65
- data/lib/zabbixapi/basic/basic_alias.rb +21 -4
- data/lib/zabbixapi/basic/basic_func.rb +56 -23
- data/lib/zabbixapi/basic/basic_init.rb +21 -4
- data/lib/zabbixapi/basic/basic_logic.rb +75 -18
- data/lib/zabbixapi/classes/actions.rb +8 -4
- data/lib/zabbixapi/classes/applications.rb +20 -6
- data/lib/zabbixapi/classes/configurations.rb +23 -17
- data/lib/zabbixapi/classes/errors.rb +2 -4
- data/lib/zabbixapi/classes/graphs.rb +65 -15
- data/lib/zabbixapi/classes/hostgroups.rb +12 -4
- data/lib/zabbixapi/classes/hosts.rb +36 -10
- data/lib/zabbixapi/classes/httptests.rb +24 -4
- data/lib/zabbixapi/classes/items.rb +24 -5
- data/lib/zabbixapi/classes/maintenance.rb +8 -4
- data/lib/zabbixapi/classes/mediatypes.rb +20 -13
- data/lib/zabbixapi/classes/proxies.rb +29 -8
- data/lib/zabbixapi/classes/screens.rb +41 -25
- data/lib/zabbixapi/classes/server.rb +8 -4
- data/lib/zabbixapi/classes/templates.rb +46 -43
- data/lib/zabbixapi/classes/triggers.rb +43 -16
- data/lib/zabbixapi/classes/unusable.rb +0 -2
- data/lib/zabbixapi/classes/usergroups.rb +33 -26
- data/lib/zabbixapi/classes/usermacros.rb +137 -31
- data/lib/zabbixapi/classes/users.rb +32 -10
- data/lib/zabbixapi/classes/valuemaps.rb +50 -0
- data/lib/zabbixapi/client.rb +61 -22
- data/lib/zabbixapi/version.rb +1 -1
- data/zabbixapi.gemspec +26 -23
- metadata +25 -73
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.travis.yml +0 -41
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -36
- data/Rakefile +0 -1
- data/json-1.x.Gemfile +0 -4
- data/json-1.x.Gemfile.lock +0 -28
- data/spec/action.rb +0 -89
- data/spec/application.rb +0 -83
- data/spec/basic_func.rb +0 -4
- data/spec/configuration.rb +0 -122
- data/spec/graph.rb +0 -135
- data/spec/host.rb +0 -176
- data/spec/hostgroup.rb +0 -55
- data/spec/httptest.rb +0 -136
- data/spec/item.rb +0 -134
- data/spec/maintenance.rb +0 -81
- data/spec/mediatype.rb +0 -50
- data/spec/query.rb +0 -18
- data/spec/screen.rb +0 -88
- data/spec/script.rb +0 -123
- data/spec/server.rb +0 -15
- data/spec/spec_helper.rb +0 -21
- data/spec/template.rb +0 -148
- data/spec/trigger.rb +0 -103
- data/spec/user.rb +0 -116
- data/spec/usergroup.rb +0 -85
- data/spec/usermacro.rb +0 -190
@@ -1,13 +1,17 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class Actions < Basic
|
3
|
-
|
3
|
+
# The method name used for interacting with Actions via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
4
6
|
def method_name
|
5
|
-
|
7
|
+
'action'
|
6
8
|
end
|
7
9
|
|
10
|
+
# The id field name used for identifying specific Action objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
8
13
|
def indentify
|
9
|
-
|
14
|
+
'name'
|
10
15
|
end
|
11
|
-
|
12
16
|
end
|
13
17
|
end
|
@@ -1,16 +1,25 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class Applications < Basic
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# The method name used for interacting with Applications via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
6
6
|
def method_name
|
7
|
-
|
7
|
+
'application'
|
8
8
|
end
|
9
9
|
|
10
|
+
# The id field name used for identifying specific Application objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
10
13
|
def indentify
|
11
|
-
|
14
|
+
'name'
|
12
15
|
end
|
13
16
|
|
17
|
+
# Get or Create Application object using Zabbix API
|
18
|
+
#
|
19
|
+
# @param data [Hash] Needs to include name and hostid to properly identify Applications via Zabbix API
|
20
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
21
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
|
+
# @return [Integer] Zabbix object id
|
14
23
|
def get_or_create(data)
|
15
24
|
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
|
16
25
|
|
@@ -20,10 +29,15 @@ class ZabbixApi
|
|
20
29
|
id
|
21
30
|
end
|
22
31
|
|
32
|
+
# Create or update Application object using Zabbix API
|
33
|
+
#
|
34
|
+
# @param data [Hash] Needs to include name and hostid to properly identify Applications via Zabbix API
|
35
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
36
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
37
|
+
# @return [Integer] Zabbix object id
|
23
38
|
def create_or_update(data)
|
24
39
|
applicationid = get_id(:name => data[:name], :hostid => data[:hostid])
|
25
40
|
applicationid ? update(data.merge(:applicationid => applicationid)) : create(data)
|
26
41
|
end
|
27
|
-
|
28
42
|
end
|
29
43
|
end
|
@@ -1,36 +1,42 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class Configurations < Basic
|
3
|
-
|
3
|
+
# @return [Boolean]
|
4
4
|
def array_flag
|
5
5
|
true
|
6
6
|
end
|
7
7
|
|
8
|
+
# The method name used for interacting with Configurations via Zabbix API
|
9
|
+
#
|
10
|
+
# @return [String]
|
8
11
|
def method_name
|
9
|
-
|
12
|
+
'configuration'
|
10
13
|
end
|
11
14
|
|
15
|
+
# The id field name used for identifying specific Configuration objects via Zabbix API
|
16
|
+
#
|
17
|
+
# @return [String]
|
12
18
|
def indentify
|
13
|
-
|
19
|
+
'host'
|
14
20
|
end
|
15
21
|
|
16
|
-
# Export configuration data
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
22
|
+
# Export configuration data using Zabbix API
|
23
|
+
#
|
24
|
+
# @param data [Hash]
|
25
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
26
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
27
|
+
# @return [Hash]
|
21
28
|
def export(data)
|
22
|
-
@client.api_request(:method =>
|
29
|
+
@client.api_request(:method => 'configuration.export', :params => data)
|
23
30
|
end
|
24
31
|
|
25
|
-
# Import
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
32
|
+
# Import configuration data using Zabbix API
|
33
|
+
#
|
34
|
+
# @param data [Hash]
|
35
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
36
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
37
|
+
# @return [Hash]
|
30
38
|
def import(data)
|
31
|
-
@client.api_request(:method =>
|
39
|
+
@client.api_request(:method => 'configuration.import', :params => data)
|
32
40
|
end
|
33
|
-
|
34
41
|
end
|
35
42
|
end
|
36
|
-
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
|
3
2
|
class BaseError < RuntimeError
|
4
3
|
attr_accessor :response, :error, :error_message
|
5
4
|
|
@@ -10,10 +9,10 @@ class ZabbixApi
|
|
10
9
|
set_error! if @response
|
11
10
|
end
|
12
11
|
|
13
|
-
|
12
|
+
private
|
14
13
|
|
15
14
|
def set_error!
|
16
|
-
@error
|
15
|
+
@error = @response['error'] rescue nil
|
17
16
|
@error_message = "#{@error['message']}: #{@error['data']}" rescue nil
|
18
17
|
end
|
19
18
|
end
|
@@ -23,5 +22,4 @@ class ZabbixApi
|
|
23
22
|
|
24
23
|
class HttpError < BaseError
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
@@ -1,14 +1,25 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class Graphs < Basic
|
3
|
-
|
3
|
+
# The method name used for interacting with Graphs via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
4
6
|
def method_name
|
5
|
-
|
7
|
+
'graph'
|
6
8
|
end
|
7
9
|
|
10
|
+
# The id field name used for identifying specific Graph objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
8
13
|
def indentify
|
9
|
-
|
14
|
+
'name'
|
10
15
|
end
|
11
16
|
|
17
|
+
# Get full/extended Graph data from Zabbix API
|
18
|
+
#
|
19
|
+
# @param data [Hash] Should include object's id field name (indentify) and id value
|
20
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
21
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
|
+
# @return [Hash]
|
12
23
|
def get_full_data(data)
|
13
24
|
log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}"
|
14
25
|
|
@@ -16,47 +27,87 @@ class ZabbixApi
|
|
16
27
|
:method => "#{method_name}.get",
|
17
28
|
:params => {
|
18
29
|
:search => {
|
19
|
-
indentify.to_sym => data[indentify.to_sym]
|
30
|
+
indentify.to_sym => data[indentify.to_sym],
|
20
31
|
},
|
21
|
-
:output =>
|
32
|
+
:output => 'extend',
|
22
33
|
}
|
23
34
|
)
|
24
35
|
end
|
25
36
|
|
37
|
+
# Get Graph ids for Host from Zabbix API
|
38
|
+
#
|
39
|
+
# @param data [Hash] Should include host value to query for matching graphs
|
40
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
41
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
42
|
+
# @return [Array] Returns array of Graph ids
|
26
43
|
def get_ids_by_host(data)
|
27
44
|
ids = []
|
28
|
-
graphs =
|
29
|
-
|
45
|
+
graphs = {}
|
46
|
+
|
47
|
+
result = @client.api_request(
|
48
|
+
:method => 'graph.get',
|
49
|
+
:params => {
|
50
|
+
:filter => {
|
51
|
+
:host => data[:host],
|
52
|
+
},
|
53
|
+
:output => 'extend',
|
54
|
+
}
|
55
|
+
)
|
56
|
+
|
30
57
|
result.each do |graph|
|
31
58
|
num = graph['graphid']
|
32
59
|
name = graph['name']
|
33
60
|
graphs[name] = num
|
34
61
|
filter = data[:filter]
|
35
62
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
ids.push(graphs[name])
|
63
|
+
if filter.nil?
|
64
|
+
ids.push(graphs[name])
|
65
|
+
elsif /#{filter}/ =~ name
|
66
|
+
ids.push(graphs[name])
|
42
67
|
end
|
43
68
|
end
|
69
|
+
|
44
70
|
ids
|
45
71
|
end
|
46
72
|
|
73
|
+
# Get Graph Item object using Zabbix API
|
74
|
+
#
|
75
|
+
# @param data [Hash] Needs to include graphids to properly identify Graph Items via Zabbix API
|
76
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
77
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
78
|
+
# @return [Hash]
|
47
79
|
def get_items(data)
|
48
|
-
@client.api_request(
|
80
|
+
@client.api_request(
|
81
|
+
:method => 'graphitem.get',
|
82
|
+
:params => {
|
83
|
+
:graphids => [data],
|
84
|
+
:output => 'extend',
|
85
|
+
}
|
86
|
+
)
|
49
87
|
end
|
50
88
|
|
89
|
+
# Get or Create Graph object using Zabbix API
|
90
|
+
#
|
91
|
+
# @param data [Hash] Needs to include name and templateid to properly identify Graphs via Zabbix API
|
92
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
93
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
94
|
+
# @return [Integer] Zabbix object id
|
51
95
|
def get_or_create(data)
|
52
96
|
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
|
53
97
|
|
54
98
|
unless (id = get_id(:name => data[:name], :templateid => data[:templateid]))
|
55
99
|
id = create(data)
|
56
100
|
end
|
101
|
+
|
57
102
|
id
|
58
103
|
end
|
59
104
|
|
105
|
+
# Create or update Graph object using Zabbix API
|
106
|
+
#
|
107
|
+
# @param data [Hash] Needs to include name and templateid to properly identify Graphs via Zabbix API
|
108
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
109
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
110
|
+
# @return [Integer] Zabbix object id
|
60
111
|
def create_or_update(data)
|
61
112
|
graphid = get_id(:name => data[:name], :templateid => data[:templateid])
|
62
113
|
graphid ? _update(data.merge(:graphid => graphid)) : create(data)
|
@@ -66,6 +117,5 @@ class ZabbixApi
|
|
66
117
|
data.delete(:name)
|
67
118
|
update(data)
|
68
119
|
end
|
69
|
-
|
70
120
|
end
|
71
121
|
end
|
@@ -1,16 +1,24 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class HostGroups < Basic
|
3
|
-
|
3
|
+
# The method name used for interacting with HostGroups via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
4
6
|
def method_name
|
5
|
-
|
7
|
+
'hostgroup'
|
6
8
|
end
|
7
9
|
|
10
|
+
# The id field name used for identifying specific HostGroup objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
8
13
|
def indentify
|
9
|
-
|
14
|
+
'name'
|
10
15
|
end
|
11
16
|
|
17
|
+
# The key field name used for HostGroup objects via Zabbix API
|
18
|
+
#
|
19
|
+
# @return [String]
|
12
20
|
def key
|
13
|
-
|
21
|
+
'groupid'
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
@@ -1,29 +1,43 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class Hosts < Basic
|
3
|
-
|
3
|
+
# The method name used for interacting with Hosts via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
4
6
|
def method_name
|
5
|
-
|
7
|
+
'host'
|
6
8
|
end
|
7
9
|
|
10
|
+
# The id field name used for identifying specific Host objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
8
13
|
def indentify
|
9
|
-
|
14
|
+
'host'
|
10
15
|
end
|
11
16
|
|
17
|
+
# Dump Host object data by key from Zabbix API
|
18
|
+
#
|
19
|
+
# @param data [Hash] Should include desired object's key and value
|
20
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
21
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
|
+
# @return [Hash]
|
12
23
|
def dump_by_id(data)
|
13
24
|
log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
|
14
25
|
|
15
26
|
@client.api_request(
|
16
|
-
:method =>
|
27
|
+
:method => 'host.get',
|
17
28
|
:params => {
|
18
29
|
:filter => {
|
19
|
-
key.to_sym => data[key.to_sym]
|
30
|
+
key.to_sym => data[key.to_sym],
|
20
31
|
},
|
21
|
-
:output =>
|
22
|
-
:selectGroups =>
|
32
|
+
:output => 'extend',
|
33
|
+
:selectGroups => 'shorten',
|
23
34
|
}
|
24
35
|
)
|
25
36
|
end
|
26
37
|
|
38
|
+
# The default options used when creating Host objects via Zabbix API
|
39
|
+
#
|
40
|
+
# @return [Hash]
|
27
41
|
def default_options
|
28
42
|
{
|
29
43
|
:host => nil,
|
@@ -31,21 +45,33 @@ class ZabbixApi
|
|
31
45
|
:status => 0,
|
32
46
|
:available => 1,
|
33
47
|
:groups => [],
|
34
|
-
:proxy_hostid => nil
|
48
|
+
:proxy_hostid => nil,
|
35
49
|
}
|
36
50
|
end
|
37
51
|
|
52
|
+
# Unlink/Remove Templates from Hosts using Zabbix API
|
53
|
+
#
|
54
|
+
# @param data [Hash] Should include hosts_id array and templates_id array
|
55
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
56
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
57
|
+
# @return [Boolean]
|
38
58
|
def unlink_templates(data)
|
39
59
|
result = @client.api_request(
|
40
|
-
:method =>
|
60
|
+
:method => 'host.massRemove',
|
41
61
|
:params => {
|
42
62
|
:hostids => data[:hosts_id],
|
43
|
-
:templates => data[:templates_id]
|
63
|
+
:templates => data[:templates_id],
|
44
64
|
}
|
45
65
|
)
|
46
66
|
result.empty? ? false : true
|
47
67
|
end
|
48
68
|
|
69
|
+
# Create or update Host object using Zabbix API
|
70
|
+
#
|
71
|
+
# @param data [Hash] Needs to include host to properly identify Hosts via Zabbix API
|
72
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
73
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
74
|
+
# @return [Integer] Zabbix object id
|
49
75
|
def create_or_update(data)
|
50
76
|
hostid = get_id(:host => data[:host])
|
51
77
|
hostid ? update(data.merge(:hostid => hostid)) : create(data)
|
@@ -1,22 +1,36 @@
|
|
1
1
|
class ZabbixApi
|
2
2
|
class HttpTests < Basic
|
3
|
-
|
3
|
+
# The method name used for interacting with HttpTests via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
4
6
|
def method_name
|
5
|
-
|
7
|
+
'httptest'
|
6
8
|
end
|
7
9
|
|
10
|
+
# The id field name used for identifying specific HttpTest objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
8
13
|
def indentify
|
9
|
-
|
14
|
+
'name'
|
10
15
|
end
|
11
16
|
|
17
|
+
# The default options used when creating HttpTest objects via Zabbix API
|
18
|
+
#
|
19
|
+
# @return [Hash]
|
12
20
|
def default_options
|
13
21
|
{
|
14
22
|
:hostid => nil,
|
15
23
|
:name => nil,
|
16
|
-
:steps => []
|
24
|
+
:steps => [],
|
17
25
|
}
|
18
26
|
end
|
19
27
|
|
28
|
+
# Get or Create HttpTest object using Zabbix API
|
29
|
+
#
|
30
|
+
# @param data [Hash] Needs to include name and hostid to properly identify HttpTests via Zabbix API
|
31
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
32
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
33
|
+
# @return [Integer] Zabbix object id
|
20
34
|
def get_or_create(data)
|
21
35
|
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
|
22
36
|
|
@@ -26,6 +40,12 @@ class ZabbixApi
|
|
26
40
|
id
|
27
41
|
end
|
28
42
|
|
43
|
+
# Create or update HttpTest object using Zabbix API
|
44
|
+
#
|
45
|
+
# @param data [Hash] Needs to include name and hostid to properly identify HttpTests via Zabbix API
|
46
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
47
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
48
|
+
# @return [Integer] Zabbix object id
|
29
49
|
def create_or_update(data)
|
30
50
|
httptestid = get_id(:name => data[:name], :hostid => data[:hostid])
|
31
51
|
httptestid ? update(data.merge(:httptestid => httptestid)) : create(data)
|