go-uptime-alert/README.md

75 lines
1.7 KiB
Markdown
Raw Normal View History

2023-10-25 10:23:36 +02:00
# go-uptime-alert
This program checks to see if each URL in a given set of URLs responds with a 200 OK HTTP status, and if they do it send a ping to a healthchecks.io API. I run this as a cronjob or systemd timer every 15 minutes, and I have the grace time and period of the Healthchecks check set to 15 minutes.
## Installation
Requires Go >= 1.20
``` shell
go install git.sr.ht/~hyperreal/go-uptime-alert@latest
```
## Usage
It requires a JSON configuration file located at `~/.config/go-uptime-alert.json`. The configuration file is of the following format:
``` json
{
"service_urls_uuids": [
{ "site_url": "https://hyperreal.coffee", "hc_ping_url": "<Healthchecks.io API ping URL>" },
{ "site_url": "https://fedi.hyperreal.coffee", "hc_ping_url": "<Healthchecks.io API ping URL>" }
]
}
```
### systemd
`~/.config/systemd/user/go-uptime-alert.service`
``` ini
[Unit]
Description=go-uptime-alert service
[Service]
Type=oneshot
ExecStart=/home/user/go/bin/go-uptime-alert
```
`~/.config/systemd/user/go-uptime-alert.timer`
``` ini
[Unit]
Description=go-uptime-alert timer
[Timer]
OnBootSec=15min
OnUnitActiveSec=15min
[Install]
WantedBy=timers.target
```
Enable linger for the user and enable the timer:
``` shell
sudo loginctl enable-linger user
systemctl --user enable --now go-uptime-alert.timer
```
### cron/periodic
Place the following at `/etc/periodic/15min/go-uptime-alert`:
``` shell
#!/bin/sh
LOGFILE="/var/log/go-uptime-alert.log"
sudo -u user /home/user/go/bin/go-uptime-alert >> "${LOGFILE}" 2>&1
```
## TODO
- Send output to a static HTML file and format appropriately for web server.
- Send output to a .md file for use in Hugo or other static site generators.