iteh-zabbixapi 0.2.2

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.
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Zabbix
19
+ VERSION = "0.2.2"
20
+ end
data/lib/zabbixapi.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'zabbixapi/base'
2
+ require 'zabbixapi/graph'
3
+ require 'zabbixapi/group'
4
+ require 'zabbixapi/host'
5
+ require 'zabbixapi/item'
6
+ require 'zabbixapi/screen'
7
+ require 'zabbixapi/template'
8
+ require 'zabbixapi/trigger'
9
+ require 'zabbixapi/usermacro'
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ X-powered-by: PHP/5.3.3
3
+ Connection: close
4
+ Content-type: application/json
5
+ Date: Thu, 23 Jun 2011 19:34:59 GMT
6
+ Server: Apache/2.2.15 (Linux/SUSE)
7
+ Content-length: 125
8
+
9
+ {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"Login name or password is incorrect"},"id":11219}
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ X-powered-by: PHP/5.3.3
3
+ Connection: close
4
+ Content-type: application/json
5
+ Date: Thu, 23 Jun 2011 20:17:10 GMT
6
+ Server: Apache/2.2.15 (Linux/SUSE)
7
+ Content-length: 58
8
+
9
+ {"jsonrpc":"2.0","result":[{"hostid":"10052"}],"id":21226}
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ X-powered-by: PHP/5.3.3
3
+ Connection: close
4
+ Content-type: application/json
5
+ Date: Thu, 23 Jun 2011 20:26:38 GMT
6
+ Server: Apache/2.2.15 (Linux/SUSE)
7
+ Content-length: 40
8
+
9
+ {"jsonrpc":"2.0","result":[],"id":68399}
@@ -0,0 +1,10 @@
1
+ HTTP/1.1 200 OK
2
+ X-powered-by: PHP/5.3.3
3
+ Connection: close
4
+ Content-type: application/json
5
+ Date: Thu, 23 Jun 2011 19:30:57 GMT
6
+ Server: Apache/2.2.15 (Linux/SUSE)
7
+ Content-length: 72
8
+ Set-cookie: zbx_sessionid=9f1404eb20c67cb91eb5edd44973d963zbx_sessionid=15de32a5993270961e6265421566357ezbx_sessionid=deleted; expires=Wed, 23-Jun-2010 19:30:56 GMT
9
+
10
+ {"jsonrpc":"2.0","result":"9f1404eb20c67cb91eb5edd44973d963","id":31113}
@@ -0,0 +1,90 @@
1
+ # from http://kalv.co.uk/2009/10/13/saving-http-requests-for-testing/
2
+ # Record HTTP is to help recording the http calls for further testing
3
+ #
4
+ # usage:
5
+ # require 'record_http'
6
+ # set up the directory it needs to save the responses
7
+ # RecordHttp.save_path = '../spec/data'
8
+ # RecordHttp.include_headers = true
9
+ # RecordHttp.file_prefix = 'http_'
10
+ #
11
+ # Run your net http requests, tests, gems that use net/http and watch everything save away!
12
+ # Net::HTTP.get(URI.parse("http://localhost"))
13
+ require 'net/http'
14
+
15
+ module RecordHttp
16
+
17
+ @@save_path = nil
18
+ @@include_headers = false
19
+ @@file_prefix = "http_"
20
+ @@perform_save = true
21
+
22
+ def self.save_path
23
+ @@save_path
24
+ end
25
+
26
+ def self.perform_save=(value)
27
+ @@perform_save = value
28
+ end
29
+
30
+ def self.perform_save
31
+ @@perform_save
32
+ end
33
+
34
+ def self.save_path=(save_path)
35
+ @@save_path = save_path
36
+ end
37
+
38
+ def self.include_headers=(include_headers)
39
+ @@include_headers = include_headers
40
+ end
41
+
42
+ def self.file_prefix=(file_prefix)
43
+ @@file_prefix = file_prefix
44
+ end
45
+
46
+ def self.save_res(address,req,res)
47
+ pathname = req.path.gsub("/","_")
48
+ method = JSON.parse(req.body)["method"]
49
+ #filename = @@save_path+"/"+@@file_prefix + address + (pathname ? pathname: "") + "_" + method
50
+ filename = @@save_path+"/"+@@file_prefix + "_" + method + ".txt"
51
+ File.open(filename,"w") do |file|
52
+ if @@include_headers
53
+ file.write("HTTP/#{res.http_version} #{res.code} #{res.message}\n")
54
+ res.to_hash.each do |key,value|
55
+ file.write("#{key.capitalize}: #{value}\n")
56
+ end
57
+ file.write("\n")
58
+ end
59
+ file.write(res.body)
60
+ end
61
+ puts "Saved file #{filename} with response from http://#{address}#{req.path}"
62
+ end
63
+
64
+ end
65
+
66
+ # set save path
67
+ RecordHttp.save_path = '../spec/data'
68
+ RecordHttp.include_headers = false
69
+ RecordHttp.file_prefix = 'http_'
70
+
71
+ # override Net::Http at request level to get post / get / put / etc
72
+ module Net
73
+ class HTTP
74
+ alias :old_request :request
75
+
76
+ def request(req, body = nil, &block)
77
+ res = old_request(req, body, &block)
78
+ begin
79
+ RecordHttp.save_res(@address,req,res) if RecordHttp.perform_save == true
80
+ rescue
81
+ puts "Error saving response #{$!}"
82
+ end
83
+ res
84
+ end
85
+
86
+ end
87
+ end
88
+
89
+ # Just run Net::Http
90
+ #puts Net::HTTP.get(URI.parse("http://localhost"))
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+
21
+ $: << File.join(File.dirname(__FILE__), "/../lib")
22
+
23
+ require 'zabbixapi'
24
+ require 'fakeweb'
25
+ require 'record_http'
26
+
27
+ RecordHttp.save_path = File.join(File.dirname(__FILE__),'/fixtures')
28
+ RecordHttp.include_headers = true
29
+ RecordHttp.file_prefix = 'http_'
30
+
31
+ #FakeWeb.allow_net_connect = false
32
+
33
+ def fixture_file(filename)
34
+ return '' if filename == ''
35
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
36
+ File.read(file_path)
37
+ end
38
+
39
+ def store_to_fixture_file(filename)
40
+
41
+ end
@@ -0,0 +1,97 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require File.join(File.dirname(__FILE__), "/spec_helper")
21
+ require 'ap'
22
+
23
+ describe Zabbix::ZabbixApi do
24
+
25
+ before(:each) do
26
+ @api_url = "http://192.168.1.29/zabbix/api_jsonrpc.php"
27
+ @api_login = "api_user"
28
+ @api_password = "api_user"
29
+ end
30
+
31
+ context 'Initialization' do
32
+
33
+ FakeWeb.register_uri(:post, "http://192.168.1.29/login_success_user.authenticate.txt", :response => fixture_file("login_success_user.authenticate.txt"))
34
+ FakeWeb.register_uri(:post, "http://192.168.1.29/failed_auth_wrong_password_user.authenticate.txt", :response => fixture_file("failed_auth_wrong_password_user.authenticate.txt"))
35
+
36
+ it 'should login with correct data' do
37
+ RecordHttp.file_prefix = 'login_success'
38
+ RecordHttp.perform_save = false
39
+ FakeWeb.allow_net_connect = false
40
+
41
+ @api_url = "http://192.168.1.29/login_success_user.authenticate.txt"
42
+ zbx = Zabbix::ZabbixApi.new(@api_url, @api_login, @api_password)
43
+ zbx.auth.should_not be_nil
44
+ end
45
+
46
+ it 'should no login with wrong data' do
47
+ RecordHttp.file_prefix = 'failed_auth_wrong_password'
48
+ RecordHttp.perform_save = false
49
+ FakeWeb.allow_net_connect = false
50
+
51
+ @api_url = "http://192.168.1.29/failed_auth_wrong_password_user.authenticate.txt"
52
+ @api_login = "wrong_user"
53
+ zbx = Zabbix::ZabbixApi.new(@api_url, @api_login, @api_password)
54
+ lambda { zbx.auth}.should raise_error(Zabbix::AuthError)
55
+ end
56
+
57
+ end
58
+
59
+ context 'get host' do
60
+
61
+ FakeWeb.register_uri(:post, "http://192.168.1.29/get_existing_host_host.get.txt",
62
+ [:response => fixture_file("login_success_user.authenticate.txt"),
63
+ :response => fixture_file("get_existing_host_host.get.txt")])
64
+ FakeWeb.register_uri(:post, "http://192.168.1.29/get_nil_for_unknown_host_host.get.txt",
65
+ [:response => fixture_file("login_success_user.authenticate.txt"),
66
+ :response => fixture_file("get_nil_for_unknown_host_host.get.txt")])
67
+
68
+ it "should get the host" do
69
+ api_url = "http://192.168.1.29/get_existing_host_host.get.txt"
70
+ zbx = Zabbix::ZabbixApi.new(api_url, @api_login, @api_password)
71
+
72
+ RecordHttp.file_prefix = 'get_existing_host'
73
+ RecordHttp.perform_save = false
74
+
75
+ FakeWeb.allow_net_connect = false
76
+
77
+ host = zbx.get_host({"filter" => {"dns" => "vagrantup.com"}})
78
+ host.should_not be_nil
79
+ end
80
+
81
+ it "should not get a unknown host" do
82
+
83
+ api_url = "http://192.168.1.29/get_nil_for_unknown_host_host.get.txt"
84
+ zbx = Zabbix::ZabbixApi.new(api_url, @api_login, @api_password)
85
+
86
+ RecordHttp.file_prefix = 'get_nil_for_unknown_host'
87
+ RecordHttp.perform_save = false
88
+
89
+ FakeWeb.allow_net_connect = false
90
+
91
+ host = zbx.get_host({"filter" => {"dns" => "no-host.com"}})
92
+ host.should be_nil
93
+ end
94
+
95
+ end
96
+
97
+ end
data/zabbixapi.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "zabbixapi/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "iteh-zabbixapi"
8
+ s.version = Zabbix::VERSION
9
+ s.authors = ['Eduard Snesarev',"Edmund Haselwanter"]
10
+ s.email = ['verm666@gmail.com',"edmund@haselwanter.com"]
11
+ s.homepage = "https://github.com/iteh/zabbixapi"
12
+ s.license = 'Apache'
13
+ s.has_rdoc = true
14
+ s.extra_rdoc_files = 'README.rdoc'
15
+
16
+ s.summary = %q{Ruby module for work with zabbix api.}
17
+ s.description = %q{Ruby module for work with zabbix api.}
18
+
19
+ s.rubyforge_project = "zabbixapi"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+
26
+ # s.add_dependency 'nokogiri', '~> 1.4.4'
27
+ # s.add_dependency 'zabbix', '~> 0.3.0'
28
+ # s.add_dependency 'httparty', '~> 0.7.8'
29
+ # s.add_dependency 'activesupport', '~> 3.0.8'
30
+ # s.add_dependency "i18n", "~> 0.6.0"
31
+ # s.add_dependency 'yajl-ruby', '~> 0.8.2'
32
+ s.add_dependency "json", ">= 1.4.4", "<= 1.5.2"
33
+ s.add_dependency "awesome_print", "~> 0.4.0"
34
+ # s.add_dependency "mixlib-cli", "~> 1.2.0"
35
+
36
+ s.add_development_dependency 'rspec', '~> 2.6.0'
37
+ s.add_development_dependency 'fakeweb', '~> 1.3.0'
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iteh-zabbixapi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 2
10
+ version: 0.2.2
11
+ platform: ruby
12
+ authors:
13
+ - Eduard Snesarev
14
+ - Edmund Haselwanter
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-24 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: json
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 1
33
+ - 4
34
+ - 4
35
+ version: 1.4.4
36
+ - - <=
37
+ - !ruby/object:Gem::Version
38
+ hash: 7
39
+ segments:
40
+ - 1
41
+ - 5
42
+ - 2
43
+ version: 1.5.2
44
+ type: :runtime
45
+ version_requirements: *id001
46
+ - !ruby/object:Gem::Dependency
47
+ name: awesome_print
48
+ prerelease: false
49
+ requirement: &id002 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ hash: 15
55
+ segments:
56
+ - 0
57
+ - 4
58
+ - 0
59
+ version: 0.4.0
60
+ type: :runtime
61
+ version_requirements: *id002
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ prerelease: false
65
+ requirement: &id003 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 23
71
+ segments:
72
+ - 2
73
+ - 6
74
+ - 0
75
+ version: 2.6.0
76
+ type: :development
77
+ version_requirements: *id003
78
+ - !ruby/object:Gem::Dependency
79
+ name: fakeweb
80
+ prerelease: false
81
+ requirement: &id004 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ hash: 27
87
+ segments:
88
+ - 1
89
+ - 3
90
+ - 0
91
+ version: 1.3.0
92
+ type: :development
93
+ version_requirements: *id004
94
+ description: Ruby module for work with zabbix api.
95
+ email:
96
+ - verm666@gmail.com
97
+ - edmund@haselwanter.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - README.rdoc
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.rdoc
109
+ - Rakefile
110
+ - examples/config.yml
111
+ - examples/zabbix_availability
112
+ - examples/zabbix_disk_io
113
+ - examples/zabbix_filesystem
114
+ - examples/zabbix_la
115
+ - examples/zabbix_memory
116
+ - examples/zabbix_net
117
+ - lib/zabbixapi.rb
118
+ - lib/zabbixapi/application.rb
119
+ - lib/zabbixapi/base.rb
120
+ - lib/zabbixapi/graph.rb
121
+ - lib/zabbixapi/group.rb
122
+ - lib/zabbixapi/host.rb
123
+ - lib/zabbixapi/item.rb
124
+ - lib/zabbixapi/screen.rb
125
+ - lib/zabbixapi/template.rb
126
+ - lib/zabbixapi/trigger.rb
127
+ - lib/zabbixapi/usermacro.rb
128
+ - lib/zabbixapi/version.rb
129
+ - spec/fixtures/failed_auth_wrong_password_user.authenticate.txt
130
+ - spec/fixtures/get_existing_host_host.get.txt
131
+ - spec/fixtures/get_nil_for_unknown_host_host.get.txt
132
+ - spec/fixtures/login_success_user.authenticate.txt
133
+ - spec/record_http.rb
134
+ - spec/spec_helper.rb
135
+ - spec/zabbixapi_spec.rb
136
+ - zabbixapi.gemspec
137
+ has_rdoc: true
138
+ homepage: https://github.com/iteh/zabbixapi
139
+ licenses:
140
+ - Apache
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project: zabbixapi
167
+ rubygems_version: 1.3.7
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Ruby module for work with zabbix api.
171
+ test_files:
172
+ - spec/fixtures/failed_auth_wrong_password_user.authenticate.txt
173
+ - spec/fixtures/get_existing_host_host.get.txt
174
+ - spec/fixtures/get_nil_for_unknown_host_host.get.txt
175
+ - spec/fixtures/login_success_user.authenticate.txt
176
+ - spec/record_http.rb
177
+ - spec/spec_helper.rb
178
+ - spec/zabbixapi_spec.rb