Class: CertCheck::Cert

Inherits:
Object
  • Object
show all
Defined in:
lib/openvpn_cert_nagios/certs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Cert

Returns a new instance of Cert.



3
4
5
# File 'lib/openvpn_cert_nagios/certs.rb', line 3

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/openvpn_cert_nagios/certs.rb', line 6

def path
  @path
end

Instance Method Details

#chk_commandObject



28
29
30
# File 'lib/openvpn_cert_nagios/certs.rb', line 28

def chk_command
  Shell.exe("openssl x509 -in #{path} -inform PEM -text -noout -enddate -startdate")
end

#expiration_dateObject



20
21
22
# File 'lib/openvpn_cert_nagios/certs.rb', line 20

def expiration_date
  Date.parse(expiration_row.split("=", 2)[1])
end

#expiration_rowObject



24
25
26
# File 'lib/openvpn_cert_nagios/certs.rb', line 24

def expiration_row
  chk_command.find { |x| x =~ /^notAfter=/ }
end

#expires_inObject



8
9
10
# File 'lib/openvpn_cert_nagios/certs.rb', line 8

def expires_in
  expiration_date - Date.today
end

#messageObject



12
13
14
# File 'lib/openvpn_cert_nagios/certs.rb', line 12

def message
  "%4d:%s" % [expires_in, name]
end

#nameObject



16
17
18
# File 'lib/openvpn_cert_nagios/certs.rb', line 16

def name
  File.basename(path, ".crt")
end