feat: add completion webhook url
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e43e8c3959
commit
07c2fae209
@ -67,6 +67,11 @@ are only as many as this config variable.
|
||||
|
||||
Default: `12`
|
||||
|
||||
### `BACKUP_COMPLETION_WEBHOOK_URL`
|
||||
|
||||
If provided, the tool will do an empty GET request to this URL to indicate it successfully completed the backup job.
|
||||
You can use this with other tools to monitor if backups are completed as they should.
|
||||
|
||||
## Building from source
|
||||
|
||||
This project uses go modules, so you'll need at least go 1.11 to compile it.
|
||||
|
13
config.go
13
config.go
@ -17,6 +17,7 @@ type conf struct {
|
||||
fullCurrentBackupPath string
|
||||
Schedule string
|
||||
MaxBackups int
|
||||
CompletionWebhookURL string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -25,9 +26,10 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
envBackupFolder = `BACKUP_FOLDER`
|
||||
envSchedule = `BACKUP_SCHEDULE`
|
||||
envMax = `BACKUP_MAX`
|
||||
envBackupFolder = `BACKUP_FOLDER`
|
||||
envSchedule = `BACKUP_SCHEDULE`
|
||||
envMax = `BACKUP_MAX`
|
||||
envCompletionWebhookURL = `BACKUP_COMPLETION_WEBHOOK_URL`
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -60,6 +62,11 @@ func init() {
|
||||
config.MaxBackups = int(maxBackups)
|
||||
}
|
||||
|
||||
webhookURL, has := os.LookupEnv(envCompletionWebhookURL)
|
||||
if has {
|
||||
config.CompletionWebhookURL = webhookURL
|
||||
}
|
||||
|
||||
updateFullBackupPath()
|
||||
}
|
||||
|
||||
|
5
main.go
5
main.go
@ -32,6 +32,11 @@ func main() {
|
||||
log.Fatalf("Could not dump databases: %s", err)
|
||||
}
|
||||
|
||||
err = callWebhook()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not call completion webhook: %s", err)
|
||||
}
|
||||
|
||||
log.Println("Done.")
|
||||
})
|
||||
if err != nil {
|
||||
|
26
webhook.go
Normal file
26
webhook.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func callWebhook() error {
|
||||
if config.CompletionWebhookURL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := http.Get(config.CompletionWebhookURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res.StatusCode > 399 {
|
||||
buf := bytes.Buffer{}
|
||||
_, _ = buf.ReadFrom(res.Body)
|
||||
return fmt.Errorf("recived an error status code while calling the webhook: %d, message: %s", res.StatusCode, buf.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user