zabbix-client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/README.md +46 -0
- data/bin/zabbix-cli +72 -0
- data/lib/zabbix/client/version.rb +1 -1
- data/spec/zabbix/client_spec.rb +13 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2850b4e361b71877b617ceba927713e160dafeea
|
4
|
+
data.tar.gz: c1ccbfaa24a5b3b0f3a91861bf64646b18e095db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c6a569a17f90459db1c338de56823a50db15adff98886c9b64555cffb050d2817a4b07fdb4811282e0440830a7f99cf667b5804ac9370688e5edc0e6224913
|
7
|
+
data.tar.gz: 20cf5217e4ca0aa3594fb9517cf0d21593316dde4182ff8519df7bb6b797d7598ccf5e43c370866f319ceed1ed8252b7b06be632d8b1b5f66bed379b34998d7c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,52 @@ Zabbix::Client.new(
|
|
76
76
|
)
|
77
77
|
```
|
78
78
|
|
79
|
+
## CLI
|
80
|
+
|
81
|
+
```sh
|
82
|
+
$ export ZABBIX_URL=http://localhost/zabbix/api_jsonrpc.php
|
83
|
+
$ export ZABBIX_USER=Admin:zabbix
|
84
|
+
$ zabbix-cli -e apiinfo.version
|
85
|
+
2.4.6
|
86
|
+
$ zabbix-cli -e 'template.getobjects(host: ["Template OS Linux"])'
|
87
|
+
[
|
88
|
+
{
|
89
|
+
"proxy_hostid": "0",
|
90
|
+
"host": "Template OS Linux",
|
91
|
+
"status": "3",
|
92
|
+
"disable_until": "0",
|
93
|
+
"error": "",
|
94
|
+
"available": "0",
|
95
|
+
"errors_from": "0",
|
96
|
+
"lastaccess": "0",
|
97
|
+
"ipmi_authtype": "0",
|
98
|
+
"ipmi_privilege": "2",
|
99
|
+
"ipmi_username": "",
|
100
|
+
"ipmi_password": "",
|
101
|
+
"ipmi_disable_until": "0",
|
102
|
+
"ipmi_available": "0",
|
103
|
+
"snmp_disable_until": "0",
|
104
|
+
"snmp_available": "0",
|
105
|
+
"maintenanceid": "0",
|
106
|
+
"maintenance_status": "0",
|
107
|
+
"maintenance_type": "0",
|
108
|
+
"maintenance_from": "0",
|
109
|
+
"ipmi_errors_from": "0",
|
110
|
+
"snmp_errors_from": "0",
|
111
|
+
"ipmi_error": "",
|
112
|
+
"snmp_error": "",
|
113
|
+
"jmx_disable_until": "0",
|
114
|
+
"jmx_available": "0",
|
115
|
+
"jmx_errors_from": "0",
|
116
|
+
"jmx_error": "",
|
117
|
+
"name": "Template OS Linux",
|
118
|
+
"flags": "0",
|
119
|
+
"templateid": "10001",
|
120
|
+
"description": ""
|
121
|
+
}
|
122
|
+
]
|
123
|
+
```
|
124
|
+
|
79
125
|
## Related links
|
80
126
|
|
81
127
|
* [Zabbix 1.8 API reference](https://www.zabbix.com/documentation/1.8/api)
|
data/bin/zabbix-cli
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'zabbix/client'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
Version = Zabbix::Client::VERSION
|
7
|
+
|
8
|
+
def parse_user!(str, options)
|
9
|
+
user, pass = str.split(':', 2)
|
10
|
+
options[:user] = user
|
11
|
+
options[:password] = pass
|
12
|
+
end
|
13
|
+
|
14
|
+
options = {
|
15
|
+
url: ENV['ZABBIX_URL'],
|
16
|
+
options: {}
|
17
|
+
}
|
18
|
+
|
19
|
+
if ENV['ZABBIX_OPTIONS']
|
20
|
+
options[:options] = JSON.parse(ENV['ZABBIX_OPTIONS'])
|
21
|
+
end
|
22
|
+
|
23
|
+
if ENV['ZABBIX_USER']
|
24
|
+
parse_user!(ENV['ZABBIX_USER'], options)
|
25
|
+
end
|
26
|
+
|
27
|
+
ARGV.options do |opt|
|
28
|
+
begin
|
29
|
+
opt.on('-u', '--url URL') {|v| options[:url] = v }
|
30
|
+
opt.on('-o', '--options JSON') {|v| options[:options] = JSON.parse(v) }
|
31
|
+
opt.on('-e', '--execute API') {|v| options[:execute] = v }
|
32
|
+
opt.on('' , '--user USER:PASS') {|v| parse_user!(v, options) }
|
33
|
+
|
34
|
+
opt.on('-h', '--help') do
|
35
|
+
puts opt.help
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
opt.parse!
|
40
|
+
|
41
|
+
unless options[:url] and options[:execute]
|
42
|
+
puts opt.help
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
rescue => e
|
46
|
+
$stderr.puts("[ERROR] #{e.message}")
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
client = Zabbix::Client.new(options[:url], options[:options])
|
53
|
+
|
54
|
+
if options[:user] and options[:password]
|
55
|
+
client.user.login(user: options[:user], password: options[:password])
|
56
|
+
end
|
57
|
+
|
58
|
+
result = client.instance_eval(options[:execute])
|
59
|
+
|
60
|
+
if result.is_a?(Hash) or result.is_a?(Array)
|
61
|
+
puts JSON.pretty_generate(result)
|
62
|
+
else
|
63
|
+
puts result
|
64
|
+
end
|
65
|
+
rescue => e
|
66
|
+
if options[:options]['debug']
|
67
|
+
raise e
|
68
|
+
else
|
69
|
+
$stderr.puts("[ERROR] #{e.message}")
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
end
|
data/spec/zabbix/client_spec.rb
CHANGED
@@ -42,6 +42,19 @@ describe Zabbix::Client do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context "when error happen" do
|
45
|
+
it do
|
46
|
+
handler = proc do |req, res|
|
47
|
+
res.status = 500
|
48
|
+
res.body = JSON.dump(:error => {:code => -1, :message => 'Any Error'})
|
49
|
+
end
|
50
|
+
|
51
|
+
run_client(:handler => handler) do |client|
|
52
|
+
expect {
|
53
|
+
client.item.get(:itemids => [1, 2, 3])
|
54
|
+
}.to raise_error(Zabbix::Client::Error, '{"code"=>-1, "message"=>"Any Error", "method"=>"item.get", "params"=>{:itemids=>[1, 2, 3]}}')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
45
58
|
it do
|
46
59
|
handler = proc do |req, res|
|
47
60
|
res.status = 404
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: This is a simple client of Zabbix API.
|
56
56
|
email:
|
57
57
|
- sgwr_dts@yahoo.co.jp
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- zabbix-cli
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
70
|
+
- bin/zabbix-cli
|
69
71
|
- lib/zabbix/client.rb
|
70
72
|
- lib/zabbix/client/client.rb
|
71
73
|
- lib/zabbix/client/error.rb
|
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
95
|
version: '0'
|
94
96
|
requirements: []
|
95
97
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.0.14.1
|
97
99
|
signing_key:
|
98
100
|
specification_version: 4
|
99
101
|
summary: This is a simple client of Zabbix API.
|