root / plugins / ssl / letsencrypt_weekly @ c6590b67
Historique | Voir | Annoter | Télécharger (5,88 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
: << =cut |
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
letsencrypt_weekly - monitor the number of CSRs by week for /etc/letsencrypt/csr/ |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
This plugin monitors the number of certificate signing requests (CSRs) done with letsencrypt's certbot. |
| 10 |
It tries to determine the registered domain and reports the number also per registered domain. |
| 11 |
For people running multiple servers this enables aggregation of those numbers across multiple nodes in the munin.conf |
| 12 |
|
| 13 |
see https://letsencrypt.org/docs/rate-limits/ |
| 14 |
|
| 15 |
=head1 CONFIGURATION |
| 16 |
|
| 17 |
You can configure the warning and critical limits for this plugin: |
| 18 |
|
| 19 |
[letsencrypt_weekly] |
| 20 |
# run with a user that is able to read /etc/letsencrypt/csr/ files and at least list directories in |
| 21 |
# /etc/letsencrypt/archive/ |
| 22 |
user root |
| 23 |
# warn when more than 40 certificates have been requested in the last week |
| 24 |
env.warning :40 |
| 25 |
# critical when more than 50 certificates have been requested in the last week |
| 26 |
env.critical :50 |
| 27 |
|
| 28 |
=head1 AGGREGATION CONFIGURATION |
| 29 |
|
| 30 |
When you have multiple servers issuing certficates for the same registered domain you can aggregate the numbers with |
| 31 |
this config: |
| 32 |
|
| 33 |
[letsencrypt] |
| 34 |
update no |
| 35 |
contact no |
| 36 |
# summarize letsencrypt_weekly from all hosts |
| 37 |
# see http://guide.munin-monitoring.org/en/latest/example/graph/aggregated-stack.html#extract-from-munin-conf |
| 38 |
# see http://guide.munin-monitoring.org/en/latest/example/graph/aggregate.html#example-plugin-aggregate |
| 39 |
|
| 40 |
letsencrypt_weekly_example_com.update no |
| 41 |
letsencrypt_weekly_example_com.graph_args --base 1000 -l 0 |
| 42 |
letsencrypt_weekly_example_com.graph_category security |
| 43 |
letsencrypt_weekly_example_com.graph_period week |
| 44 |
letsencrypt_weekly_example_com.graph_title Letsencrypt example.com certificate requests |
| 45 |
letsencrypt_weekly_example_com.graph_vlabel requests / week |
| 46 |
letsencrypt_weekly_example_com.graph_scale no |
| 47 |
letsencrypt_weekly_example_com.graph_total Total |
| 48 |
letsencrypt_weekly_example_com.weekly.label Certificates for example.com |
| 49 |
letsencrypt_weekly_example_com.weekly.draw AREA |
| 50 |
letsencrypt_weekly_example_com.weekly.stack \ |
| 51 |
line1_name=example.com;line1-host-name.example.com:letsencrypt_weekly.example_com_weekly \ |
| 52 |
line2_name=example.com;line2-host-name.example.com:letsencrypt_weekly.example_com_weekly |
| 53 |
|
| 54 |
letsencrypt_renewal_weekly_example_com.update no |
| 55 |
letsencrypt_renewal_weekly_example_com.graph_args --base 1000 -l 0 |
| 56 |
letsencrypt_renewal_weekly_example_com.graph_category security |
| 57 |
letsencrypt_renewal_weekly_example_com.graph_period week |
| 58 |
letsencrypt_renewal_weekly_example_com.graph_title Letsencrypt example.com certificate renewal requests |
| 59 |
letsencrypt_renewal_weekly_example_com.graph_vlabel requests / week |
| 60 |
letsencrypt_renewal_weekly_example_com.graph_scale no |
| 61 |
letsencrypt_renewal_weekly_example_com.graph_total Total |
| 62 |
letsencrypt_renewal_weekly_example_com.weekly.label Certificate renewals for example.com |
| 63 |
letsencrypt_renewal_weekly_example_com.weekly.draw AREA |
| 64 |
letsencrypt_renewal_weekly_example_com.weekly.stack \ |
| 65 |
line1_name=example.com;line1-host-name.example.com:letsencrypt_weekly.example_com_renewal_weekly \ |
| 66 |
line2_name=example.com;line2-host-name.example.com:letsencrypt_weekly.example_com_renewal_weekly |
| 67 |
|
| 68 |
=head1 Dependencies |
| 69 |
|
| 70 |
Dependencies: openssl |
| 71 |
|
| 72 |
=head1 AUTHOR |
| 73 |
|
| 74 |
andreas perhab - andreas.perhab@wt-io-it.at (https://www.wt-io-it.at/) |
| 75 |
|
| 76 |
=head1 LICENSE |
| 77 |
|
| 78 |
GPLv2 |
| 79 |
|
| 80 |
=head1 MAGIC MARKERS |
| 81 |
|
| 82 |
#%# family=auto |
| 83 |
#%# capabilities=autoconf |
| 84 |
|
| 85 |
=cut |
| 86 |
|
| 87 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 88 |
|
| 89 |
warning=${warning:-:40}
|
| 90 |
critical=${critical:-:50} #letsencrypt doesn't allow more than 50 certificates per week
|
| 91 |
# see https://letsencrypt.org/docs/rate-limits/ |
| 92 |
|
| 93 |
|
| 94 |
get_files_and_domains() {
|
| 95 |
find /etc/letsencrypt/csr/ -mtime -7 -type f -print0 2>/dev/null | xargs -0 -I pem bash -c 'echo -n "pem "; openssl req -in pem -text -noout | grep DNS: | sed "s/.*DNS://g"' |
| 96 |
} |
| 97 |
|
| 98 |
get_registered_domains() {
|
| 99 |
local REMOVE_PATH |
| 100 |
local TRIM_SUBDOMAIN |
| 101 |
REMOVE_PATH='s,.*/,,;' |
| 102 |
TRIM_SUBDOMAIN='s/.*\.\([a-z0-9-]\+\.[a-z]\+\)/\1/;' |
| 103 |
find /etc/letsencrypt/archive/ -mindepth 1 -maxdepth 1 | sed "$REMOVE_PATH $TRIM_SUBDOMAIN" | sort | uniq |
| 104 |
} |
| 105 |
|
| 106 |
if [ "$1" = "autoconf" ] ; then |
| 107 |
test -d /etc/letsencrypt/csr/ && echo "yes" || echo "no (directory /etc/letsencrypt/csr does not exist)" |
| 108 |
elif [ "$1" = "config" ] ; then |
| 109 |
echo "graph_title Letsencrypt certificate requests during last week" |
| 110 |
echo "graph_args --base 1000" |
| 111 |
echo "graph_vlabel Number of certificates" |
| 112 |
echo "graph_category security" |
| 113 |
echo "letsencrypt_weekly.label Letsencrypt certificates last week" |
| 114 |
for domain in $(get_registered_domains); do |
| 115 |
key=${domain//[-.]/_}
|
| 116 |
echo "${key}_weekly.label $domain"
|
| 117 |
print_warning "${key}_weekly"
|
| 118 |
print_critical "${key}_weekly"
|
| 119 |
echo "${key}_renewal_weekly.label $domain renewals"
|
| 120 |
done |
| 121 |
elif [ "$1" = "" ] ; then |
| 122 |
if existing_renewal_requests=$(get_files_and_domains); then |
| 123 |
value=$(echo "$existing_renewal_requests" | grep -v '^$' -c) |
| 124 |
else |
| 125 |
value="U" |
| 126 |
fi |
| 127 |
echo "letsencrypt_weekly.value $value" |
| 128 |
values="" |
| 129 |
for domain in $(get_registered_domains); do |
| 130 |
key=${domain//[-.]/_}
|
| 131 |
if [ "$values" != "" ] ; then |
| 132 |
values="$values\n${key}_weekly.value 0\n${key}_renewal_weekly.value 0"
|
| 133 |
else |
| 134 |
values="${key}_weekly.value 0\n${key}_renewal_weekly.value 0"
|
| 135 |
fi |
| 136 |
done |
| 137 |
while read -r file_domain; do |
| 138 |
file=${file_domain% *}
|
| 139 |
domain=${file_domain#* }
|
| 140 |
registered_domain_key=$(echo "$domain" | sed 's/.*\.\([a-z0-9-]\+\.[a-z]\+\)/\1/;s/[-.]/_/g') |
| 141 |
previous_certs=$(find "/etc/letsencrypt/archive/$domain" -name 'cert*.pem' -not -cnewer "$file" | wc -l) |
| 142 |
if [ "$previous_certs" -gt 0 ] ; then |
| 143 |
value_key="${registered_domain_key}_renewal_weekly.value "
|
| 144 |
else |
| 145 |
value_key="${registered_domain_key}_weekly.value "
|
| 146 |
fi |
| 147 |
old_value=$(echo -e "$values" | grep "$value_key" | sed 's/.* //g') |
| 148 |
value=$((old_value + 1)) |
| 149 |
values=${values//$value_key$old_value/$value_key$value}
|
| 150 |
done < <(get_files_and_domains) |
| 151 |
echo -e $"$values" |
| 152 |
fi |
