Class: CertCheck

Inherits:
Object
  • Object
show all
Includes:
NagiosCheck
Defined in:
lib/openvpn_cert_nagios/certs.rb,
lib/openvpn_cert_nagios/check.rb,
lib/openvpn_cert_nagios/shell.rb,
lib/openvpn_cert_nagios/version.rb

Defined Under Namespace

Classes: Cert, Shell

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#certsObject



24
25
26
27
28
29
# File 'lib/openvpn_cert_nagios/check.rb', line 24

def certs
  @certs ||= Dir.new(options.path)
    .entries
    .find_all{ |f| f =~ /.*\.crt$/ }
    .map { |f| "#{ options.path }/#{ f }" }
end

#checkObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openvpn_cert_nagios/check.rb', line 11

def check

  result = certs.reduce({days: 9999, message: []}) do |memo, file|
    cert = Cert.new(file)
    memo[:message] << cert.message
    memo[:days] = [cert.expires_in, memo[:days]].min
    memo
  end

  store_value :expires, result[:days]
  store_message result[:message].sort.join(",").delete(' ')
end