zabbixapi 0.1.6.4 → 0.1.7
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 +7 -1
- data/examples/basic_auth.rb +30 -0
- data/examples/maintenance-example.rb +55 -0
- data/examples/populate_new_zabbix.sh +84 -0
- data/examples/zabbix_availability +7 -7
- data/examples/zabbix_clear_default +36 -0
- data/examples/zabbix_cpufan-sersor +114 -0
- data/examples/zabbix_cputemp-sersor +112 -0
- data/examples/zabbix_disk_io +8 -8
- data/examples/zabbix_filesystem +20 -20
- data/examples/zabbix_group +25 -0
- data/examples/zabbix_hlsp +100 -0
- data/examples/zabbix_host +37 -0
- data/examples/zabbix_iops +131 -0
- data/examples/zabbix_ipmi-cpufan-sersor +101 -0
- data/examples/zabbix_ipmi_systemp +110 -0
- data/examples/zabbix_la +42 -7
- data/examples/zabbix_mailer +125 -0
- data/examples/zabbix_mdadm +72 -0
- data/examples/zabbix_megaraid +71 -0
- data/examples/zabbix_memory +35 -21
- data/examples/zabbix_named +71 -0
- data/examples/zabbix_net +144 -8
- data/examples/zabbix_nginx +167 -0
- data/examples/zabbix_nginx_500 +112 -0
- data/examples/zabbix_ntp +71 -0
- data/examples/zabbix_nv-gputemp +111 -0
- data/examples/zabbix_pgsql +125 -0
- data/examples/zabbix_server_process +71 -0
- data/examples/zabbix_smart_blade +94 -0
- data/examples/zabbix_ssh +71 -0
- data/examples/zabbix_varnish +71 -0
- data/lib/zabbixapi.rb +1 -0
- data/lib/zabbixapi/application.rb +2 -2
- data/lib/zabbixapi/base.rb +6 -1
- data/lib/zabbixapi/host.rb +3 -3
- data/lib/zabbixapi/maintenance.rb +78 -0
- data/spec/localhost.rb +7 -1
- data/zabbixapi.gemspec +2 -2
- metadata +30 -4
- data/spec/request.rb +0 -130
data/lib/zabbixapi/base.rb
CHANGED
@@ -23,7 +23,7 @@ module Zabbix
|
|
23
23
|
|
24
24
|
class ZabbixApi
|
25
25
|
|
26
|
-
attr_accessor :debug
|
26
|
+
attr_accessor :debug, :basic_auth
|
27
27
|
|
28
28
|
def initialize (api_url, api_user, api_password)
|
29
29
|
@api_url = api_url
|
@@ -31,6 +31,7 @@ module Zabbix
|
|
31
31
|
@api_password = api_password
|
32
32
|
|
33
33
|
@debug = false # Disable debug by default
|
34
|
+
@basic_auth = false #Disable basic_auth by default
|
34
35
|
end
|
35
36
|
|
36
37
|
def do_request(message)
|
@@ -54,6 +55,10 @@ module Zabbix
|
|
54
55
|
request.add_field('Content-Type', 'application/json-rpc')
|
55
56
|
request.body=(message_json)
|
56
57
|
|
58
|
+
if @basic_auth
|
59
|
+
request.basic_auth @api_user, @api_password
|
60
|
+
end
|
61
|
+
|
57
62
|
begin
|
58
63
|
puts "[ZBXAPI] : #{Time.now()} : INFO : Do request. Body => #{request.body}" if @debug
|
59
64
|
response = http.request(request)
|
data/lib/zabbixapi/host.rb
CHANGED
@@ -8,8 +8,8 @@ module Zabbix
|
|
8
8
|
'method' => 'host.update',
|
9
9
|
'params' => host
|
10
10
|
}
|
11
|
-
|
12
|
-
|
11
|
+
response = send_request(message)
|
12
|
+
response.empty? ? nil : response['hostids'][0].to_i
|
13
13
|
end
|
14
14
|
|
15
15
|
def add_host(host_options)
|
@@ -50,7 +50,7 @@ module Zabbix
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
response = send_request(message)
|
53
|
-
response.empty? ?
|
53
|
+
response.empty? ? nil : response[0]['hostid'].to_i
|
54
54
|
end
|
55
55
|
|
56
56
|
def delete_host(hostname)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Zabbix
|
2
|
+
class ZabbixApi
|
3
|
+
|
4
|
+
def create_maintenance(host_id, maintenance_options)
|
5
|
+
|
6
|
+
time_now = Time.now.to_i
|
7
|
+
|
8
|
+
maintenance_default = {
|
9
|
+
'hostids' => [host_id],
|
10
|
+
'groupids' => [],
|
11
|
+
'name' => '',
|
12
|
+
'maintenance_type' => '0', # 0 = with data collection, 1 = without
|
13
|
+
'description' => '',
|
14
|
+
'active_since' => '',
|
15
|
+
'active_till' => ''
|
16
|
+
}
|
17
|
+
message = {
|
18
|
+
'method' => 'maintenance.create',
|
19
|
+
'params' => merge_opt(maintenance_default, maintenance_options)
|
20
|
+
}
|
21
|
+
response = send_request(message)
|
22
|
+
response.empty? ? nil : response['maintenanceids'][0].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_maintenance_id(host_id)
|
26
|
+
message = {
|
27
|
+
'method' => 'maintenance.get',
|
28
|
+
'params' => {
|
29
|
+
'hostids' => [host_id]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
response = send_request(message)
|
33
|
+
response.empty? ? nil : response[0]['maintenanceid'].to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def maintenance_exists?(maintenance_id)
|
37
|
+
# seems like .nodeids and .maintenance are ignored
|
38
|
+
# mmethner: .maintenanceid is the only settings which not always returns true
|
39
|
+
message = {
|
40
|
+
'method' => 'maintenance.exists',
|
41
|
+
'params' => {
|
42
|
+
'nodeids' => [],
|
43
|
+
'maintenance' => '',
|
44
|
+
'maintenanceid' => maintenance_id,
|
45
|
+
}
|
46
|
+
}
|
47
|
+
response = send_request(message)
|
48
|
+
response
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_maintenance(maintenance_id, maintenance_options)
|
52
|
+
|
53
|
+
maintenance_options["maintenanceid"] = maintenance_id
|
54
|
+
message = {
|
55
|
+
'method' => 'maintenance.update',
|
56
|
+
'params' => maintenance_options
|
57
|
+
}
|
58
|
+
response = send_request(message)
|
59
|
+
|
60
|
+
# the zabbix api returns boolean
|
61
|
+
# even the official zabbix api documentation specifies an array
|
62
|
+
response
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_maintenance(maintenance_id)
|
66
|
+
message = {
|
67
|
+
'method' => 'maintenance.delete',
|
68
|
+
'params' => [maintenance_id]
|
69
|
+
}
|
70
|
+
response = send_request(message)
|
71
|
+
|
72
|
+
# the zabbix api returns boolean
|
73
|
+
# even the official zabbix api documentation specifies an array
|
74
|
+
response
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/spec/localhost.rb
CHANGED
@@ -10,7 +10,7 @@ api_password = 'zabbix'
|
|
10
10
|
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
11
11
|
#zbx.debug = true
|
12
12
|
|
13
|
-
describe Zabbix::ZabbixApi, "
|
13
|
+
describe Zabbix::ZabbixApi, "test_api" do
|
14
14
|
|
15
15
|
# 01. Create group
|
16
16
|
it "Create some group" do
|
@@ -104,3 +104,9 @@ describe Zabbix::ZabbixApi, "create_group" do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|
107
|
+
|
108
|
+
describe Zabbix::ZabbixApi, "test_examples" do
|
109
|
+
it "Test all examples" do
|
110
|
+
system("examples/populate_new_zabbix.sh development")
|
111
|
+
end
|
112
|
+
end
|
data/zabbixapi.gemspec
CHANGED
@@ -4,12 +4,12 @@ require 'rake'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
|
7
|
-
spec.version = '0.1.
|
7
|
+
spec.version = '0.1.7'
|
8
8
|
spec.name = 'zabbixapi'
|
9
9
|
spec.summary = 'Ruby module for work with zabbix api.'
|
10
10
|
|
11
11
|
spec.email = 'vadv.mkn@gmail.com'
|
12
|
-
spec.author = 'Eduard Snesarev and Dmitry Vasiliev'
|
12
|
+
spec.author = 'Eduard Snesarev and Dmitry Vasiliev, mathiasmethner@googlemail.com'
|
13
13
|
spec.homepage = 'https://github.com/vadv/zabbixapi/wiki'
|
14
14
|
spec.description = 'Ruby module for work with zabbix api v1.8.'
|
15
15
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbixapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Eduard Snesarev and Dmitry Vasiliev
|
8
|
+
- Eduard Snesarev and Dmitry Vasiliev, mathiasmethner@googlemail.com
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-02 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
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/zabbixapi/group.rb
|
26
26
|
- lib/zabbixapi/host.rb
|
27
27
|
- lib/zabbixapi/item.rb
|
28
|
+
- lib/zabbixapi/maintenance.rb
|
28
29
|
- lib/zabbixapi/mediatype.rb
|
29
30
|
- lib/zabbixapi/screen.rb
|
30
31
|
- lib/zabbixapi/template.rb
|
@@ -32,16 +33,40 @@ files:
|
|
32
33
|
- lib/zabbixapi/user.rb
|
33
34
|
- lib/zabbixapi/usermacro.rb
|
34
35
|
- spec/localhost.rb
|
35
|
-
- spec/request.rb
|
36
36
|
- zabbixapi.gemspec
|
37
37
|
- README.rdoc
|
38
|
+
- examples/basic_auth.rb
|
38
39
|
- examples/config.yml
|
40
|
+
- examples/maintenance-example.rb
|
41
|
+
- examples/populate_new_zabbix.sh
|
39
42
|
- examples/zabbix_availability
|
43
|
+
- examples/zabbix_clear_default
|
44
|
+
- examples/zabbix_cpufan-sersor
|
45
|
+
- examples/zabbix_cputemp-sersor
|
40
46
|
- examples/zabbix_disk_io
|
41
47
|
- examples/zabbix_filesystem
|
48
|
+
- examples/zabbix_group
|
49
|
+
- examples/zabbix_hlsp
|
50
|
+
- examples/zabbix_host
|
51
|
+
- examples/zabbix_iops
|
52
|
+
- examples/zabbix_ipmi-cpufan-sersor
|
53
|
+
- examples/zabbix_ipmi_systemp
|
42
54
|
- examples/zabbix_la
|
55
|
+
- examples/zabbix_mailer
|
56
|
+
- examples/zabbix_mdadm
|
57
|
+
- examples/zabbix_megaraid
|
43
58
|
- examples/zabbix_memory
|
59
|
+
- examples/zabbix_named
|
44
60
|
- examples/zabbix_net
|
61
|
+
- examples/zabbix_nginx
|
62
|
+
- examples/zabbix_nginx_500
|
63
|
+
- examples/zabbix_ntp
|
64
|
+
- examples/zabbix_nv-gputemp
|
65
|
+
- examples/zabbix_pgsql
|
66
|
+
- examples/zabbix_server_process
|
67
|
+
- examples/zabbix_smart_blade
|
68
|
+
- examples/zabbix_ssh
|
69
|
+
- examples/zabbix_varnish
|
45
70
|
homepage: https://github.com/vadv/zabbixapi/wiki
|
46
71
|
licenses: []
|
47
72
|
post_install_message:
|
@@ -67,3 +92,4 @@ signing_key:
|
|
67
92
|
specification_version: 3
|
68
93
|
summary: Ruby module for work with zabbix api.
|
69
94
|
test_files: []
|
95
|
+
has_rdoc: true
|
data/spec/request.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'zabbixapi'
|
2
|
-
require 'json'
|
3
|
-
require 'servers/server18'
|
4
|
-
|
5
|
-
# settings
|
6
|
-
api_url = 'http://somehost'
|
7
|
-
api_login = ''
|
8
|
-
api_password = ''
|
9
|
-
|
10
|
-
|
11
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
12
|
-
#zbx.debug = true
|
13
|
-
|
14
|
-
describe Zabbix::ZabbixApi do
|
15
|
-
|
16
|
-
before :each do
|
17
|
-
# stub auth tocken
|
18
|
-
Zabbix::ZabbixApi.any_instance.stub(:auth).and_return "a9a1f569d10d6339f23c4d122a7f5c46"
|
19
|
-
# stub resquest
|
20
|
-
@request = mock
|
21
|
-
Net::HTTP.any_instance.stub(:request).and_return @request
|
22
|
-
@request.stub(:code).and_return "200"
|
23
|
-
end
|
24
|
-
|
25
|
-
# 01. Create group
|
26
|
-
it "Create some group" do
|
27
|
-
@request.stub(:body).and_return Server18.hostgroup_create
|
28
|
-
result = zbx.add_group('some_group')
|
29
|
-
result.should equal(107819)
|
30
|
-
end
|
31
|
-
|
32
|
-
# 02. Get group_id
|
33
|
-
it "Get group_id" do
|
34
|
-
@request.stub(:body).and_return Server18.hostgroup_get
|
35
|
-
result = zbx.get_group_id('some_group')
|
36
|
-
result.should equal(100100000000002)
|
37
|
-
end
|
38
|
-
|
39
|
-
# 03. Get unknown group_id
|
40
|
-
it "Get unknown group" do
|
41
|
-
@request.stub(:body).and_return Server18.hostgroup_get_error
|
42
|
-
result = zbx.get_group_id('___some_group')
|
43
|
-
result.should be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
# 04. Create host
|
47
|
-
host_options = {
|
48
|
-
"ip" => '127.0.0.1',
|
49
|
-
"dns" => 'my.example.com',
|
50
|
-
"host" => 'my.example.com',
|
51
|
-
"useip" => 1,
|
52
|
-
"groups" => [1]
|
53
|
-
}
|
54
|
-
it "Create host" do
|
55
|
-
@request.stub(:body).and_return Server18.host_create
|
56
|
-
result = zbx.add_host(host_options)
|
57
|
-
result.should equal(107819)
|
58
|
-
end
|
59
|
-
|
60
|
-
# 05. Get host
|
61
|
-
it "Get host by name" do
|
62
|
-
@request.stub(:body).and_return Server18.host_get
|
63
|
-
result = zbx.get_host_id('my.example.com')
|
64
|
-
result.should equal(100100000010017)
|
65
|
-
end
|
66
|
-
|
67
|
-
# 06. Get unknown host
|
68
|
-
it "Get unknown host by name" do
|
69
|
-
@request.stub(:body).and_return Server18.host_get_error
|
70
|
-
result = zbx.get_host_id('___my.example.com')
|
71
|
-
result.should be_nil
|
72
|
-
end
|
73
|
-
|
74
|
-
# 07. Delete host
|
75
|
-
it "Delete host" do
|
76
|
-
@request.stub(:body).and_return Server18.host_delete
|
77
|
-
result = zbx.delete_host('my.example.com')
|
78
|
-
result.should be_kind_of(Integer)
|
79
|
-
end
|
80
|
-
|
81
|
-
# 08. Delete unknown host
|
82
|
-
it "Delete unknown host" do
|
83
|
-
@request.stub(:body).and_return Server18.host_delete_error
|
84
|
-
result = zbx.delete_host('__my.example.com')
|
85
|
-
result.should be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
# 09. Delete group
|
89
|
-
it "Delete some group" do
|
90
|
-
@request.stub(:body).and_return Server18.hostgroup_delete
|
91
|
-
result = zbx.delete_group('some_group')
|
92
|
-
result.should be_kind_of(Integer)
|
93
|
-
end
|
94
|
-
|
95
|
-
# 10. Delete unknown group
|
96
|
-
it "Delete unknown group" do
|
97
|
-
@request.stub(:body).and_return Server18.hostgroup_delete_error
|
98
|
-
result = zbx.delete_group('___some_group')
|
99
|
-
result.should be_nil
|
100
|
-
end
|
101
|
-
|
102
|
-
# 11. Mediatype create
|
103
|
-
mediatype_options = {
|
104
|
-
'type' => '0', #email
|
105
|
-
'description' => 'example_mediatype',
|
106
|
-
'smtp_server' => 'test.company.com',
|
107
|
-
'smtp_helo' => 'test.company.com',
|
108
|
-
'smtp_email' => 'test@test.company.com',
|
109
|
-
}
|
110
|
-
it "Create mediatype" do
|
111
|
-
@request.stub(:body).and_return Server18.mediatype_create
|
112
|
-
result = zbx.add_mediatype(mediatype_options)
|
113
|
-
result.should equal(100100000214797)
|
114
|
-
end
|
115
|
-
|
116
|
-
# 12. Mediatype unknown delete
|
117
|
-
it "Delete unknown mediatype" do
|
118
|
-
@request.stub(:body).and_return Server18.mediatype_delete_error
|
119
|
-
result = zbx.delete_mediatype('__example_mediatype')
|
120
|
-
result.should be_nil
|
121
|
-
end
|
122
|
-
|
123
|
-
# 13. Mediatype delete
|
124
|
-
it "Delete mediatype" do
|
125
|
-
@request.stub(:body).and_return Server18.mediatype_delete
|
126
|
-
result = zbx.delete_mediatype('example_mediatype')
|
127
|
-
result.should be_kind_of(Integer)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|