Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Healthchecks integration #179

Closed
Zottelchen opened this issue Apr 11, 2022 · 8 comments
Closed

Healthchecks integration #179

Zottelchen opened this issue Apr 11, 2022 · 8 comments

Comments

@Zottelchen
Copy link

Hi,
I have a feature request: An Integration of Healthchecks. There is a hosted version, but it can also be selfhosted. It should do the following things:

  1. Webhook when starting a location
  2. Webhook when finishing a location, including status (or success/fail) as well as a (truncated?) log.

Suggested config:

locations:
  my-location-name:
    from: path/to/backup
    to: name-of-backend
    healthcheck: <uuid> (assume hc-ping.com) OR <url> (for selfhosting)

For comparison, here is a shell script I currently use:

HEALTHPING="https://hc-ping.com/<uuid>"
curl -fsS -m 10 --retry 5 -o /dev/null ${HEALTHPING}/start
LOG=$(restic [or other programs] 2>&1)
curl -fsS -m 10 --retry 5 --data-raw "$LOG" -o /dev/null ${HEALTHPING}/$?

The benefit of having that directly integrated here is that it is one thing less to break. Or in a Windows case, one thing less to properly install [curl] as well as not having to fight with shitty Windows batch syntax just to set up a backup for my moms pictures (especially once #68 is merged).

@cupcakearmy
Copy link
Owner

Hey there,

Have you tried hooks? https://autorestic.vercel.app/location/hooks

Adding another option to the config should only be done if it's a generic one. Is there any spec for agnostic healthchecks?

But in general I'd say this perfect for hooks, which already solve this functionality

@olofvndrhr
Copy link

Hey, i even have a working example which i personally use.

This tells healthchecks when you started and when you finished, even with the autorestic location.
And if it fails it will trigger a fail, with the /fail endpoint of healthchecks.
With this example you even know how long your backup took.

extras:
  default_options: &default_opts
    hooks:
      before:
        - 'curl -m 10 --retry 5 -X POST -H "Content-Type: text/plain" --data "Starting backup for location: ${AUTORESTIC_LOCATION}" https://<healthchecks-url>/ping/<uid>/start'
      failure:
        - 'curl -m 10 --retry 5 -X POST -H "Content-Type: text/plain" --data "Backup failed for location: ${AUTORESTIC_LOCATION}" https://<healthchecks-url>/ping/<uid>/fail'
      success:
        - 'curl -m 10 --retry 5 -X POST -H "Content-Type: text/plain" --data "Backup successful for location: ${AUTORESTIC_LOCATION}" https://<healthchecks-url>/ping/<uid>'

And if you set it as a yaml anchor you can reuse the snippet for every location.

locations:
  something:
    from: /somewhere
    to:
      - somewhere-else
    <<: *default_opts

@cupcakearmy
Copy link
Owner

We can include it inthe docs if you wish :)
They solve the issue without introducting new complexity to the code.

@olofvndrhr
Copy link

Yes, if it helps others.
And you can rename the anchor to something that makes more sense for the example :)
Something like:

extras:
  healthchecks: &healthchecks

Or something you find intuitive

@cupcakearmy
Copy link
Owner

Added. Thanks a lot!

https://autorestic.vercel.app/examples

@Zottelchen
Copy link
Author

@cupcakearmy @olofvndrhr

Hey, thanks for this example!

However, I thought it might be nice to have a standard way, so a similar config could be used on Windows and on Linux, without the need to install curl properly on Windows. Currently, curl on Windows is just an alias of Invoke-WebRequest. To make things worse, this a Powerhell-specific alias and does not work anywhere else.

@cupcakearmy
Copy link
Owner

While there is a PR I have little plans to support windows as it will generate an absurd amount of issues which I can't debug. (Don't use/own windows)
But since hooks are generic you can write a script, use whatever functionality is available in windows.
And I don't see a clean generic way to implement this as an option without vendor lock

@ljani
Copy link

ljani commented Apr 18, 2022

@Zottelchen: curl is shipped with Windows since Windows 1803. PowerShell Core does not alias curl to Invoke-WebRequest, only the old PowerShell 5 does, but you can get around it by calling curl.exe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants