Class: Monittr::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/monittr.rb

Overview

Represents one monitored instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, xml) ⇒ Server

Returns a new instance of Server.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/monittr.rb', line 27

def initialize(url, xml)
  @url = url
  @xml = Nokogiri::XML(xml)
  if error = @xml.xpath('error').first
    @system      = Services::Base.new :name    => error.attributes['name'].content,
                                      :message => error.attributes['message'].content,
                                      :status  => 3
    @filesystems = []
    @processes   = []
    @hosts   = []
  else
    @system      = Services::System.new(@xml.xpath("//service[@type=5]").first)
    @filesystems = @xml.xpath("//service[@type=0]").map { |xml| Services::Filesystem.new(xml) }
    @processes   = @xml.xpath("//service[@type=3]").map { |xml| Services::Process.new(xml) }
    @hosts       = @xml.xpath("//service[@type=4]").map { |xml| Services::Host.new(xml) }
  end
end

Instance Attribute Details

#filesystemsObject (readonly)

Returns the value of attribute filesystems.



25
26
27
# File 'lib/monittr.rb', line 25

def filesystems
  @filesystems
end

#hostsObject (readonly)

Returns the value of attribute hosts.



25
26
27
# File 'lib/monittr.rb', line 25

def hosts
  @hosts
end

#processesObject (readonly)

Returns the value of attribute processes.



25
26
27
# File 'lib/monittr.rb', line 25

def processes
  @processes
end

#systemObject (readonly)

Returns the value of attribute system.



25
26
27
# File 'lib/monittr.rb', line 25

def system
  @system
end

#urlObject (readonly)

Returns the value of attribute url.



25
26
27
# File 'lib/monittr.rb', line 25

def url
  @url
end

#xmlObject (readonly)

Returns the value of attribute xml.



25
26
27
# File 'lib/monittr.rb', line 25

def xml
  @xml
end

Class Method Details

.fetch(url = 'http://admin:monit@localhost:2812') ⇒ Object

Retrieve Monit status XML from the URL



47
48
49
50
51
52
53
54
# File 'lib/monittr.rb', line 47

def self.fetch(url='http://admin:monit@localhost:2812')
  monit_url  = url
  monit_url += '/' unless url =~ /\/$/
  monit_url += '_status?format=xml' unless url =~ /_status\?format=xml$/
  self.new url, RestClient.get(monit_url)
rescue Exception => e
  self.new url, %Q|<error status="3" name="#{e.class}" message="#{e.message}" />|
end

Instance Method Details

#inspectObject



56
57
58
# File 'lib/monittr.rb', line 56

def inspect
  %Q|<#{self.class} name="#{system.name}" status="#{system.status}" message="#{system.message}">|
end