zabbixapi 0.1.1 → 0.1.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,29 @@
1
+ require 'base'
2
+
3
+ module Zabbix
4
+ class ZabbixApi
5
+ def add_application(app_options)
6
+
7
+ app_options_default = {
8
+ 'hostid' => nil,
9
+ 'name' => nil
10
+ }
11
+
12
+ application = merge_opt(app_options_default, app_options)
13
+ message = {
14
+ 'method' => 'application.create',
15
+ 'params' => application
16
+ }
17
+
18
+ responce = send_request(message)
19
+
20
+ if not ( responce.empty? ) then
21
+ result = responce['applicationids'][0].to_i
22
+ else
23
+ result = nil
24
+ end
25
+
26
+ return result
27
+ end
28
+ end
29
+ end
data/lib/base.rb CHANGED
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'net/http'
5
5
  require 'net/https'
6
6
 
7
- module ZabbixApi
7
+ module Zabbix
8
8
 
9
9
  class JsonMessage < RuntimeError
10
10
  end
@@ -21,6 +21,8 @@ module ZabbixApi
21
21
  class Error < RuntimeError
22
22
  end
23
23
 
24
+ class ZabbixApi
25
+
24
26
  def initialize ( api_url, api_user, api_password )
25
27
  @api_url = api_url
26
28
  @api_user = api_user
@@ -36,6 +38,8 @@ module ZabbixApi
36
38
 
37
39
  message_json = JSON.generate(message)
38
40
 
41
+ # puts message.inspect
42
+
39
43
  uri = URI.parse(@api_url)
40
44
  http = Net::HTTP.new(uri.host, uri.port)
41
45
 
@@ -63,6 +67,9 @@ module ZabbixApi
63
67
 
64
68
 
65
69
  # Check errors in zabbix answer. If error exist - raise exception Zabbix::Error
70
+
71
+ # puts responce_body_hash.inspect
72
+
66
73
  if ( error = responce_body_hash['error'] ) then
67
74
  error_message = error['message']
68
75
  error_data = error['data']
@@ -115,5 +122,5 @@ module ZabbixApi
115
122
 
116
123
  return a.merge(c)
117
124
  end
118
-
125
+ end
119
126
  end
data/lib/graph.rb CHANGED
@@ -1,55 +1,68 @@
1
1
  module Zabbix
2
- class ZabbixApi
3
-
4
- def get_graph_id(host_id, graph_name)
5
-
6
- message = {
7
- 'method' => 'graph.get',
8
- 'params' => {
9
- 'filter' => {
10
- 'name' => graph_name,
11
- 'hostid' => host_id
12
- }
13
- }
14
- }
15
-
16
- responce = send_request(message)
17
-
18
- unless ( responce.empty? ) then
19
- result = responce[0]['graphid']
20
- else
21
- result = nil
22
- end
23
- end
24
-
25
- def get_graphs(host_id)
26
-
27
- message = {
28
- 'method' => 'graph.get',
29
- 'params' => {
30
- 'extendoutput' => '1',
31
- 'filter' => {
32
- 'hostid' => host_id
33
- }
34
- }
35
- }
36
-
37
- responce = send_request(message)
38
-
39
- unless ( responce.empty? ) then
40
- result = {}
41
-
42
- responce.each() do |graph|
43
- graph_id = graph['graphid']
44
- graph_name = graph['name']
45
-
46
- result[graph_id] = graph_name
47
- end
48
- else
49
- result = nil
50
- end
51
-
52
- return result
53
- end
54
- end
2
+ class ZabbixApi
3
+
4
+ def add_graph(graph)
5
+ message = {
6
+ 'method' => 'graph.create',
7
+ 'params' => graph
8
+ }
9
+
10
+ responce = send_request(message)
11
+
12
+ puts "DEBUG: #{responce.inspect}"
13
+
14
+ return 0
15
+ end
16
+
17
+ def get_graph_id(host_id, graph_name)
18
+
19
+ message = {
20
+ 'method' => 'graph.get',
21
+ 'params' => {
22
+ 'filter' => {
23
+ 'name' => graph_name,
24
+ 'hostid' => host_id
25
+ }
26
+ }
27
+ }
28
+
29
+ responce = send_request(message)
30
+
31
+ unless ( responce.empty? ) then
32
+ result = responce[0]['graphid']
33
+ else
34
+ result = nil
35
+ end
36
+ end
37
+
38
+ def get_graphs(host_id)
39
+
40
+ message = {
41
+ 'method' => 'graph.get',
42
+ 'params' => {
43
+ 'extendoutput' => '1',
44
+ 'filter' => {
45
+ 'hostid' => host_id
46
+ }
47
+ }
48
+ }
49
+
50
+ responce = send_request(message)
51
+
52
+ unless ( responce.empty? ) then
53
+ result = {}
54
+
55
+ responce.each() do |graph|
56
+ graph_id = graph['graphid']
57
+ graph_name = graph['name']
58
+
59
+ result[graph_id] = graph_name
60
+ end
61
+ else
62
+ result = nil
63
+ end
64
+
65
+ return result
66
+ end
67
+ end
55
68
  end
data/lib/host.rb CHANGED
@@ -27,6 +27,7 @@ module Zabbix
27
27
  # - ipmi_privilege - Default: 0;
28
28
  # - ipmi_username - Default: '';
29
29
  # - ipmi_password - Default: '';
30
+ class ZabbixApi
30
31
  def add_host(host_options)
31
32
 
32
33
  host_default = {
@@ -93,4 +94,5 @@ module Zabbix
93
94
 
94
95
  return result
95
96
  end
97
+ end
96
98
  end
data/lib/item.rb CHANGED
@@ -4,7 +4,7 @@ module Zabbix
4
4
 
5
5
  item_options = {
6
6
  'description' => nil,
7
- 'key_' => nil,
7
+ 'key_' => nil,
8
8
  'hostid' => nil,
9
9
  'delay' => 60,
10
10
  'history' => 60,
@@ -47,6 +47,7 @@ module Zabbix
47
47
  'params' => [ item_options ]
48
48
  }
49
49
 
50
+
50
51
  responce = send_request(message)
51
52
 
52
53
  unless ( responce.empty? ) then
data/lib/trigger.rb CHANGED
@@ -8,15 +8,19 @@ module Zabbix
8
8
  'params' => [ trigger ]
9
9
  }
10
10
 
11
+
11
12
  responce = send_request(message)
12
13
 
14
+
13
15
  unless ( responce.empty? ) then
14
16
  result = responce['triggerids'][0]
15
17
  else
16
18
  result = nil
17
19
  end
18
20
 
21
+
19
22
  return result
23
+
20
24
  end
21
25
 
22
26
  def get_trigger_id(host_id, trigger_name)
data/lib/zabbixapi.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'base'
2
- require 'graph'
3
- require 'group'
4
- require 'host'
5
- require 'item'
6
- require 'screen'
7
- require 'template'
8
- require 'trigger'
9
- require 'usermacro'
1
+ require './base'
2
+ require './graph'
3
+ require './group'
4
+ require './host'
5
+ require './item'
6
+ require './screen'
7
+ require './template'
8
+ require './trigger'
9
+ require './usermacro'
data/zabbixapi.gemspec CHANGED
@@ -4,13 +4,13 @@ require 'echoe'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
 
7
- spec.version = '0.1.1'
7
+ spec.version = '0.1.2'
8
8
  spec.name = 'zabbixapi'
9
9
  spec.summary = 'Ruby module for work with zabbix api.'
10
10
 
11
11
  spec.email = 'verm666@gmail.com'
12
12
  spec.author = 'Eduard Snesarev'
13
- spec.homepage = 'http://github.com/verm666/zabbixapi'
13
+ spec.homepage = 'http://github.com/verm666/RubyZabbixApi'
14
14
  spec.description = 'Ruby module for work with zabbix api. '
15
15
 
16
16
  spec.has_rdoc = true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eduard Snesarev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 +04:00
18
+ date: 2011-03-28 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,21 +28,21 @@ extensions: []
28
28
  extra_rdoc_files:
29
29
  - README.rdoc
30
30
  files:
31
- - lib/trigger.rb
32
- - lib/screen.rb
33
- - lib/1.rb
31
+ - lib/application.rb
32
+ - lib/base.rb
33
+ - lib/graph.rb
34
+ - lib/group.rb
34
35
  - lib/host.rb
35
- - lib/usermacro.rb
36
- - lib/template.rb
37
36
  - lib/item.rb
37
+ - lib/screen.rb
38
+ - lib/template.rb
39
+ - lib/trigger.rb
40
+ - lib/usermacro.rb
38
41
  - lib/zabbixapi.rb
39
- - lib/base.rb
40
- - lib/group.rb
41
- - lib/graph.rb
42
42
  - zabbixapi.gemspec
43
43
  - README.rdoc
44
44
  has_rdoc: true
45
- homepage: http://github.com/verm666/zabbixapi
45
+ homepage: http://github.com/verm666/RubyZabbixApi
46
46
  licenses: []
47
47
 
48
48
  post_install_message:
data/lib/1.rb DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'rubygems'
4
- require './base'
5
- require './host'
6
-
7
-
8
- zbx = ZabbixApi.new('', '', '')