zabbixapi 0.1.6 → 0.1.6.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/README.rdoc +20 -6
- data/examples/zabbix_filesystem +1 -1
- data/lib/zabbixapi/application.rb +14 -31
- data/lib/zabbixapi/base.rb +24 -25
- data/lib/zabbixapi/graph.rb +19 -33
- data/lib/zabbixapi/group.rb +31 -51
- data/lib/zabbixapi/host.rb +43 -61
- data/lib/zabbixapi/item.rb +56 -97
- data/lib/zabbixapi/screen.rb +65 -112
- data/lib/zabbixapi/template.rb +42 -98
- data/lib/zabbixapi/trigger.rb +28 -59
- data/lib/zabbixapi/usermacro.rb +27 -42
- data/spec/item.rb +38 -42
- data/zabbixapi.gemspec +1 -1
- metadata +2 -2
data/lib/zabbixapi/trigger.rb
CHANGED
@@ -1,95 +1,64 @@
|
|
1
1
|
module Zabbix
|
2
|
-
|
3
2
|
class ZabbixApi
|
4
|
-
def add_trigger(trigger)
|
5
3
|
|
4
|
+
def add_trigger(trigger)
|
6
5
|
message = {
|
7
|
-
|
8
|
-
|
6
|
+
'method' => 'trigger.create',
|
7
|
+
'params' => [trigger]
|
9
8
|
}
|
10
|
-
|
11
9
|
response = send_request(message)
|
12
|
-
|
13
|
-
unless response.empty? then
|
14
|
-
result = response['triggerids'][0]
|
15
|
-
else
|
16
|
-
result = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
return result
|
20
|
-
|
10
|
+
response.empty? ? nil : response['triggerids'][0]
|
21
11
|
end
|
22
12
|
|
23
13
|
def get_trigger_id(host_id, trigger_name)
|
24
|
-
|
25
14
|
message = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
'method' => 'trigger.get',
|
16
|
+
'params' => {
|
17
|
+
'filter' => {
|
18
|
+
'hostid' => host_id,
|
19
|
+
'description' => trigger_name
|
20
|
+
}
|
31
21
|
}
|
32
|
-
}
|
33
22
|
}
|
34
|
-
|
35
23
|
response = send_request(message)
|
36
|
-
|
37
|
-
unless response.empty? then
|
38
|
-
result = response[0]['triggerid']
|
39
|
-
else
|
40
|
-
result = nil
|
41
|
-
end
|
42
|
-
|
43
|
-
return result
|
24
|
+
response.empty? ? nil : response[0]['triggerid']
|
44
25
|
end
|
45
26
|
|
46
27
|
def get_triggers_by_host(host_id)
|
47
|
-
|
48
28
|
message = {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
29
|
+
'method' => 'trigger.get',
|
30
|
+
'params' => {
|
31
|
+
'filter' => {
|
32
|
+
'hostid' => host_id,
|
33
|
+
},
|
34
|
+
'extendoutput' => '1'
|
35
|
+
}
|
56
36
|
}
|
57
|
-
|
58
37
|
response = send_request(message)
|
59
|
-
|
60
|
-
|
38
|
+
if response.empty?
|
39
|
+
result = {}
|
40
|
+
else
|
61
41
|
result = {}
|
62
42
|
response.each do |trigger|
|
63
43
|
trigger_id = trigger['triggerid']
|
64
44
|
description = trigger['description']
|
65
45
|
result[trigger_id] = description
|
66
46
|
end
|
67
|
-
else
|
68
|
-
result = {}
|
69
47
|
end
|
70
|
-
|
71
48
|
return result
|
72
49
|
end
|
73
50
|
|
74
51
|
def update_trigger_status(trigger_id, status)
|
75
|
-
|
76
52
|
message = {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
53
|
+
'method' => 'trigger.update_status',
|
54
|
+
'params' => {
|
55
|
+
'triggerid' => trigger_id,
|
56
|
+
'status' => status
|
57
|
+
}
|
82
58
|
}
|
83
|
-
|
84
59
|
response = send_request(message)
|
85
|
-
|
86
|
-
unless response.empty? then
|
87
|
-
result = response['triggerids'][0]
|
88
|
-
else
|
89
|
-
result = nil
|
90
|
-
end
|
91
|
-
|
92
|
-
return result
|
60
|
+
response.empty? ? nil : response['triggerids'][0]
|
93
61
|
end
|
62
|
+
|
94
63
|
end
|
95
64
|
end
|
data/lib/zabbixapi/usermacro.rb
CHANGED
@@ -1,74 +1,59 @@
|
|
1
1
|
module Zabbix
|
2
|
-
|
3
2
|
class ZabbixApi
|
4
|
-
def add_macro(host_id, macro_name, macro_value)
|
5
3
|
|
4
|
+
def add_macro(host_id, macro_name, macro_value)
|
6
5
|
message = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
'method' => 'Usermacro.create',
|
7
|
+
'params' => {
|
8
|
+
'hostid' => host_id,
|
9
|
+
'macro' => macro_name,
|
10
|
+
'value' => macro_value
|
11
|
+
}
|
13
12
|
}
|
14
|
-
|
15
13
|
response = send_request(message)
|
16
|
-
|
17
|
-
if hostmacroids = response['hostmacroids'] then
|
18
|
-
result = hostmacroids
|
19
|
-
else
|
20
|
-
result = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
return result
|
14
|
+
hostmacroids == response['hostmacroids'] ? hostmacroids : nil
|
24
15
|
end
|
25
16
|
|
26
17
|
def get_macro(host_id, macro_name)
|
27
|
-
|
28
18
|
message = {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
19
|
+
'method' => 'Usermacro.get',
|
20
|
+
'params' => {
|
21
|
+
'hostids' => host_id,
|
22
|
+
'macros' => macro_name,
|
23
|
+
'extendoutput' => '1'
|
24
|
+
}
|
35
25
|
}
|
36
|
-
|
37
26
|
response = send_request(message)
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
if response.empty?
|
28
|
+
result = nil
|
29
|
+
else
|
30
|
+
if hostmacroid == response[0]['hostmacroid']
|
41
31
|
macro_id = hostmacroid
|
42
32
|
macro_value = response[0]['value']
|
43
33
|
|
44
34
|
result = {
|
45
|
-
|
46
|
-
|
35
|
+
'id' => macro_id,
|
36
|
+
'value' => macro_value
|
47
37
|
}
|
48
38
|
else
|
49
39
|
result = nil
|
50
40
|
end
|
51
|
-
else
|
52
|
-
result = nil
|
53
41
|
end
|
54
|
-
|
55
42
|
return result
|
56
43
|
end
|
57
44
|
|
58
45
|
def set_macro_value(host_id, macro_name, macro_value)
|
59
|
-
|
60
46
|
message = {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
47
|
+
'method' => 'usermacro.updateValue',
|
48
|
+
'params' => {
|
49
|
+
'hostid' => host_id,
|
50
|
+
'macro' => macro_name,
|
51
|
+
'value' => macro_value
|
52
|
+
}
|
67
53
|
}
|
68
|
-
|
69
54
|
response = send_request(message)
|
70
|
-
|
71
55
|
return true
|
72
56
|
end
|
57
|
+
|
73
58
|
end
|
74
59
|
end
|
data/spec/item.rb
CHANGED
@@ -1,60 +1,56 @@
|
|
1
1
|
require 'zabbixapi'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require 'webmock/rspec'
|
5
|
-
include WebMock::API
|
4
|
+
#require 'webmock/rspec'
|
5
|
+
#include WebMock::API
|
6
6
|
|
7
7
|
# settings
|
8
8
|
api_url = 'http://zabbix.local/api_jsonrpc.php'
|
9
|
-
api_login = '
|
9
|
+
api_login = 'Admin'
|
10
10
|
api_password = 'zabbix'
|
11
11
|
|
12
|
-
# 01. Add item
|
13
|
-
auth_response = '{"jsonrpc":"2.0","result":"a82039d56baba1f92311aa917af9939b","id":83254}'
|
14
|
-
add_item_response = '{"jsonrpc":"2.0","result":{"itemids":["19541"]},"id":80163}'
|
15
|
-
item_options = {
|
16
|
-
'description' => "Description",
|
17
|
-
'key_' => "key[,avg1]",
|
18
|
-
'hostid' => '10160',
|
19
|
-
'applications' => [ 393 ],
|
20
|
-
'history' => 7,
|
21
|
-
'trends' => 30,
|
22
|
-
'delay' => 60,
|
23
|
-
'value_type' => 0
|
24
|
-
}
|
25
12
|
|
26
|
-
|
27
|
-
|
13
|
+
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
14
|
+
#zbx.debug = true
|
28
15
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
result = zbx.
|
33
|
-
result.should eq("19541")
|
16
|
+
# 01. Create group
|
17
|
+
describe Zabbix::ZabbixApi, "create_group" do
|
18
|
+
it "Create some group" do
|
19
|
+
result = zbx.add_group('some_group')
|
34
20
|
end
|
35
21
|
end
|
36
22
|
|
37
|
-
# 02.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
'
|
42
|
-
|
43
|
-
|
44
|
-
'applications' => [ 393 ],
|
45
|
-
'history' => 7,
|
46
|
-
'trends' => 30,
|
47
|
-
'delay' => 60,
|
48
|
-
'value_type' => 0
|
23
|
+
# 02. Create host
|
24
|
+
host_options = {
|
25
|
+
"ip" => '127.0.0.1',
|
26
|
+
"dns" => 'my.example.com',
|
27
|
+
"host" => 'my.example.com',
|
28
|
+
"useip" => 1,
|
29
|
+
"groups" => ['some_group']
|
49
30
|
}
|
31
|
+
describe Zabbix::ZabbixApi, "create_host" do
|
32
|
+
it "Create host" do
|
33
|
+
result = zbx.add_host(host_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# 03. Get host
|
38
|
+
describe Zabbix::ZabbixApi, "get_host" do
|
39
|
+
it "Get host by name" do
|
40
|
+
result = zbx.get_host_id('my.example.com')
|
41
|
+
end
|
42
|
+
end
|
50
43
|
|
51
|
-
|
52
|
-
|
44
|
+
# 04. Delete group
|
45
|
+
describe Zabbix::ZabbixApi, "delete_group" do
|
46
|
+
it "Delete some group" do
|
47
|
+
result = zbx.delete_group('some_group')
|
48
|
+
end
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
result = zbx.
|
58
|
-
result.should eq("19541")
|
51
|
+
# 05. Delete host
|
52
|
+
describe Zabbix::ZabbixApi, "delete_host" do
|
53
|
+
it "Delete host" do
|
54
|
+
result = zbx.delete_host('my.example.com')
|
59
55
|
end
|
60
56
|
end
|
data/zabbixapi.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbixapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.6
|
4
|
+
version: 0.1.6.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: 2012-10-
|
12
|
+
date: 2012-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby module for work with zabbix api v1.8.
|
15
15
|
email: vadv.mkn@gmail.com
|