From 3efdb1338b4e8a5568a9a792c89f34566b47661a Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 2 Oct 2009 20:23:05 +0200 Subject: [PATCH] Add dsa-check-cert-expire: Checks if a given cert on disk will expire soon. --- .../checks/dsa-check-cert-expire | 56 +++++++++++++++++++ dsa-nagios-checks/debian/changelog | 7 +++ dsa-nagios-checks/debian/copyright | 5 ++ 3 files changed, 68 insertions(+) create mode 100755 dsa-nagios-checks/checks/dsa-check-cert-expire diff --git a/dsa-nagios-checks/checks/dsa-check-cert-expire b/dsa-nagios-checks/checks/dsa-check-cert-expire new file mode 100755 index 0000000..89a119a --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-cert-expire @@ -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 " >&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 diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index f07c7b2..e74e040 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -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 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. diff --git a/dsa-nagios-checks/debian/copyright b/dsa-nagios-checks/debian/copyright index fbd517c..840df50 100644 --- a/dsa-nagios-checks/debian/copyright +++ b/dsa-nagios-checks/debian/copyright @@ -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 -- 2.20.1