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

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

Instance Attribute Summary collapse

Attributes inherited from ServiceChecker

#interval, #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, interval) ⇒ CommandChecker

Returns a new instance of CommandChecker.



102
103
104
105
# File 'lib/wakame/monitor/service.rb', line 102

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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



100
101
102
# File 'lib/wakame/monitor/service.rb', line 100

def command
  @command
end

Instance Method Details

#checkObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/wakame/monitor/service.rb', line 107

def check()
  outputs =[]
  cmdstat = ::Open4.popen4(@command) { |pid, stdin, stdout, stderr|
    stdout.each { |l|
      outputs << l
    }
    stderr.each { |l|
      outputs << l
    }
  }
  if outputs.size > 0
    @service_monitor.send_event(Wakame::Packets::MonitoringOutput.new(@service_monitor.agent, self.svc_id, outputs.join('')))
  end

  Wakame.log.debug("#{self.class}: Detected the failed exit status: #{@command}: #{cmdstat}") if cmdstat.exitstatus != 0
  cmdstat.exitstatus == 0 ? Wakame::Service::STATUS_ONLINE : Wakame::Service::STATUS_OFFLINE
end