Class: Wakame::Monitor::Service::CommandChecker

Inherits:
ServiceChecker show all
Defined in:
lib/wakame/monitor/service.rb

Instance Attribute Summary collapse

Attributes inherited from ServiceChecker

#last_checked_at, #status, #svc_id, #timer

Instance Method Summary collapse

Methods inherited from ServiceChecker

#start, #stop

Constructor Details

#initialize(svc_id, svc_mon, cmdstr) ⇒ CommandChecker

Returns a new instance of CommandChecker.



97
98
99
100
# File 'lib/wakame/monitor/service.rb', line 97

def initialize(svc_id, svc_mon, cmdstr)
  super(svc_id, svc_mon)
  @command = cmdstr
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



95
96
97
# File 'lib/wakame/monitor/service.rb', line 95

def command
  @command
end

Instance Method Details

#checkObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/wakame/monitor/service.rb', line 102

def check()
  outputs =[]
  cmdstat = ::Open4.popen4(@command) { |pid, stdin, stdout, stderr|
    stdout.each { |l|
      outputs << l
    }
    stderr.each { |l|
      outputs << l
    }
  }
  Wakame.log.debug("#{self.class}: Exit Status #{@command}: #{cmdstat}")
  if outputs.size > 0
    @service_monitor.send_event(Wakame::Packets::MonitoringOutput.new(@service_monitor.agent, self.svc_id, outputs.join('')))
  end
  cmdstat.exitstatus == 0 ? Wakame::Service::STATUS_ONLINE : Wakame::Service::STATUS_OFFLINE
end