You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
2 years ago
|
#!/bin/bash
|
||
|
|
||
|
# Recommended crontab:
|
||
|
# * * * * * /path/to/collect-certdata.sh
|
||
|
|
||
|
influx_host="{{ influx_host }}"
|
||
|
influx_path="/api/v2/write"
|
||
|
influx_org="{{ influx_org }}"
|
||
|
influx_bucket="{{ influx_bucket }}"
|
||
|
influx_token="{{ influx_token }}"
|
||
|
influx_metric="certificate"
|
||
|
domains=({% for dns in certificate_monitor_domains %}"{{dns}}" {% endfor %})
|
||
|
|
||
|
influx_url="${influx_host}${influx_path}?org=${influx_org}&bucket=${influx_bucket}"
|
||
|
influx_header_auth="Authorization: Token ${influx_token}"
|
||
|
influx_header_content="Content-Type: text/plain; charset=utf-8"
|
||
|
influx_header_accept="Accept: application/json"
|
||
|
|
||
|
for dn in ${domains[@]}; do
|
||
|
certificate="$(openssl s_client -connect ${dn}:443 2>/dev/null </dev/null | openssl x509)"
|
||
|
|
||
|
# Calculation broken down from https://gist.github.com/holly/4205943
|
||
|
datestr=`echo "${certificate}" | openssl x509 -enddate -noout | cut -d'=' -f2`
|
||
|
daystr=`date -d "$datestr" "+%s"`
|
||
|
current_time=$(date "+%s")
|
||
|
days=`echo $((($daystr - $current_time) / 60 / 60 / 24))`
|
||
|
|
||
|
data="${influx_metric},domain=${dn} remaining=${days}i"
|
||
|
|
||
|
curl --request POST "${influx_url}" --header "${influx_header_auth}" --header "${influx_header_content}" --header "${influx_header_accept}" --data-binary "${data}"
|
||
|
|
||
|
done
|