monit 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -0
 - data/lib/monit/httpd.rb +3 -3
 - data/lib/monit/platform.rb +1 -1
 - data/lib/monit/server.rb +13 -13
 - data/lib/monit/service.rb +11 -28
 - data/lib/monit/status.rb +14 -13
 - data/lib/monit/version.rb +1 -1
 - data/spec/monit_spec.rb +45 -45
 - metadata +3 -13
 - data/lib/monit/status/httpd.rb +0 -12
 - data/lib/monit/status/platform.rb +0 -15
 - data/lib/monit/status/server.rb +0 -18
 - data/lib/monit/status/service.rb +0 -79
 
    
        data/Rakefile
    CHANGED
    
    
    
        data/lib/monit/httpd.rb
    CHANGED
    
    | 
         @@ -2,11 +2,11 @@ module Monit 
     | 
|
| 
       2 
2 
     | 
    
         
             
              # The HTTPD section from the Monit XML
         
     | 
| 
       3 
3 
     | 
    
         
             
              class HTTPD
         
     | 
| 
       4 
4 
     | 
    
         
             
                attr_reader :address, :port, :ssl
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       6 
6 
     | 
    
         
             
                def initialize(options = {})
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @address = options["address"]
         
     | 
| 
       8 
     | 
    
         
            -
                  @port 
     | 
| 
       9 
     | 
    
         
            -
                  @ssl 
     | 
| 
      
 8 
     | 
    
         
            +
                  @port    = options["port"]
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @ssl     = options["ssl"] == "1" ? true : false
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         
             
            end
         
     | 
    
        data/lib/monit/platform.rb
    CHANGED
    
    
    
        data/lib/monit/server.rb
    CHANGED
    
    | 
         @@ -1,18 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Monit
         
     | 
| 
       2 
2 
     | 
    
         
             
              # The server section from the Monit XML
         
     | 
| 
       3 
3 
     | 
    
         
             
              class Server
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
                attr_reader :id, :incarnation, :version, :uptime, :poll, :startdelay, :localhostname, :controlfile, :httpd
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize(options = {})
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @id = options["id"]
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @incarnation = options["incarnation"]
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @version = options["version"]
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @uptime = options["uptime"].to_i
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @poll = options["poll"].to_i
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @startdelay = options["startdelay"].to_i
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @localhostname = options["localhostname"]
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @controlfile = options["controlfile"]
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @httpd = options["httpd"].is_a?(HTTPD) ? options["httpd"] : HTTPD.new(options["httpd"])
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         
             
            end
         
     | 
    
        data/lib/monit/service.rb
    CHANGED
    
    | 
         @@ -5,10 +5,10 @@ module Monit 
     | 
|
| 
       5 
5 
     | 
    
         
             
                TYPES = { 0 => "Filesystem", 1 => "Directory", 2 => "File", 3 => "Daemon", 4 => "Connection", 5 => "System" }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                def initialize(hash = nil, options = {})
         
     | 
| 
       8 
     | 
    
         
            -
                  @host 
     | 
| 
       9 
     | 
    
         
            -
                  @port 
     | 
| 
       10 
     | 
    
         
            -
                  @ssl 
     | 
| 
       11 
     | 
    
         
            -
                  @auth 
     | 
| 
      
 8 
     | 
    
         
            +
                  @host     ||= options[:host] || "localhost"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @port     ||= options[:port] || 2812
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @ssl      ||= options[:ssl]  || false
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @auth     ||= options[:auth] || false
         
     | 
| 
       12 
12 
     | 
    
         
             
                  @username = options[:username]
         
     | 
| 
       13 
13 
     | 
    
         
             
                  @password = options[:password]
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -21,24 +21,10 @@ module Monit 
     | 
|
| 
       21 
21 
     | 
    
         
             
                  @ssl ? URI::HTTPS.build(url_params) : URI::HTTP.build(url_params)
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                def stop!
         
     | 
| 
       29 
     | 
    
         
            -
                  self.do :stop
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                def restart!
         
     | 
| 
       33 
     | 
    
         
            -
                  self.do :restart
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                def monitor!
         
     | 
| 
       37 
     | 
    
         
            -
                  self.do :monitor
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                def unmonitor!
         
     | 
| 
       41 
     | 
    
         
            -
                  self.do :unmonitor
         
     | 
| 
      
 24 
     | 
    
         
            +
                [:start, :stop, :restart, :monitor, :unmonitor].each do |action|
         
     | 
| 
      
 25 
     | 
    
         
            +
                  define_method "#{action}!" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    self.do action
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
       42 
28 
     | 
    
         
             
                end
         
     | 
| 
       43 
29 
     | 
    
         | 
| 
       44 
30 
     | 
    
         
             
                def do(action)
         
     | 
| 
         @@ -46,17 +32,14 @@ module Monit 
     | 
|
| 
       46 
32 
     | 
    
         
             
                  http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
       47 
33 
     | 
    
         | 
| 
       48 
34 
     | 
    
         
             
                  if @ssl
         
     | 
| 
       49 
     | 
    
         
            -
                    http.use_ssl 
     | 
| 
      
 35 
     | 
    
         
            +
                    http.use_ssl     = true
         
     | 
| 
       50 
36 
     | 
    
         
             
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       51 
37 
     | 
    
         
             
                  end
         
     | 
| 
       52 
38 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                  request 
     | 
| 
      
 39 
     | 
    
         
            +
                  request      = Net::HTTP::Post.new(uri.request_uri)
         
     | 
| 
       54 
40 
     | 
    
         
             
                  request.body = "action=#{action}"
         
     | 
| 
       55 
41 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                  if @auth
         
     | 
| 
       57 
     | 
    
         
            -
                    request.basic_auth(@username, @password)
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                  request.basic_auth(@username, @password) if @auth
         
     | 
| 
       60 
43 
     | 
    
         
             
                  request["User-Agent"] = "Monit Ruby client #{Monit::VERSION}"
         
     | 
| 
       61 
44 
     | 
    
         | 
| 
       62 
45 
     | 
    
         
             
                  begin
         
     | 
    
        data/lib/monit/status.rb
    CHANGED
    
    | 
         @@ -27,10 +27,10 @@ module Monit 
     | 
|
| 
       27 
27 
     | 
    
         
             
                # * +username+ - username for authentication
         
     | 
| 
       28 
28 
     | 
    
         
             
                # * +password+ - password for authentication
         
     | 
| 
       29 
29 
     | 
    
         
             
                def initialize(options = {})
         
     | 
| 
       30 
     | 
    
         
            -
                  @host  
     | 
| 
       31 
     | 
    
         
            -
                  @port  
     | 
| 
       32 
     | 
    
         
            -
                  @ssl 
     | 
| 
       33 
     | 
    
         
            -
                  @auth  
     | 
| 
      
 30 
     | 
    
         
            +
                  @host     = options[:host]    || "localhost"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @port     = (options[:port]   || 2812).to_i
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @ssl      = options[:ssl]     || false
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @auth     = options[:auth]    || false
         
     | 
| 
       34 
34 
     | 
    
         
             
                  @username = options[:username]
         
     | 
| 
       35 
35 
     | 
    
         
             
                  @password = options[:password]
         
     | 
| 
       36 
36 
     | 
    
         
             
                  @services = []
         
     | 
| 
         @@ -72,17 +72,18 @@ module Monit 
     | 
|
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                # Parse the XML from Monit into a hash and into a Ruby representation.
         
     | 
| 
       74 
74 
     | 
    
         
             
                def parse(xml)
         
     | 
| 
       75 
     | 
    
         
            -
                  @hash 
     | 
| 
       76 
     | 
    
         
            -
                  @server 
     | 
| 
      
 75 
     | 
    
         
            +
                  @hash     = Hash.from_xml(xml)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @server   = Server.new(@hash["monit"]["server"])
         
     | 
| 
       77 
77 
     | 
    
         
             
                  @platform = Platform.new(@hash["monit"]["platform"])
         
     | 
| 
       78 
78 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
                  options = { 
     | 
| 
       80 
     | 
    
         
            -
                    :host 
     | 
| 
       81 
     | 
    
         
            -
                    :port 
     | 
| 
       82 
     | 
    
         
            -
                    :ssl 
     | 
| 
       83 
     | 
    
         
            -
                    :auth 
     | 
| 
       84 
     | 
    
         
            -
                    :username => @username, 
     | 
| 
       85 
     | 
    
         
            -
                    :password => @password 
     | 
| 
      
 79 
     | 
    
         
            +
                  options = {
         
     | 
| 
      
 80 
     | 
    
         
            +
                    :host     => @host,
         
     | 
| 
      
 81 
     | 
    
         
            +
                    :port     => @port,
         
     | 
| 
      
 82 
     | 
    
         
            +
                    :ssl      => @ssl,
         
     | 
| 
      
 83 
     | 
    
         
            +
                    :auth     => @auth,
         
     | 
| 
      
 84 
     | 
    
         
            +
                    :username => @username,
         
     | 
| 
      
 85 
     | 
    
         
            +
                    :password => @password
         
     | 
| 
      
 86 
     | 
    
         
            +
                  }
         
     | 
| 
       86 
87 
     | 
    
         | 
| 
       87 
88 
     | 
    
         
             
                  if @hash["monit"]["service"].is_a? Array
         
     | 
| 
       88 
89 
     | 
    
         
             
                    @services = @hash["monit"]["service"].map do |service|
         
     | 
    
        data/lib/monit/version.rb
    CHANGED
    
    
    
        data/spec/monit_spec.rb
    CHANGED
    
    | 
         @@ -17,7 +17,7 @@ describe Monit do 
     | 
|
| 
       17 
17 
     | 
    
         
             
                  lambda { @status.password }.should raise_error(NoMethodError)
         
     | 
| 
       18 
18 
     | 
    
         
             
                  @status.services.should == []
         
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       21 
21 
     | 
    
         
             
                it "should generate the correct URL" do
         
     | 
| 
       22 
22 
     | 
    
         
             
                  @status = Monit::Status.new
         
     | 
| 
       23 
23 
     | 
    
         
             
                  @status.url.should be_kind_of URI
         
     | 
| 
         @@ -29,7 +29,7 @@ describe Monit do 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  @status.port = 8080
         
     | 
| 
       30 
30 
     | 
    
         
             
                  @status.url.to_s.should == "https://rails.fi:8080/_status?format=xml"
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
       33 
33 
     | 
    
         
             
                it "should parse XML into a Hash" do
         
     | 
| 
       34 
34 
     | 
    
         
             
                  status = Monit::Status.new
         
     | 
| 
       35 
35 
     | 
    
         
             
                  status.stub!(:xml).and_return(File.read(SMALLISH_STATUS_PATH))
         
     | 
| 
         @@ -39,7 +39,7 @@ describe Monit do 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  status.hash["monit"]["server"].should_not be_nil
         
     | 
| 
       40 
40 
     | 
    
         
             
                  status.hash["monit"]["platform"].should_not be_nil
         
     | 
| 
       41 
41 
     | 
    
         
             
                  status.hash["monit"]["service"].should_not be_nil
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       43 
43 
     | 
    
         
             
                  status.stub!(:xml).and_return(File.read(LARGISH_STATUS_PATH))
         
     | 
| 
       44 
44 
     | 
    
         
             
                  status.parse(status.xml)
         
     | 
| 
       45 
45 
     | 
    
         
             
                  status.hash.should be_kind_of Hash
         
     | 
| 
         @@ -48,22 +48,22 @@ describe Monit do 
     | 
|
| 
       48 
48 
     | 
    
         
             
                  status.hash["monit"]["platform"].should_not be_nil
         
     | 
| 
       49 
49 
     | 
    
         
             
                  status.hash["monit"]["service"].should_not be_nil
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       52 
52 
     | 
    
         
             
                it "should parse XML into a Ruby representation" do
         
     | 
| 
       53 
53 
     | 
    
         
             
                  status = Monit::Status.new
         
     | 
| 
       54 
54 
     | 
    
         
             
                  status.stub!(:xml).and_return(File.read(SMALLISH_STATUS_PATH))
         
     | 
| 
       55 
55 
     | 
    
         
             
                  status.parse(status.xml)
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
       57 
57 
     | 
    
         
             
                  status.server.should be_kind_of Monit::Server
         
     | 
| 
       58 
58 
     | 
    
         
             
                  status.server.httpd.should be_kind_of Monit::HTTPD
         
     | 
| 
       59 
59 
     | 
    
         
             
                  status.platform.should be_kind_of Monit::Platform
         
     | 
| 
       60 
60 
     | 
    
         
             
                  status.services.should be_kind_of Array
         
     | 
| 
       61 
61 
     | 
    
         
             
                  status.services.first.should be_kind_of Monit::Service
         
     | 
| 
       62 
62 
     | 
    
         
             
                  status.services.first.should be_kind_of OpenStruct
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       64 
64 
     | 
    
         
             
                  status.stub!(:xml).and_return(File.read(LARGISH_STATUS_PATH))
         
     | 
| 
       65 
65 
     | 
    
         
             
                  status.parse(status.xml)
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       67 
67 
     | 
    
         
             
                  status.server.should be_kind_of Monit::Server
         
     | 
| 
       68 
68 
     | 
    
         
             
                  status.server.httpd.should be_kind_of Monit::HTTPD
         
     | 
| 
       69 
69 
     | 
    
         
             
                  status.platform.should be_kind_of Monit::Platform
         
     | 
| 
         @@ -72,20 +72,20 @@ describe Monit do 
     | 
|
| 
       72 
72 
     | 
    
         
             
                  status.services.first.should be_kind_of OpenStruct
         
     | 
| 
       73 
73 
     | 
    
         
             
                end
         
     | 
| 
       74 
74 
     | 
    
         
             
              end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
       76 
76 
     | 
    
         
             
              describe "Server" do
         
     | 
| 
       77 
77 
     | 
    
         
             
                it "should create a new instance of Monit::Server from a hash" do
         
     | 
| 
       78 
78 
     | 
    
         
             
                  hash = {         "id" => "52255a0b8999c46c98de9697a8daef67",
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
      
 79 
     | 
    
         
            +
                    "incarnation" => "1283946152",
         
     | 
| 
      
 80 
     | 
    
         
            +
                    "version" => "5.1.1",
         
     | 
| 
      
 81 
     | 
    
         
            +
                    "uptime" => "4",
         
     | 
| 
      
 82 
     | 
    
         
            +
                    "poll" => "30",
         
     | 
| 
      
 83 
     | 
    
         
            +
                    "startdelay" => "0",
         
     | 
| 
      
 84 
     | 
    
         
            +
                    "localhostname" => "Example.local",
         
     | 
| 
      
 85 
     | 
    
         
            +
                    "controlfile" => "/etc/monitrc",
         
     | 
| 
      
 86 
     | 
    
         
            +
                    "httpd" => { "address" => nil,
         
     | 
| 
      
 87 
     | 
    
         
            +
                      "port" => "2812",
         
     | 
| 
      
 88 
     | 
    
         
            +
                      "ssl" => "0" } }
         
     | 
| 
       89 
89 
     | 
    
         
             
                  server = Monit::Server.new(hash)
         
     | 
| 
       90 
90 
     | 
    
         
             
                  server.id.should == "52255a0b8999c46c98de9697a8daef67"
         
     | 
| 
       91 
91 
     | 
    
         
             
                  server.incarnation.should == "1283946152"
         
     | 
| 
         @@ -98,27 +98,27 @@ describe Monit do 
     | 
|
| 
       98 
98 
     | 
    
         
             
                  server.httpd.should be_kind_of Monit::HTTPD
         
     | 
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         
             
              end
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
       102 
102 
     | 
    
         
             
              describe "HTTPD" do
         
     | 
| 
       103 
103 
     | 
    
         
             
                it "should create a new instance of Monit::HTTPD from a hash" do
         
     | 
| 
       104 
104 
     | 
    
         
             
                  hash = { "address" => nil,
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
                    "port" => 2812,
         
     | 
| 
      
 106 
     | 
    
         
            +
                    "ssl" => "0" }
         
     | 
| 
       107 
107 
     | 
    
         
             
                  httpd = Monit::HTTPD.new(hash)
         
     | 
| 
       108 
108 
     | 
    
         
             
                  httpd.address.should be_nil
         
     | 
| 
       109 
109 
     | 
    
         
             
                  httpd.port.should == 2812
         
     | 
| 
       110 
110 
     | 
    
         
             
                  httpd.ssl.should be_false
         
     | 
| 
       111 
111 
     | 
    
         
             
                end
         
     | 
| 
       112 
112 
     | 
    
         
             
              end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
       114 
114 
     | 
    
         
             
              describe "Platform" do
         
     | 
| 
       115 
115 
     | 
    
         
             
                it "should create a new instance of Monit::Platform from a hash" do
         
     | 
| 
       116 
116 
     | 
    
         
             
                  hash = { "name" => "Darwin",
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
                    "release" => "10.4.0",
         
     | 
| 
      
 118 
     | 
    
         
            +
                    "version" => "Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386",
         
     | 
| 
      
 119 
     | 
    
         
            +
                    "machine" => "i386",
         
     | 
| 
      
 120 
     | 
    
         
            +
                    "cpu" => "2",
         
     | 
| 
      
 121 
     | 
    
         
            +
                    "memory" => "4194304" }
         
     | 
| 
       122 
122 
     | 
    
         
             
                  platform = Monit::Platform.new(hash)
         
     | 
| 
       123 
123 
     | 
    
         
             
                  platform.name.should == "Darwin"
         
     | 
| 
       124 
124 
     | 
    
         
             
                  platform.release.should == "10.4.0"
         
     | 
| 
         @@ -128,27 +128,27 @@ describe Monit do 
     | 
|
| 
       128 
128 
     | 
    
         
             
                  platform.memory.should == 4194304
         
     | 
| 
       129 
129 
     | 
    
         
             
                end
         
     | 
| 
       130 
130 
     | 
    
         
             
              end
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
       132 
132 
     | 
    
         
             
              describe "Service" do
         
     | 
| 
       133 
133 
     | 
    
         
             
                let(:service) do
         
     | 
| 
       134 
134 
     | 
    
         
             
                  hash = { "collected_sec" => "1283946152",
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
      
 135 
     | 
    
         
            +
                    "collected_usec" => "309973",
         
     | 
| 
      
 136 
     | 
    
         
            +
                    "name" => "Example.local",
         
     | 
| 
      
 137 
     | 
    
         
            +
                    "status" => "0",
         
     | 
| 
      
 138 
     | 
    
         
            +
                    "status_hint" => "0",
         
     | 
| 
      
 139 
     | 
    
         
            +
                    "monitor" => "1",
         
     | 
| 
      
 140 
     | 
    
         
            +
                    "monitormode" => "0",
         
     | 
| 
      
 141 
     | 
    
         
            +
                    "pendingaction" => "0",
         
     | 
| 
      
 142 
     | 
    
         
            +
                    "groups" => { "name" => "server" },
         
     | 
| 
      
 143 
     | 
    
         
            +
                    "system" => { "load" => { "avg01" => "0.28",
         
     | 
| 
      
 144 
     | 
    
         
            +
                      "avg05" => "0.43",
         
     | 
| 
      
 145 
     | 
    
         
            +
                      "avg15" => "0.48" },
         
     | 
| 
      
 146 
     | 
    
         
            +
                      "cpu" => {   "user" => "10.0",
         
     | 
| 
      
 147 
     | 
    
         
            +
                        "system" => "4.1" },
         
     | 
| 
      
 148 
     | 
    
         
            +
                        "memory" => { "percent" => "44.1",
         
     | 
| 
      
 149 
     | 
    
         
            +
                          "kilobyte" => "1850152" }
         
     | 
| 
      
 150 
     | 
    
         
            +
                  },
         
     | 
| 
      
 151 
     | 
    
         
            +
                    "type" => "5" }
         
     | 
| 
       152 
152 
     | 
    
         
             
                  Monit::Service.new(hash) 
         
     | 
| 
       153 
153 
     | 
    
         
             
                end
         
     | 
| 
       154 
154 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: monit
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-06-03 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rake
         
     | 
| 
         @@ -127,10 +127,6 @@ files: 
     | 
|
| 
       127 
127 
     | 
    
         
             
            - lib/monit/server.rb
         
     | 
| 
       128 
128 
     | 
    
         
             
            - lib/monit/service.rb
         
     | 
| 
       129 
129 
     | 
    
         
             
            - lib/monit/status.rb
         
     | 
| 
       130 
     | 
    
         
            -
            - lib/monit/status/httpd.rb
         
     | 
| 
       131 
     | 
    
         
            -
            - lib/monit/status/platform.rb
         
     | 
| 
       132 
     | 
    
         
            -
            - lib/monit/status/server.rb
         
     | 
| 
       133 
     | 
    
         
            -
            - lib/monit/status/service.rb
         
     | 
| 
       134 
130 
     | 
    
         
             
            - lib/monit/version.rb
         
     | 
| 
       135 
131 
     | 
    
         
             
            - monit.gemspec
         
     | 
| 
       136 
132 
     | 
    
         
             
            - spec/monit_spec.rb
         
     | 
| 
         @@ -149,21 +145,15 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       149 
145 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       150 
146 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       151 
147 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       152 
     | 
    
         
            -
                  segments:
         
     | 
| 
       153 
     | 
    
         
            -
                  - 0
         
     | 
| 
       154 
     | 
    
         
            -
                  hash: -2454781035396715959
         
     | 
| 
       155 
148 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       156 
149 
     | 
    
         
             
              none: false
         
     | 
| 
       157 
150 
     | 
    
         
             
              requirements:
         
     | 
| 
       158 
151 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       159 
152 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       160 
153 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       161 
     | 
    
         
            -
                  segments:
         
     | 
| 
       162 
     | 
    
         
            -
                  - 0
         
     | 
| 
       163 
     | 
    
         
            -
                  hash: -2454781035396715959
         
     | 
| 
       164 
154 
     | 
    
         
             
            requirements: []
         
     | 
| 
       165 
155 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       166 
     | 
    
         
            -
            rubygems_version: 1.8. 
     | 
| 
      
 156 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
       167 
157 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       168 
158 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       169 
159 
     | 
    
         
             
            summary: Connect to Monit
         
     | 
    
        data/lib/monit/status/httpd.rb
    DELETED
    
    | 
         @@ -1,12 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Monit
         
     | 
| 
       2 
     | 
    
         
            -
              # The HTTPD section from the Monit XML
         
     | 
| 
       3 
     | 
    
         
            -
              class HTTPD
         
     | 
| 
       4 
     | 
    
         
            -
                attr_reader :address, :port, :ssl
         
     | 
| 
       5 
     | 
    
         
            -
                    
         
     | 
| 
       6 
     | 
    
         
            -
                def initialize(options = {})
         
     | 
| 
       7 
     | 
    
         
            -
                  @address = options["address"]
         
     | 
| 
       8 
     | 
    
         
            -
                  @port = options["port"].to_i
         
     | 
| 
       9 
     | 
    
         
            -
                  @ssl = options["ssl"] == "1" ? true : false
         
     | 
| 
       10 
     | 
    
         
            -
                end
         
     | 
| 
       11 
     | 
    
         
            -
              end
         
     | 
| 
       12 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,15 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Monit
         
     | 
| 
       2 
     | 
    
         
            -
              # The platform section from the Monit XML
         
     | 
| 
       3 
     | 
    
         
            -
              class Platform
         
     | 
| 
       4 
     | 
    
         
            -
                attr_reader :name, :release, :version, :machine, :cpu, :memory
         
     | 
| 
       5 
     | 
    
         
            -
                
         
     | 
| 
       6 
     | 
    
         
            -
                def initialize(options = {})
         
     | 
| 
       7 
     | 
    
         
            -
                  @name = options["name"]
         
     | 
| 
       8 
     | 
    
         
            -
                  @release = options["release"]
         
     | 
| 
       9 
     | 
    
         
            -
                  @version = options["version"]
         
     | 
| 
       10 
     | 
    
         
            -
                  @machine = options["machine"]
         
     | 
| 
       11 
     | 
    
         
            -
                  @cpu = options["cpu"].to_i
         
     | 
| 
       12 
     | 
    
         
            -
                  @memory = options["memory"].to_i
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/monit/status/server.rb
    DELETED
    
    | 
         @@ -1,18 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Monit
         
     | 
| 
       2 
     | 
    
         
            -
              # The server section from the Monit XML
         
     | 
| 
       3 
     | 
    
         
            -
              class Server
         
     | 
| 
       4 
     | 
    
         
            -
                  attr_reader :id, :incarnation, :version, :uptime, :poll, :startdelay, :localhostname, :controlfile, :httpd
         
     | 
| 
       5 
     | 
    
         
            -
                  
         
     | 
| 
       6 
     | 
    
         
            -
                  def initialize(options = {})
         
     | 
| 
       7 
     | 
    
         
            -
                    @id = options["id"]
         
     | 
| 
       8 
     | 
    
         
            -
                    @incarnation = options["incarnation"]
         
     | 
| 
       9 
     | 
    
         
            -
                    @version = options["version"]
         
     | 
| 
       10 
     | 
    
         
            -
                    @uptime = options["uptime"].to_i
         
     | 
| 
       11 
     | 
    
         
            -
                    @poll = options["poll"].to_i
         
     | 
| 
       12 
     | 
    
         
            -
                    @startdelay = options["startdelay"].to_i
         
     | 
| 
       13 
     | 
    
         
            -
                    @localhostname = options["localhostname"]
         
     | 
| 
       14 
     | 
    
         
            -
                    @controlfile = options["controlfile"]
         
     | 
| 
       15 
     | 
    
         
            -
                    @httpd = options["httpd"].is_a?(HTTPD) ? options["httpd"] : HTTPD.new(options["httpd"])
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/monit/status/service.rb
    DELETED
    
    | 
         @@ -1,79 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "ostruct"
         
     | 
| 
       2 
     | 
    
         
            -
            module Monit
         
     | 
| 
       3 
     | 
    
         
            -
              # The service section from the Monit XML. Inherits from OpenStruct.
         
     | 
| 
       4 
     | 
    
         
            -
              class Service < OpenStruct
         
     | 
| 
       5 
     | 
    
         
            -
                TYPES = { 0 => "Filesystem", 1 => "Directory", 2 => "File", 3 => "Daemon", 4 => "Connection", 5 => "System" }
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                def initialize(hash = nil, options = {})
         
     | 
| 
       8 
     | 
    
         
            -
                  @host ||= options[:host] ||= "localhost"
         
     | 
| 
       9 
     | 
    
         
            -
                  @port ||= options[:port] ||= 2812
         
     | 
| 
       10 
     | 
    
         
            -
                  @ssl  ||= options[:ssl]  ||= false
         
     | 
| 
       11 
     | 
    
         
            -
                  @auth ||= options[:auth] ||= false
         
     | 
| 
       12 
     | 
    
         
            -
                  @username = options[:username]
         
     | 
| 
       13 
     | 
    
         
            -
                  @password = options[:password]
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  hash = rename_service_type(hash) if hash
         
     | 
| 
       16 
     | 
    
         
            -
                  super(hash)
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                def url path
         
     | 
| 
       20 
     | 
    
         
            -
                  url_params = { :host => @host, :port => @port, :path => "/#{path}" }
         
     | 
| 
       21 
     | 
    
         
            -
                  @ssl ? URI::HTTPS.build(url_params) : URI::HTTP.build(url_params)
         
     | 
| 
       22 
     | 
    
         
            -
                end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                def start
         
     | 
| 
       25 
     | 
    
         
            -
                  return self.do :start
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                def stop
         
     | 
| 
       29 
     | 
    
         
            -
                  return self.do :stop
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                def restart
         
     | 
| 
       33 
     | 
    
         
            -
                  return self.do :restart
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                def monitor
         
     | 
| 
       37 
     | 
    
         
            -
                  return self.do :monitor
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                def unmonitor
         
     | 
| 
       41 
     | 
    
         
            -
                  return self.do :unmonitor
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                def do(action)
         
     | 
| 
       45 
     | 
    
         
            -
                  uri = self.url self.name
         
     | 
| 
       46 
     | 
    
         
            -
                  http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                  if @ssl
         
     | 
| 
       49 
     | 
    
         
            -
                    http.use_ssl = true
         
     | 
| 
       50 
     | 
    
         
            -
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       51 
     | 
    
         
            -
                  end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                  request = Net::HTTP::Post.new(uri.request_uri)
         
     | 
| 
       54 
     | 
    
         
            -
                  request.body = "action=#{action}"
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                  if @auth
         
     | 
| 
       57 
     | 
    
         
            -
                    request.basic_auth(@username, @password)
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  request["User-Agent"] = "Monit Ruby client #{Monit::VERSION}"
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                  response = http.request(request)
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                  if response.code == "200"
         
     | 
| 
       65 
     | 
    
         
            -
                    return true
         
     | 
| 
       66 
     | 
    
         
            -
                  else
         
     | 
| 
       67 
     | 
    
         
            -
                    return false
         
     | 
| 
       68 
     | 
    
         
            -
                  end
         
     | 
| 
       69 
     | 
    
         
            -
                end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                private
         
     | 
| 
       72 
     | 
    
         
            -
                # Renames the Service type from "type" to "service_type" to avoid conflicts
         
     | 
| 
       73 
     | 
    
         
            -
                def rename_service_type(hash)
         
     | 
| 
       74 
     | 
    
         
            -
                  hash["service_type"] = hash["type"]
         
     | 
| 
       75 
     | 
    
         
            -
                  hash.delete("type")
         
     | 
| 
       76 
     | 
    
         
            -
                  hash
         
     | 
| 
       77 
     | 
    
         
            -
                end
         
     | 
| 
       78 
     | 
    
         
            -
              end
         
     | 
| 
       79 
     | 
    
         
            -
            end
         
     |