Sha256: 606d840c6af82e2356f8670a189a99fba90096e8809c7863414826eb4157fe1f

Contents?: true

Size: 1.84 KB

Versions: 5

Compression:

Stored size: 1.84 KB

Contents

require 'httparty'

module ZabbixNudge

  class Jmx

    include HTTParty
    base_uri 'http://localhost:8080'
    format :json

    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

    # http://www.jolokia.org/reference/html/protocol.html#search

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

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

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

    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

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

    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

    private

    def result_key(datum)
      "#{self.class.to_s.demodulize.underscore}[#{datum['request']['mbean']};#{datum['request']['attribute']};#{datum['request']['path']}]"
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zabbix_nudge-0.1.9 lib/zabbix_nudge/jmx.rb
zabbix_nudge-0.1.8 lib/zabbix_nudge/jmx.rb
zabbix_nudge-0.1.7 lib/zabbix_nudge/jmx.rb
zabbix_nudge-0.1.5 lib/zabbix_nudge/jmx.rb
zabbix_nudge-0.1.3 lib/zabbix_nudge/jmx.rb