Class: Monittr::Server
- Inherits:
-
Object
- Object
- Monittr::Server
- Defined in:
- lib/monittr.rb
Overview
Represents one monitored instance
Instance Attribute Summary collapse
-
#filesystems ⇒ Object
readonly
Returns the value of attribute filesystems.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
-
.fetch(url = 'http://admin:monit@localhost:2812') ⇒ Object
Retrieve Monit status XML from the URL.
Instance Method Summary collapse
-
#initialize(url, xml) ⇒ Server
constructor
A new instance of Server.
- #inspect ⇒ Object
Constructor Details
#initialize(url, xml) ⇒ Server
Returns a new instance of Server.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/monittr.rb', line 28 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
#filesystems ⇒ Object (readonly)
Returns the value of attribute filesystems.
26 27 28 |
# File 'lib/monittr.rb', line 26 def filesystems @filesystems end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
26 27 28 |
# File 'lib/monittr.rb', line 26 def hosts @hosts end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
26 27 28 |
# File 'lib/monittr.rb', line 26 def processes @processes end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
26 27 28 |
# File 'lib/monittr.rb', line 26 def system @system end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
26 27 28 |
# File 'lib/monittr.rb', line 26 def url @url end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
26 27 28 |
# File 'lib/monittr.rb', line 26 def xml @xml end |
Class Method Details
.fetch(url = 'http://admin:monit@localhost:2812') ⇒ Object
Retrieve Monit status XML from the URL
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/monittr.rb', line 48 def self.fetch(url='http://admin:monit@localhost:2812') Timeout::timeout(1) do monit_url = url monit_url += '/' unless url =~ /\/$/ monit_url += '_status?format=xml' unless url =~ /_status\?format=xml$/ self.new url, RestClient.get(monit_url) end rescue Exception => e self.new url, %Q|<error status="3" name="#{e.class}" message="#{e.}" />| end |
Instance Method Details
#inspect ⇒ Object
59 60 61 |
# File 'lib/monittr.rb', line 59 def inspect %Q|<#{self.class} name="#{system.name}" status="#{system.status}" message="#{system.}">| end |