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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ad7955298428f796e35412241a4d1338ae9fa16
4
- data.tar.gz: 180b9d92f9d42baa3f864a5a8113838bc90ec9d3
3
+ metadata.gz: 2850b4e361b71877b617ceba927713e160dafeea
4
+ data.tar.gz: c1ccbfaa24a5b3b0f3a91861bf64646b18e095db
5
5
  SHA512:
6
- metadata.gz: 0810ae905c0b2864fde7081749ad5d54d29f6f6ff9f1ec46c9f863a94fd3b5ae6606f29c19c77620dbc6aec4a4fb7dfb31439c820f99c58899495fb7125cc4af
7
- data.tar.gz: ee5eb325cc555b14566d61ae8d170be17751121bba79a4a5816da939e0bbaef31813e482c8be7576d822775e16a7f3606d62a13b1059186ffa60bd22d19b87a8
6
+ metadata.gz: 12c6a569a17f90459db1c338de56823a50db15adff98886c9b64555cffb050d2817a4b07fdb4811282e0440830a7f99cf667b5804ac9370688e5edc0e6224913
7
+ data.tar.gz: 20cf5217e4ca0aa3594fb9517cf0d21593316dde4182ff8519df7bb6b797d7598ccf5e43c370866f319ceed1ed8252b7b06be632d8b1b5f66bed379b34998d7c
@@ -1,6 +1,13 @@
1
+ sudo: false
1
2
  language: ruby
3
+ cache: bundler
2
4
  rvm:
3
5
  - 2.0.0
6
+ - 2.1.8
7
+ - 2.2.4
8
+ - 2.3.0
9
+ before_install:
10
+ - gem install bundler
4
11
  script:
5
12
  - bundle install
6
13
  - bundle exec rake
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)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Zabbix
2
2
  class Client
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -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.0
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: 2014-09-01 00:00:00.000000000 Z
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.4.1
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.