Skip to content

Commit

Permalink
Switched to using a var for the webhook url, wrapped the chia monit a…
Browse files Browse the repository at this point in the history
…lerting in the monit config with a check, removed tailscale IPs in the alerting message
  • Loading branch information
pmaslana committed Oct 21, 2024
1 parent fce39a6 commit 518754c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions chia-blockchain/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ chia_healthcheck_port: 9950
add_monit_config: true
monit_start_now: true
chia_alerts_receiver_token: ""
chia_monit_alert_on_restart: false
chia_monit_alert_webhook_url: ""
# How many times the port check needs to fail before monit will restart the service
chia_monit_failure_threshold: 3

Expand Down
3 changes: 2 additions & 1 deletion chia-blockchain/templates/monit_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ check host localhost with address 127.0.0.1
{% if "timelord" in chia_enabled_services %}
if failed port {{ chia_healthcheck_port }} protocol http request "/timelord" status = 200 for 1 cycles then restart
{% endif %}
{% endif %}
if 5 restarts within {{ 5 * chia_monit_failure_threshold }} cycles then timeout
{% if chia_monit_alert_on_restart %}
if 1 restarts within {{ chia_monit_failure_threshold }} cycles then exec "/etc/monit/monit-notify.sh"
{% endif %}
8 changes: 3 additions & 5 deletions chia-blockchain/templates/monit_notify.sh.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/bash

# Webhook URL where the alert will be sent
WEBHOOK_URL="https://alert-receiver.chiaops.com/ips-info"
WEBHOOK_URL="{{ chia_monit_alert_webhook_url }}"
HOSTNAME=$(/bin/hostname)
BEARER_TOKEN="{{ CHIA_ALERTS_RECEIVER_TOKEN }}"
BEARER_TOKEN="{{ chia_alerts_receiver_token }}"

# Get the Tailscale IPv4 address
TAILSCALE_IPV4=$(tailscale ip | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n 1)
PAYLOAD=$(
cat <<EOF
{
Expand All @@ -15,7 +13,7 @@ PAYLOAD=$(
"status": "warning",
"annotations": {
"title": "Monit Alert",
"description": "Monit has restarted the Chia services on host $HOSTNAME with Tailscale IP $TAILSCALE_IPV4"
"description": "Monit has restarted the Chia services on host $HOSTNAME"
}
}
]
Expand Down

0 comments on commit 518754c

Please sign in to comment.