Need Check cert requireng cert,key and password as options

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
jamespye
Posts: 5
Joined: Thu Sep 06, 2012 9:03 am

Need Check cert requireng cert,key and password as options

Post by jamespye »

Is there a plugin that takes certs,keys and password for options to query & alert for certificate expirations? I can do this with openssl and I can identify the expiration date status but I don't know how to get Nagios to take notice and make alerts for warnings and critical.
My test script output that needs evaluated by Nagios to set alerts or better yet a plugin that you can enter certs,keys and passwords in. Thank you very much.

#!/bin/ksh
rm -f /tmp/certcheck.out

STATUS=0
TODAY=$(date +%s)
CERT=/home/monitor/ValidatePartnerCert/cert.pem
KEY=/home/monitor/ValidatePartnerCert/cert_key.pem
PASS=xxxxxxxx
CKDATE(){
CRTDATE=`date --utc --date "$EXPDATE" +%s`
if [[ $CRTDATE-$TODAY -lt 2592000 ]]; then
printf "\n Expiring in 90 days: Yes\n ", %s
STATUS=1
elif [[ $CRTDATE-$TODAY -lt 7776000 ]]
then
printf "\n Expiring in 90 days: No\n ", %s
STATUS=2
else
STATUS=0
fi
return $STATUS
}

for i in cert1.com:2222 cert2.com.:43 cert3:18443
do
EXPDATE=`openssl s_client -connect ${i} -cert ${CERT} -key ${KEY} -pass ${PASS} < /dev/null |openssl x509 -noout -enddate | sed s'/notAfter=//'`
#EXPDATE="Aug 2 14:13:30 GMT 2013" # for testing status
CKDATE
#cert=`openssl s_client -connect ${i} -cert ${CERT} -key ${KEY} -pass ${PASS} < /dev/null |openssl x509 -noout -subject| awk -F'CN=' '{print $2}'`
echo $i $STATUS
done > /tmp/certcheck.out

cat /tmp/certcheck.out

Expiring in 90 days: Yes
,cert1.com:2222 1

Expiring in 90 days: Yes
,cert2.com:443 1

Expiring in 90 days: Yes
,cert3.com:18443 1
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Need Check cert requireng cert,key and password as optio

Post by scottwilkerson »

Here is the Nagios plug-in development guidelines if you want to turn this into a proper plugin
http://nagiosplug.sourceforge.net/devel ... lines.html
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Need Check cert requireng cert,key and password as optio

Post by abrist »

There are a few plugins on the exchange.
http://exchange.nagios.org/index.php?op ... expiration
Specifically:
http://exchange.nagios.org/directory/Tu ... on/details
Alternatively, an explanation of how to do it with check_http:
http://www.barryodonovan.com/index.php/ ... ith-nagios
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked