zenvelope 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/zenvelope.rb +72 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4cd210d3c1457e4ded61b4e765c9a83d65630885
|
4
|
+
data.tar.gz: 468f8c8ffcd530fa952446969ec8b0005db2fab3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f159a9a6d0147a604af6470f558a484a9b15cabd379708df817f864ed18a9910d049fc1d247dab32e06212265f0c575510de8db9bbe4165744dbcacd16d012b
|
7
|
+
data.tar.gz: 119771d8c59df4c7299bce51f84c489bab70ba085aab3dc419b357fada383f3a2f2769b5c5115bb9b9ed0a6a1a4628899f234e3fdf665059618094936b9251c3
|
data/lib/zenvelope.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
# API wrapper class
|
5
|
+
class Zenvelope
|
6
|
+
JSON_RPC_VERSION = '2.0'
|
7
|
+
RANDOM_ID_SEED = 100_000
|
8
|
+
VERSION = '0.1.0.pre'
|
9
|
+
|
10
|
+
# Subclass that provides the "action", i.e. the "get" in "host.get"
|
11
|
+
class ZenvelopeAction
|
12
|
+
def initialize(verb, parent)
|
13
|
+
@verb = verb
|
14
|
+
@parent = parent
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(method, *args)
|
18
|
+
@parent.query([@verb, '.', method].join, args.first)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(url = 'http://localhost')
|
23
|
+
@auth = nil
|
24
|
+
@url = url.chomp('/') + '/api_jsonrpc.php'
|
25
|
+
end
|
26
|
+
|
27
|
+
def login(creds = { user: 'Admin', password: 'zabbix' })
|
28
|
+
@auth = query('user.login', creds)
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(method)
|
32
|
+
instance_variable_set('@' + method.to_s, ZenvelopeAction.new(method, self))
|
33
|
+
instance_variable_get('@' + method.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def query(method, parameters)
|
37
|
+
payload = { id: rand(RANDOM_ID_SEED), jsonrpc: JSON_RPC_VERSION,
|
38
|
+
method: method, params: parameters
|
39
|
+
}
|
40
|
+
|
41
|
+
payload[:auth] = @auth unless method.include? 'apiinfo'
|
42
|
+
|
43
|
+
begin
|
44
|
+
response = JSON.parse(request(payload), symbolize_names: true)
|
45
|
+
rescue
|
46
|
+
response = {
|
47
|
+
error: {
|
48
|
+
message: 'Unable to parse JSON response',
|
49
|
+
data: "Please check that the path #{@url} is correct."
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
if response.key? :error
|
55
|
+
response
|
56
|
+
else
|
57
|
+
response[:result]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def request(payload)
|
64
|
+
conn = Faraday.new(url: @url) do |faraday|
|
65
|
+
faraday.adapter :net_http_persistent
|
66
|
+
faraday.headers['Content-Type'] = 'application/json'
|
67
|
+
faraday.headers['User-Agent'] = "Zenvelope #{VERSION}"
|
68
|
+
end
|
69
|
+
|
70
|
+
conn.post { |req| req.body = payload.to_json }.body
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zenvelope
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nickolai
|
8
|
+
- Barnum
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.9'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: net-http-persistent
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.9'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.9'
|
42
|
+
description: A simple Ruby API wrapper for Zabbix server
|
43
|
+
email: nbarnum@users.noreply.github.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/zenvelope.rb
|
49
|
+
homepage: https://github.com/nbarnum/zenvelope
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.9.3
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.3.1
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.4.8
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Simple Zabbix API wrapper
|
73
|
+
test_files: []
|