Class: ZabbixPusher::Jmx

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/zabbix_pusher/jmx.rb

Instance Method Summary collapse

Constructor Details

#initialize(items = [], options = {}) ⇒ Jmx

Returns a new instance of Jmx.



28
29
30
31
32
33
34
35
36
37
# File 'lib/zabbix_pusher/jmx.rb', line 28

def initialize(items=[] ,options={})
  self.class.base_uri options[:base_uri] if options[:base_uri]
  @payload = Array.new
  @items = items
  @items.each do |item|  mbean,attribute,path = item.split(';')
    tokens = { "mbean" => mbean, "attribute" => attribute, "type" => "READ"}
    tokens["path"] = path if path
    @payload  << tokens
  end
end

Instance Method Details

#list(path, config = {}) ⇒ Object

www.jolokia.org/reference/html/protocol.html#list use options = { “maxDepth” => 2} to limit depth



48
49
50
# File 'lib/zabbix_pusher/jmx.rb', line 48

def list(path,config={})
  self.class.post('/jolokia', :body => { "type" => "LIST", "path" => path, "config" => config}.to_json)
end

#processed_itemsObject



64
65
66
67
68
69
# File 'lib/zabbix_pusher/jmx.rb', line 64

def processed_items
  data = self.class.post('/jolokia', :body => @payload.to_json, :timeout => 5) rescue nil
  result = Hash.new
  data.each{|datum| result[result_key(datum)] = datum['value'] if datum['request']} if data
  result
end

#read(mbean, attribute, path = nil, config = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/zabbix_pusher/jmx.rb', line 52

def read(mbean,attribute,path=nil,config={})
  payload = { "type" => "READ", "mbean" => mbean, "attribute" => attribute}
  payload["path"] = path if path
  payload["config"] = config if config.length > 0
  ap payload.to_json
  self.class.post('/jolokia', :body => payload.to_json, :timeout => 5)
end

#search(mbean, config = {}) ⇒ Object



41
42
43
# File 'lib/zabbix_pusher/jmx.rb', line 41

def search(mbean,config={})
  self.class.post('/jolokia', :body => { "type" => "SEARCH", "mbean" => mbean, "config" => config}.to_json)
end

#versionObject



60
61
62
# File 'lib/zabbix_pusher/jmx.rb', line 60

def version
  self.class.post('/jolokia', :body => { "type" => "VERSION"}.to_json)
end