Class: OkComputer::Clamav::ClamdCheck

Inherits:
OkComputer::Check
  • Object
show all
Defined in:
lib/ok_computer/clamav/clamd_check.rb

Overview

This class performs a health check on a clamd instance using the PING command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket_path: '/var/run/clamav/clamd.ctl') ⇒ ClamdCheck

‘socket_path`: the Unix socket path clamd is using.

default: /var/run/clamav/clamd.ctl (Debian/Ubuntu) homebrew on macOS uses /tmp/clamd.socket



13
14
15
# File 'lib/ok_computer/clamav/clamd_check.rb', line 13

def initialize(socket_path:'/var/run/clamav/clamd.ctl')
  @socket_path = socket_path
end

Instance Attribute Details

#socket_pathObject (readonly)

Returns the value of attribute socket_path.



7
8
9
# File 'lib/ok_computer/clamav/clamd_check.rb', line 7

def socket_path
  @socket_path
end

Instance Method Details

#checkObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ok_computer/clamav/clamd_check.rb', line 17

def check
  socket = UNIXSocket.new(socket_path)
  socket.write "nPING\n"
  clamd_status = socket.readline
  socket.close

  if clamd_status != "PONG\n"
    mark_failure
    mark_message "clamd responded to PING with #{clamd_status}"
  else
    mark_message 'clamd is running and responds to PING'
  end
end