openvpn_cert_nagios 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b4406c75272d6dfc8b2b4725428ca78c310c296
4
+ data.tar.gz: f11365712aed9ca2c4a368a3755d99677d36c5e8
5
+ SHA512:
6
+ metadata.gz: ecfd59b19ed28743f53dd4967fb920d9734887696ffed4da0a6616d70bdf1694f54aa36fad92f1a892607f576a442a60b819fa1cb528d6cfeca64f088f538d35
7
+ data.tar.gz: d37a84b9681b3bf0f3d90bf17423f3e0c04d8a9a40f470251394cc5a764464c8a3c92fefc1b59888c1f046ee05aa18364d6810372438f2aa288f68906d70cb1c
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'openvpn_cert_nagios'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ root = File.dirname(File.dirname(__FILE__))
8
+ $: << (File.expand_path 'lib', root)
9
+ require 'openvpn_cert_nagios'
10
+ end
11
+
12
+ CertCheck.new.run
@@ -0,0 +1 @@
1
+ require "openvpn_cert_nagios/base"
@@ -0,0 +1,8 @@
1
+ require "nagios_check"
2
+ require 'open3'
3
+ require 'date'
4
+
5
+ require "openvpn_cert_nagios/version"
6
+ require "openvpn_cert_nagios/shell"
7
+ require "openvpn_cert_nagios/certs"
8
+ require "openvpn_cert_nagios/check"
@@ -0,0 +1,32 @@
1
+ class CertCheck
2
+ class Cert
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+ attr_reader :path
7
+
8
+ def expires_in
9
+ expiration_date - Date.today
10
+ end
11
+
12
+ def message
13
+ "%4d:%s" % [expires_in, name]
14
+ end
15
+
16
+ def name
17
+ File.basename(path, ".crt")
18
+ end
19
+
20
+ def expiration_date
21
+ Date.parse(expiration_row.split("=", 2)[1])
22
+ end
23
+
24
+ def expiration_row
25
+ chk_command.find { |x| x =~ /^notAfter=/ }
26
+ end
27
+
28
+ def chk_command
29
+ Shell.exe("openssl x509 -in #{path} -inform PEM -text -noout -enddate -startdate")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ class CertCheck
2
+ include NagiosCheck
3
+
4
+ enable_warning :mandatory
5
+ enable_critical :mandatory
6
+
7
+ on "--path PATH", "-P PATH", String, :mandatory
8
+
9
+ enable_timeout
10
+
11
+ def check
12
+
13
+ result = certs.reduce({days: 9999, message: []}) do |memo, file|
14
+ cert = Cert.new(file)
15
+ memo[:message] << cert.message
16
+ memo[:days] = [cert.expires_in, memo[:days]].min
17
+ memo
18
+ end
19
+
20
+ store_value :expires, result[:days]
21
+ store_message result[:message].sort.join(",").delete(' ')
22
+ end
23
+
24
+ def certs
25
+ @certs ||= Dir.new(options.path)
26
+ .entries
27
+ .find_all{ |f| f =~ /.*\.crt$/ }
28
+ .map { |f| "#{ options.path }/#{ f }" }
29
+ end
30
+
31
+ end
@@ -0,0 +1,19 @@
1
+ class CertCheck
2
+ ##
3
+ # Execute shell commands. Simple popen3 wrapper, that returns either
4
+ # STDOUT or exit status, and aborts on non zero status.
5
+ #
6
+ class Shell
7
+ def self.exe(cmd)
8
+
9
+ Open3.popen3({"PATH" => "/usr/bin:/bin:/usr/sbin:/sbin"}, cmd) do |stdin, stdout, stderr, process|
10
+
11
+ stdin.close
12
+ raise "#{cmd} FAILED: #{stderr.read} #{ stdout.read }" if process.value != 0
13
+ stdout.readlines
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,3 @@
1
+ class CertCheck
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openvpn_cert_nagios
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Kovalov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nagios_check
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ description: |2+
56
+
57
+ For every certificate in EasyRSA directory check expiration date and issue warning or critial warning alert.
58
+
59
+ email: dmytro.kovalov@gmail.com
60
+ executables:
61
+ - check_open_vpn_cert
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - bin/check_open_vpn_cert
66
+ - lib/openvpn_cert_nagios.rb
67
+ - lib/openvpn_cert_nagios/base.rb
68
+ - lib/openvpn_cert_nagios/certs.rb
69
+ - lib/openvpn_cert_nagios/check.rb
70
+ - lib/openvpn_cert_nagios/shell.rb
71
+ - lib/openvpn_cert_nagios/version.rb
72
+ homepage: http://dmytro.github.com/
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Check expiration date of the OpenVPN certs
97
+ test_files: []
98
+ has_rdoc: