Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / ssl / certificate_file_expiry @ bba98f95

Historique | Voir | Annoter | Télécharger (1,82 ko)

1
#!/bin/sh
2
: << =cut
3
=head1 NAME
4

    
5
certificate_file_expiry - check the certificate validity of your certificates
6

    
7
= head1 CONFIGURATION
8

    
9
Installing: Add list of your certificates prefixed by the type in munin plugin-conf.d
10

    
11
For openvpn ca.crt and crl.pem
12
[certificate_file_expiry]
13
user root
14
env.CERTS crl:/etc/openvpn/easy-rsa/keys/crl.pem x509:/etc/openvpn/easy-rsa/keys/ca.crt
15

    
16
For letsencrypt certificates
17
[certificate_file_expiry]
18
user root
19
env.CERTS x509:/etc/letsencrypt/live/domain1.example.com/cert.pem x509:/etc/letsencrypt/live/domain2.example.com/cert.pem
20

    
21
Warning and Critical levels can also be configured with env variables like this
22
[certificate_file_expiry]
23
...
24
# warn when certificate will be invalid within 5 days
25
env.warning 5:
26
# critical when certificate will be invalid within 1 day
27
env.critical 1:
28

    
29
=head1 Dependencies
30

    
31
Dependencies: openssl
32

    
33
=head1 AUTHOR
34

    
35
andreas perhab - andreas.perhab@wt-io-it.at
36
https://www.wt-io-it.at/
37

    
38
=head1 LICENSE
39

    
40
GPLv2
41

    
42
=cut
43

    
44
. "$MUNIN_LIBDIR/plugins/plugin.sh"
45

    
46
if [ "$1" = "config" ] ; then
47
	echo "graph_title Certificate validity"
48
	echo "graph_args --logarithmic --base 1000"
49
	echo "graph_vlabel certificate validity in days"
50
	echo "graph_category security"
51
fi
52

    
53
now=$(date +%s)
54
warning=${warning:-5:}
55
critical=${critical:-1:}
56
for cert in ${CERTS}; do
57
	cert_type=${cert%:*}
58
	cert_file=${cert#*:}
59
	cert_name=$(clean_fieldname "$cert_file")
60
	if [ "$1" = "config" ] ; then
61
		echo "${cert_name}.label ${cert_file}"
62
		print_warning "$cert_name"
63
		print_critical "$cert_name"
64
	elif [ "$1" = "" ] ; then
65
		validity=$(/usr/bin/openssl "$cert_type" -text -noout -in "$cert_file" | grep -E '(Next Update|Not After)')
66
		validity=${validity#*:}
67
		validity=$(date --date="$validity" +%s)
68
		validity=$((validity - now))
69
		validity=$(echo "$validity" | awk '{ print ($1 / 86400) }')
70
		echo "${cert_name}.value $validity"
71
	fi
72
done