Quantcast
Channel: THWACK: Message List
Viewing all articles
Browse latest Browse all 20396

Re: PGP Certificate expiration monitoring

$
0
0

I have a script that outputs the information to the screen - written by one of our Linux guys.  The script is below:

 

#!/bin/bash

## functions
function date_to_days_remaining()
{
    # takes date arg in yyyy-mm-dd format
    date1=$( date --date "$( echo $1 | tr -d '-' )" +%s )
    date2=$( date +%s )
    echo $(( $(( $date1 - $date2 )) / 86400 ))
}

 

## script
pgp -l 2>/dev/null | tail -n+3 | head -n-1 | awk '{print $5}' | while read key_id
do
    key_details=$( pgp --list-key-details $key_id )
    key_name=$( echo "${key_details}" | grep 'Key Details:' | awk '{for(i=n;i<=NF;i++)$(i-(n-1))=$i;NF=NF-(n-1);print $0}' n=3 | tr -d ',' )

    count=0
    for exp in $( echo "${key_details}" | grep 'Expires:' | awk '{ print $2 }' )
    do
        if [ "${exp}" != "Never" ]
        then
            expires_days=$( date_to_days_remaining $exp )
            if [ $count -eq 0 ]
            then
                echo "${key_id}, ${key_name}, primary, ${expires_days}"
            else
                echo "${key_id}, ${key_name}, subkey ${count}, ${expires_days}"
            fi
            ((count++))
        fi
    done
done

 

this gives the following information (Just a few lines of the full output):

0xC0482C2B, companyUK Test Key (companyUK Test Key 2012) <support@company.com>, primary, -348

0xC0482C2B, companyUK Test Key (companyUK Test Key 2012) <support@company.com>, subkey 1, -348

0x11F86268, companyUK Test Key 2013 (companyUK Test Key 2013) <support@company.com>, primary, 26

0x11F86268, companyUK Test Key 2013 (companyUK Test Key 2013) <support@company.com>, subkey 1, 26

 

The columns are such:

    Key ID (primary)

2.       Key Name

3.       Whether expiry represents the primary or a sub key (and which subkey)

4.       Days before expiry (negative has obviously expired already)

  

      What I need to be able to do is get the monitor to read each line and give a warning alert if the number of days is less than 60 and a critical alert if it is less than 30 days.  I also want to be able to put this data into the NetPerfMon database to be able to build reports on it at a later date.  Plus this script will need to run on multiple keystores on the same server

 

 

     Thanks in advance

     Simon

 

W


Viewing all articles
Browse latest Browse all 20396

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>