Add dsa-check-cert-expire: Checks if a given cert on disk will expire soon.
authorPeter Palfrader <peter@palfrader.org>
Fri, 2 Oct 2009 18:23:05 +0000 (20:23 +0200)
committerPeter Palfrader <peter@palfrader.org>
Fri, 2 Oct 2009 18:23:05 +0000 (20:23 +0200)
dsa-nagios-checks/checks/dsa-check-cert-expire [new file with mode: 0755]
dsa-nagios-checks/debian/changelog
dsa-nagios-checks/debian/copyright

diff --git a/dsa-nagios-checks/checks/dsa-check-cert-expire b/dsa-nagios-checks/checks/dsa-check-cert-expire
new file mode 100755 (executable)
index 0000000..89a119a
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Checks if a given cert on disk will expire soon
+
+# Copyright 2009 Peter Palfrader
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+set -u
+set -e
+
+# warn if expires within 2 weeks, critical if within a day or already is expired
+warn=1209600
+crit=86400
+
+if [ "$#" != 1 ]; then
+       echo "Usage: $0 <certfile>" >&2
+       exit 3
+fi
+
+cert="$1"
+
+if ! [ -r "$cert" ] ; then
+       echo "Cert file ($cert) does not exist or is not readable" >&2
+       exit 3
+fi
+
+expires=`openssl x509 -enddate -noout < "$cert"`
+
+if openssl x509 -checkend "$warn" -noout < "$cert" ; then
+       echo "OK: $expires"
+       exit 0
+fi
+if openssl x509 -checkend "$crit" -noout < "$cert" ; then
+       echo "WARN: $expires"
+       exit 1
+fi
+echo "CRITICAL: $expires"
+exit 2
index f07c7b2..e74e040 100644 (file)
@@ -1,3 +1,10 @@
+dsa-nagios-checks (83) stable; urgency=low
+
+  * Add dsa-check-cert-expire: Checks if a given cert on disk will expire
+    soon.
+
+ -- Peter Palfrader <weasel@debian.org>  Fri, 02 Oct 2009 20:22:42 +0200
+
 dsa-nagios-checks (82) stable; urgency=low
 
   * dsa-check-raid-3ware: Learn about REBUILDING state for 3ware raid units.
index fbd517c..840df50 100644 (file)
@@ -85,3 +85,8 @@ dsa-check-soas:
 dsa-check-raid-aacraid:
   Copyright: 2008,2009 Peter Palfrader
   License: MIT
+
+########################################################################
+dsa-check-cert-expire
+  Copyright: 2009 Peter Palfrader
+  License: MIT