zabbixapi 0.5.0b2 → 0.5.0b3
Sign up to get free protection for your applications and to get access to all the features.
- 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/lib/zabbixapi/items.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
class Items
|
2
|
+
class Items < Basic
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
|
4
|
+
def api_method_name
|
5
|
+
"item"
|
6
|
+
end
|
7
|
+
|
8
|
+
def api_identify
|
9
|
+
"description"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(client)
|
13
|
+
@client = client
|
7
14
|
@item_default_options = {
|
8
15
|
:description => nil,
|
9
16
|
:key_ => nil,
|
@@ -48,40 +55,14 @@ class ZabbixApi
|
|
48
55
|
def create(data)
|
49
56
|
result = @client.api_request(:method => "item.create", :params => [merge_params(data)] )
|
50
57
|
result.empty? ? nil : result['itemids'][0].to_i
|
51
|
-
end
|
52
|
-
|
53
|
-
def add(data)
|
54
|
-
create(data)
|
55
|
-
end
|
58
|
+
end
|
56
59
|
|
57
60
|
def get_full_data(data)
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_id(data)
|
62
|
-
result = get_full_data(data)
|
63
|
-
itemid = nil
|
64
|
-
result.each { |item| itemid = item['itemid'].to_i if item['name'] == data[:name] }
|
65
|
-
itemid
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_or_update(data)
|
69
|
-
itemid = get_id(:description => data[:description], :hostid => data[:hostid])
|
70
|
-
itemid ? update(data.merge(:itemid => itemid)) : create(data)
|
71
|
-
end
|
72
|
-
|
73
|
-
def update(data)
|
74
|
-
result = @client.api_request(:method => "item.update", :params => data)
|
75
|
-
result.empty? ? nil : result['itemids'][0].to_i
|
61
|
+
get_full_data_filter(data)
|
76
62
|
end
|
77
63
|
|
78
64
|
def delete(data)
|
79
|
-
|
80
|
-
result.empty? ? nil : result['itemids'][0].to_i
|
81
|
-
end
|
82
|
-
|
83
|
-
def destroy(data)
|
84
|
-
delete(data)
|
65
|
+
delete_array(data)
|
85
66
|
end
|
86
67
|
|
87
68
|
end
|
data/lib/zabbixapi/mediatypes.rb
CHANGED
@@ -1,62 +1,28 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
class Mediatypes
|
2
|
+
class Mediatypes < Basic
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:exec_path => "", #Name of external script
|
14
|
-
:gsm_modem => "", #Serial device name of GSM modem
|
15
|
-
:username => "", #Jabber user name used by Zabbix server
|
16
|
-
:passwd => "" #Jabber password used by Zabbix server
|
17
|
-
}
|
18
|
-
end
|
4
|
+
#:description => "", #Name
|
5
|
+
#:type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
|
6
|
+
#:smtp_server => "",
|
7
|
+
#:smtp_helo => "",
|
8
|
+
#:smtp_email => "", #Email address of Zabbix server
|
9
|
+
#:exec_path => "", #Name of external script
|
10
|
+
#:gsm_modem => "", #Serial device name of GSM modem
|
11
|
+
#:username => "", #Jabber user name used by Zabbix server
|
12
|
+
#:passwd => "", #Jabber password used by Zabbix server
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
# * *Args* :
|
23
|
-
# - +data+ -> Hash with :description => "MediaGroup" and mediatype options
|
24
|
-
# * *Returns* :
|
25
|
-
# - Nil or Integer
|
26
|
-
def create(data)
|
27
|
-
result = @client.api_request(:method => "mediatype.create", :params => data)
|
28
|
-
result ? result['mediatypeids'][0].to_i : nil
|
14
|
+
def api_method_name
|
15
|
+
"mediatype"
|
29
16
|
end
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
def add(data)
|
34
|
-
create(data)
|
18
|
+
def api_identify
|
19
|
+
"name"
|
35
20
|
end
|
36
21
|
|
37
|
-
# Delete MediaType
|
38
|
-
#
|
39
|
-
# * *Args* :
|
40
|
-
# - +data+ -> Array with mediatypeids
|
41
|
-
# * *Returns* :
|
42
|
-
# - Nil or Integer
|
43
22
|
def delete(data)
|
44
|
-
|
45
|
-
result ? result['mediatypeids'][0].to_i : nil
|
46
|
-
end
|
47
|
-
|
48
|
-
# Destroy MediaType
|
49
|
-
# Synonym delete
|
50
|
-
def destroy(data)
|
51
|
-
delete(data)
|
23
|
+
delete_array(data)
|
52
24
|
end
|
53
25
|
|
54
|
-
# Get MediaType info
|
55
|
-
#
|
56
|
-
# * *Args* :
|
57
|
-
# - +data+ -> Hash with :description => "MediaType"
|
58
|
-
# * *Returns* :
|
59
|
-
# - Nil or Integer
|
60
26
|
def get_full_data(data)
|
61
27
|
@client.api_request(
|
62
28
|
:method => "mediatype.get",
|
@@ -67,44 +33,5 @@ class ZabbixApi
|
|
67
33
|
)
|
68
34
|
end
|
69
35
|
|
70
|
-
def get(data)
|
71
|
-
get_full_data(data)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Return MediaTypeid
|
75
|
-
#
|
76
|
-
# * *Args* :
|
77
|
-
# - +data+ -> Hash with :description => "MediaType"
|
78
|
-
# * *Returns* :
|
79
|
-
# - Nil or Integer
|
80
|
-
def get_id(data)
|
81
|
-
result = get_full_data(data)
|
82
|
-
mediatypeid = nil
|
83
|
-
result.each { |mt| mediatypeid = mt['mediatypeid'].to_i if mt['description'] == data[:description] }
|
84
|
-
mediatypeid
|
85
|
-
end
|
86
|
-
|
87
|
-
# Return MediaTypeid
|
88
|
-
#
|
89
|
-
# * *Args* :
|
90
|
-
# - +data+ -> Hash with :description => "MediaType"
|
91
|
-
# * *Returns* :
|
92
|
-
# - Nil or Integer
|
93
|
-
def update(data)
|
94
|
-
result = @client.api_request(:method => "mediatype.update", :params => data)
|
95
|
-
result.empty? ? nil : result['mediatypeids'][0].to_i
|
96
|
-
end
|
97
|
-
|
98
|
-
# Return MediaTypeid
|
99
|
-
#
|
100
|
-
# * *Args* :
|
101
|
-
# - +data+ -> Hash with :name => "UserGroup"
|
102
|
-
# * *Returns* :
|
103
|
-
# - Integer
|
104
|
-
def create_or_update(data)
|
105
|
-
mediatypeid = get_id(:description => data[:description], :mediatypeid => data[:mediatypeid])
|
106
|
-
mediatypeid ? update(data.merge(:mediatypeid => mediatypeid)) : create(data)
|
107
|
-
end
|
108
|
-
|
109
36
|
end
|
110
37
|
end
|
data/lib/zabbixapi/screens.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
class Screens
|
2
|
+
class Screens < Basic
|
3
|
+
|
4
|
+
def api_method_name
|
5
|
+
"screen"
|
6
|
+
end
|
7
|
+
|
8
|
+
def api_identify
|
9
|
+
"name"
|
10
|
+
end
|
3
11
|
|
4
12
|
# extracted from frontends/php/include/defines.inc.php
|
5
13
|
#SCREEN_RESOURCE_GRAPH => 0,
|
@@ -20,42 +28,6 @@ class ZabbixApi
|
|
20
28
|
#SCREEN_RESOURCE_SYSTEM_STATUS => 15,
|
21
29
|
#SCREEN_RESOURCE_HOST_TRIGGERS => 16
|
22
30
|
|
23
|
-
def initialize(options = {})
|
24
|
-
@client = Client.new(options)
|
25
|
-
@options = options
|
26
|
-
@screeb_default_options = {
|
27
|
-
:vsize => 3
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Create screen
|
32
|
-
#
|
33
|
-
# * *Args* :
|
34
|
-
# - +data+ -> Hash with :name => "Screen name", hsize (rows) and vsize (columns) and array :screenitems => []
|
35
|
-
# screenitems contains :resourcetype (0 - graph), :resourcetypeid (id item) and :x and :y position
|
36
|
-
# * *Returns* :
|
37
|
-
# - Nil or Integer
|
38
|
-
def create(data)
|
39
|
-
result = @client.api_request(:method => "screen.create", :params => data)
|
40
|
-
result ? result['screenids'][0].to_i : nil
|
41
|
-
end
|
42
|
-
|
43
|
-
# Create screen
|
44
|
-
# Synonym create
|
45
|
-
def add(data)
|
46
|
-
create(data)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Update screen
|
50
|
-
#
|
51
|
-
# * *Args* :
|
52
|
-
# - +data+ -> Hash with :screenid => [ "screenid" ]
|
53
|
-
# * *Returns* :
|
54
|
-
# - Nil or Integer
|
55
|
-
def update(data)
|
56
|
-
result = @client.api_request(:method => "screen.update", :params => data)
|
57
|
-
result ? result['screenids'][0].to_i : nil
|
58
|
-
end
|
59
31
|
|
60
32
|
# Return info about screen
|
61
33
|
#
|
@@ -68,29 +40,6 @@ class ZabbixApi
|
|
68
40
|
result.empty? ? [] : result
|
69
41
|
end
|
70
42
|
|
71
|
-
# Return screenid
|
72
|
-
#
|
73
|
-
# * *Args* :
|
74
|
-
# - +data+ -> Hash with :name => "Screen name"
|
75
|
-
# * *Returns* :
|
76
|
-
# - Nil or Integer
|
77
|
-
def get_id(data)
|
78
|
-
result = get_full_data(data)
|
79
|
-
screenid = nil
|
80
|
-
result.each { |screen| screenid = screen['screenid'].to_i if screen['name'] == data[:name] }
|
81
|
-
screenid
|
82
|
-
end
|
83
|
-
|
84
|
-
# Delete screen
|
85
|
-
#
|
86
|
-
# * *Args* :
|
87
|
-
# - +data+ -> Hash with :params => [screenid]
|
88
|
-
# * *Returns* :
|
89
|
-
# - Nil or Integer
|
90
|
-
def delete(data)
|
91
|
-
result = @client.api_request(:method => "screen.delete", :params => data)
|
92
|
-
result.empty? ? nil : result['screenids'][0].to_i
|
93
|
-
end
|
94
43
|
|
95
44
|
# Create screen all graphs for host
|
96
45
|
#
|
data/lib/zabbixapi/server.rb
CHANGED
data/lib/zabbixapi/templates.rb
CHANGED
@@ -1,51 +1,22 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
class Templates
|
2
|
+
class Templates < Basic
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
@options = options
|
4
|
+
def api_method_name
|
5
|
+
"template"
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
# * *Args* :
|
12
|
-
# - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
|
13
|
-
# * *Returns* :
|
14
|
-
# - Nil or Integer
|
15
|
-
def create(data)
|
16
|
-
result = @client.api_request(:method => "template.create", :params => [data])
|
17
|
-
result.empty? ? nil : result['templateids'][0].to_i
|
8
|
+
def api_identify
|
9
|
+
"name"
|
18
10
|
end
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
def add(data)
|
23
|
-
create(data)
|
12
|
+
def create(data)
|
13
|
+
create_array(data)
|
24
14
|
end
|
25
15
|
|
26
|
-
# Delete template
|
27
|
-
#
|
28
|
-
# * *Args* :
|
29
|
-
# - +data+ -> Hash with :host => "Template_Name"
|
30
|
-
# * *Returns* :
|
31
|
-
# - Nil or Integer
|
32
16
|
def delete(data)
|
33
|
-
|
34
|
-
result.empty? ? nil : result['templateids'][0].to_i
|
17
|
+
delete_array_sym(data)
|
35
18
|
end
|
36
19
|
|
37
|
-
# Destroy template
|
38
|
-
# Synonym delete
|
39
|
-
def destroy(data)
|
40
|
-
delete(data)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Return templateids linked with host
|
44
|
-
#
|
45
|
-
# * *Args* :
|
46
|
-
# - +data+ -> Hash with :hostids => [hostid]
|
47
|
-
# * *Returns* :
|
48
|
-
# - Array with templateids
|
49
20
|
def get_ids_by_host(data)
|
50
21
|
result = []
|
51
22
|
@client.api_request(:method => "template.get", :params => data).each do |tmpl|
|
@@ -53,19 +24,7 @@ class ZabbixApi
|
|
53
24
|
end
|
54
25
|
result
|
55
26
|
end
|
56
|
-
|
57
|
-
# Return templateid
|
58
|
-
#
|
59
|
-
# * *Args* :
|
60
|
-
# - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
|
61
|
-
# * *Returns* :
|
62
|
-
# - Integer
|
63
|
-
def get_or_create(data)
|
64
|
-
unless templateid = get_id(:host => data[:host])
|
65
|
-
templateid = create(data)
|
66
|
-
end
|
67
|
-
templateid
|
68
|
-
end
|
27
|
+
|
69
28
|
|
70
29
|
# Analog Zabbix api call massUpdate
|
71
30
|
#
|
@@ -156,17 +115,5 @@ class ZabbixApi
|
|
156
115
|
end
|
157
116
|
end
|
158
117
|
|
159
|
-
# Return info about template
|
160
|
-
#
|
161
|
-
# * *Args* :
|
162
|
-
# - +data+ -> Hash with :host => "Template name"
|
163
|
-
# * *Returns* :
|
164
|
-
# - Nil or Integer
|
165
|
-
def get_id(data)
|
166
|
-
templateid = nil
|
167
|
-
get_full_data(data).each { |template| templateid = template['templateid'].to_i if template['host'] == data[:host] }
|
168
|
-
templateid
|
169
|
-
end
|
170
|
-
|
171
118
|
end
|
172
|
-
end
|
119
|
+
end
|
data/lib/zabbixapi/triggers.rb
CHANGED
@@ -1,49 +1,25 @@
|
|
1
1
|
class ZabbixApi
|
2
|
-
class Triggers
|
2
|
+
class Triggers < Basic
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
@options = options
|
4
|
+
def api_method_name
|
5
|
+
"trigger"
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
result.empty? ? nil : result['triggerids'][0].to_i
|
12
|
-
end
|
13
|
-
|
14
|
-
def add(data)
|
15
|
-
create(data)
|
8
|
+
def api_identify
|
9
|
+
"description"
|
16
10
|
end
|
17
11
|
|
18
12
|
def delete(data)
|
19
|
-
|
20
|
-
result.empty? ? nil : result['triggerids'][0].to_i
|
21
|
-
end
|
22
|
-
|
23
|
-
def destroy(data)
|
24
|
-
delete(data)
|
13
|
+
delete_array(data)
|
25
14
|
end
|
26
15
|
|
27
|
-
def
|
28
|
-
|
29
|
-
result.empty? ? nil : result['triggerids'][0].to_i
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_or_update(data)
|
33
|
-
triggerid = get_id(:description => data[:description], :templateid => data[:templateid])
|
34
|
-
triggerid ? update(data.merge(:triggerid => triggerid)) : create(data)
|
16
|
+
def create(data)
|
17
|
+
create_array(data)
|
35
18
|
end
|
36
19
|
|
37
20
|
def get_full_data(data)
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def get_id(data)
|
42
|
-
result = get_full_data(data)
|
43
|
-
triggerid = nil
|
44
|
-
result.each { |template| triggerid = template['triggerid'].to_i if template['name'] == data[:name] }
|
45
|
-
triggerid
|
21
|
+
get_full_data_filter(data)
|
46
22
|
end
|
47
23
|
|
48
24
|
end
|
49
|
-
end
|
25
|
+
end
|