Class: Bosh::Agent::MonitClient

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

Constant Summary collapse

TYPES =
{
  :file_system => 0,
  :directory => 1,
  :file => 2,
  :process => 3,
  :remote_host => 4,
  :system => 5,
  :fifo => 6
}
TYPES_INVERSE =
TYPES.invert
STATUS_MESSAGES =
{
  :file_system => "accessible",
  :directory => "accessible",
  :file => "accessible",
  :process => "running",
  :remote_host => "online with all services",
  :system => "running",
  :fifo => "accessible"
}
MONITOR =
{
  :no => 0,
  :yes => 1,
  :init => 2
}
MONITOR_INVERSE =
MONITOR.invert

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ MonitClient

Returns a new instance of MonitClient.



37
38
39
40
# File 'lib/bosh_agent/monit_client.rb', line 37

def initialize(uri, options = {})
  @logger = options[:logger] || Logger.new(nil)
  @uri = URI.parse(uri)
end

Instance Method Details

#monit_infoObject



82
83
84
85
86
87
88
89
90
# File 'lib/bosh_agent/monit_client.rb', line 82

def monit_info
  status = get_status
  monit_status = status["monit"]
  {
    :id => monit_status["id"],
    :incarnation => monit_status["incarnation"],
    :version => monit_status["version"]
  }
end

#monitor(arg) ⇒ Object



54
55
56
# File 'lib/bosh_agent/monit_client.rb', line 54

def monitor(arg)
  service_names(arg).each { |service_name| service_action(service_name, "monitor") }
end

#restart(arg) ⇒ Object



50
51
52
# File 'lib/bosh_agent/monit_client.rb', line 50

def restart(arg)
  service_names(arg).each { |service_name| service_action(service_name, "restart") }
end

#start(arg) ⇒ Object



42
43
44
# File 'lib/bosh_agent/monit_client.rb', line 42

def start(arg)
  service_names(arg).each { |service_name| service_action(service_name, "start") }
end

#status(arg) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bosh_agent/monit_client.rb', line 62

def status(arg)
  status = get_status
  services = get_services(status, arg)
  result = {}
  services.each do |service|
    type = TYPES_INVERSE[service["type"].to_i]
    status_message = service["status_message"] || STATUS_MESSAGES[type]
    result[service["name"]] = {
      :type => type,
      :status => {
        :code => service["status"].to_i,
        :message => status_message
      },
      :monitor => MONITOR_INVERSE[service["monitor"].to_i],
      :raw => service
    }
  end
  result
end

#stop(arg) ⇒ Object



46
47
48
# File 'lib/bosh_agent/monit_client.rb', line 46

def stop(arg)
  service_names(arg).each { |service_name| service_action(service_name, "stop") }
end

#unmonitor(arg) ⇒ Object



58
59
60
# File 'lib/bosh_agent/monit_client.rb', line 58

def unmonitor(arg)
  service_names(arg).each { |service_name| service_action(service_name, "unmonitor") }
end