diff --git a/files/certificate-validity.sh b/files/certificate-validity.sh new file mode 100644 index 0000000..ca58acf --- /dev/null +++ b/files/certificate-validity.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +rm -f /var/lib/prometheus/node-exporter/certs.prom + +for f in /etc/certs/*; do + snapshot_timestamp=$(openssl x509 -noout -enddate -in $f/cert.pem | cut -d= -f2) + snapshot_secs=$(date --date "$snapshot_timestamp" +%s) + now=$(date +%s) + delta=$((snapshot_secs - now)) + name=$(echo $f | cut -d/ -f4) + printf 'certificate_validity{label="%s"} %s\n' $name $delta >> /var/lib/prometheus/node-exporter/certs.prom +done diff --git a/tasks/main.yml b/tasks/main.yml index b571cc3..490a25e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -95,3 +95,18 @@ register: install_cert_result changed_when: cert_result.results[domains_index].changed failed_when: install_cert_result.rc != 0 and "Reload error for" not in install_cert_result.stderr + +- name: Place monitoring script + become: yes + copy: + src: files/certificate-validity.sh + dest: /root/.acme.sh/certificate-validity.sh + mode: 0700 + +- name: Ensure monitoring data is updated + become: yes + cron: + name: "Update monitoring data each minute" + minute: "*/10" + hour: "*" + job: "/root/.acme.sh/certificate-validity.sh"