From 9cf1463a75db7adb306e5f5f9f547ac1bbb9af8d Mon Sep 17 00:00:00 2001 From: WhatTheMike Date: Thu, 11 May 2023 12:24:52 +0000 Subject: [PATCH] Added endlessh collection script --- playbooks/smolmonitor.yaml | 18 ++++++++++++++++++ templates/collect-certdata.sh.j2 | 4 ++-- templates/collect-endlesshdata.sh.j2 | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 templates/collect-endlesshdata.sh.j2 diff --git a/playbooks/smolmonitor.yaml b/playbooks/smolmonitor.yaml index c71e8f1..8c340f0 100644 --- a/playbooks/smolmonitor.yaml +++ b/playbooks/smolmonitor.yaml @@ -47,3 +47,21 @@ state: present become: true become_method: sudo + + +####- endlessh monitoring script + + - name: Verify certificate script is deployed + ansible.builtin.template: + dest: /opt/sublight/scripts/collect-endlesshdata.sh + src: ~/ansible/templates/collect-endlesshdata.sh.j2 + mode: '0744' + - name: Ensure cert monitoring script is scheduled + ansible.builtin.cron: + name: "Poll endlessh data" + minute: "*" + job: "/opt/sublight/scripts/collect-endlesshdata.sh" + user: root + state: present + become: true + become_method: sudo diff --git a/templates/collect-certdata.sh.j2 b/templates/collect-certdata.sh.j2 index a6914e8..c30ae1b 100644 --- a/templates/collect-certdata.sh.j2 +++ b/templates/collect-certdata.sh.j2 @@ -6,8 +6,8 @@ influx_host="{{ influx_host }}" influx_path="/api/v2/write" influx_org="{{ influx_org }}" -influx_bucket="{{ influx_bucket }}" -influx_token="{{ influx_token }}" +influx_bucket="{{ influx_bucket_cert }}" +influx_token="{{ influx_token_cert }}" influx_metric="certificate" domains=({% for dns in certificate_monitor_domains %}"{{dns}}" {% endfor %}) diff --git a/templates/collect-endlesshdata.sh.j2 b/templates/collect-endlesshdata.sh.j2 new file mode 100644 index 0000000..34fe727 --- /dev/null +++ b/templates/collect-endlesshdata.sh.j2 @@ -0,0 +1,26 @@ +#!/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_endlessh }}" +influx_token="{{ influx_token_endlessh }}" +influx_metric="endlessh" +endless_hosts=({% for endless_host in endlessh_hostnames %}"{{endless_host}}" {% endfor %}) +# https://aperture.dismyserver.net/.endlessh.stats.html +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 endless_host in ${endless_hosts[@]}; do + endless_stats="$(curl -s https://${endless_host}/.endlessh.stats.html)" + endless_active="$(echo ${endless_stats} | cut -d/ -f1)" + endless_total="$(echo ${endless_stats} | cut -d/ -f2)" + data="${influx_metric},host=${endless_host} active=${endless_active}i,total=${endless_total}i" + + curl --request POST "${influx_url}" --header "${influx_header_auth}" --header "${influx_header_content}" --header "${influx_header_accept}" --data-binary "${data}" +done