zenoss_client 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,7 +45,9 @@ It should still be installed in the same fashion as the blog post steps through.
45
45
  == TO USE:
46
46
  A gem is now available. 'gem install zenoss_client'
47
47
 
48
- require 'zenoss'
48
+ <pre>
49
+ <code>
50
+ require 'zenoss'
49
51
  require 'date'
50
52
 
51
53
  server = 'https://zenhost:port/zport/dmd'
@@ -57,11 +59,12 @@ A gem is now available. 'gem install zenoss_client'
57
59
  rrdpts = dev.get_rrd_data_points
58
60
  datapoints = dev.fetch_rrd_value rrdpts.first.name, (DateTime.now - 1)
59
61
 
60
- # Get the uptime of the device
61
- dev.sys_uptime
62
+ # Get the uptime of the device
63
+ dev.sys_uptime
62
64
 
63
65
  # Get a list of events for this system
64
66
  dev.get_events
65
-
67
+ </code>
68
+ </pre>
66
69
 
67
70
  Have fun and let me know what needs to be fixed / added.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -21,6 +21,7 @@ require 'rubygems'
21
21
  require 'date'
22
22
  require 'tzinfo'
23
23
  require 'uri'
24
+ require 'ostruct'
24
25
  require 'httpclient'
25
26
  require 'json'
26
27
 
@@ -35,6 +35,7 @@ module Zenoss
35
35
  @zenoss_uri = (url.is_a?(URI) ? url : URI.parse(url))
36
36
  @request_number = 1
37
37
  @httpcli = HTTPClient.new
38
+ @httpcli.receive_timeout = 360 # six minutes should be more that sufficient
38
39
  sign_in(user,pass)
39
40
  end
40
41
 
@@ -62,7 +62,7 @@ module Zenoss
62
62
  raise ZenossError, "Bad HTTP Response #{resp.status}: Cound not make JSON call"
63
63
  end
64
64
 
65
- json = JSON.load(resp.body.content)
65
+ json = JSON.load(resp.http_body.content)
66
66
  # Check for JSON success. There are some exceptions where this doesn't make sense:
67
67
  # 1. Sometimes the 'success' key does not exist like in EventsRouter#query
68
68
  # 2. When json['result'] is not a Hash like a return from ReportRouter#get_tree
@@ -21,19 +21,34 @@ module Zenoss
21
21
  module JSONAPI
22
22
  module EventsRouter
23
23
 
24
- def get_events(device=nil, component=nil, event_class=nil, limit=100)
25
- data = {
26
- :start => 0,
27
- :limit => 100,
28
- :dir => 'DESC',
29
- :sort => 'severity',
30
- :params => { :severity => [5,4,3,2,1], :eventState => [0,1]},
24
+ # Query events for the given parameters.
25
+ # @param [String] uid the uid to query events for. If this isn't specified
26
+ # the query may take a very long time
27
+ # @param [Hash] opts misc options to limit/filter events
28
+ # @option opts [Fixnum] :limit the Max index of events to retrieve
29
+ # @option opts [Fixnum] :start the Min index of events to retrieve
30
+ # @option opts [String] :sort Key on which to sort the return results (default: 'lastTime')
31
+ # @option opts [String] :dir Sort order; can be either 'ASC' or 'DESC'
32
+ # @option opts [Hash] :params Key-value pair of filters for this search. (default: None)
33
+ # @option opts [Boolean<true>] :history True to search the event history
34
+ # table instead of active events (default: False)
35
+ # @option opts [Array<Hash>] :criteria A list of key-value pairs to to build query's
36
+ # where clause (default: None)
37
+ # @option opts [String] :device limit events to a specific device. This only makes sense
38
+ # if the uid being passed is not a device.
39
+ # @option opts [String] :component limit events to a specific component
40
+ # @option opts [String] :event_class limit events to a specific eventClass
41
+ def query_events(uid=nil, opts = {})
42
+ defaults = {
43
+ :limit => 100,
44
+ :start => 0,
45
+ :sort => 'lastTime',
46
+ :dir => 'DESC',
47
+ :history => false,
31
48
  }
32
- data[:params][:device] = device if device
33
- data[:params][:component] = component if component
34
- data[:params][:eventClass] = event_class if event_class
49
+ opts = defaults.merge(opts)
35
50
 
36
- resp = json_request('EventsRouter', 'query', [data])
51
+ resp = self.ev_query(uid, opts)
37
52
 
38
53
  events = []
39
54
  resp['events'].each do |ev|
@@ -42,6 +57,26 @@ module Zenoss
42
57
  events
43
58
  end
44
59
 
60
+
61
+ # @param [String] uid the uid to query events for. If this isn't specified
62
+ # the query may take a very long time
63
+ # @param [Hash] opts misc options to limit/filter events
64
+ # @see #query_events
65
+ def ev_query(uid, opts)
66
+ data = {
67
+ :limit => opts[:limit],
68
+ :start => opts[:start],
69
+ :sort => opts[:sort],
70
+ :dir => opts[:dir],
71
+ :history => opts[:history],
72
+ }
73
+ data[:uid] = uid unless uid.nil?
74
+ data[:params] = opts[:params] if opts.has_key?(:params)
75
+ data[:criteria] = opts[:criteria] if opts.has_key?(:criteria)
76
+
77
+ json_request('EventsRouter', 'query', [data])
78
+ end
79
+
45
80
  end # EventsRouter
46
81
  end # JSONAPI
47
82
  end # Zenoss
@@ -38,7 +38,11 @@ module Zenoss
38
38
 
39
39
  # Get events for this device
40
40
  def get_events
41
- @zenoss.get_events(self.name)
41
+ @zenoss.query_events(self.uid)
42
+ end
43
+
44
+ def get_event_history
45
+ @zenoss.query_events(self.uid,{:history => true})
42
46
  end
43
47
 
44
48
  def get_info(keys = nil)
@@ -23,16 +23,6 @@ module Zenoss
23
23
 
24
24
  # ------------------ REST Calls ------------------ #
25
25
 
26
- def get_event_history
27
- #rest('getEventHistory')
28
- get_event_manager('history')
29
- end
30
-
31
- def get_event_manager(table='status')
32
- manager = rest("getEventManager?table=#{table}")
33
- Model::Events::MySqlEventManager.new(manager.sub(/.* at (.*)>$/,'\1'))
34
- end
35
-
36
26
  # Fetches that status number for this device or component
37
27
  def get_status(statusclass=nil)
38
28
  method = 'getStatus'
@@ -72,7 +72,7 @@ module Zenoss
72
72
  raise ZenossError, "Bad HTTP Response #{resp.status}: Cound not make REST call"
73
73
  end
74
74
 
75
- resp.body.content
75
+ resp.http_body.content
76
76
  end
77
77
  end
78
78
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
  gem.extra_rdoc_files = %w(README.textile COPYING.txt)
29
29
 
30
30
  gem.required_ruby_version = '>= 1.8.7'
31
- gem.add_runtime_dependency 'httpclient'
32
- gem.add_runtime_dependency 'tzinfo'
33
- gem.add_runtime_dependency 'json'
31
+ gem.add_runtime_dependency 'httpclient', '~> 2.2.0'
32
+ gem.add_runtime_dependency 'tzinfo', '~> 0.3.20'
33
+ gem.add_runtime_dependency 'json', '~> 1.5.0'
34
34
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zenoss_client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Wanek
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-28 00:00:00 -05:00
13
+ date: 2011-05-31 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: "0"
24
+ version: 2.2.0
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
- - - ">="
33
+ - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: "0"
35
+ version: 0.3.20
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -41,9 +41,9 @@ dependencies:
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ">="
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: "0"
46
+ version: 1.5.0
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
49
  description: " This is a wrapper around the Zenoss JSON and REST APIs. For the most things it\n should feel very familiar to zendmd, but there are some changes do to the merging\n of the JSON and REST APIs. Please read the API docs for Zenoss and the YARDDoc for\n this gem (rdoc.info).\n"
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements: []
125
125
 
126
126
  rubyforge_project:
127
- rubygems_version: 1.5.0
127
+ rubygems_version: 1.6.2
128
128
  signing_key:
129
129
  specification_version: 3
130
130
  summary: A wrapper around the Zenoss JSON and REST APIs