feat: add completion webhook url
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
e43e8c3959
commit
07c2fae209
|
@ -67,6 +67,11 @@ are only as many as this config variable.
|
||||||
|
|
||||||
Default: `12`
|
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
|
## Building from source
|
||||||
|
|
||||||
This project uses go modules, so you'll need at least go 1.11 to compile it.
|
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
|
fullCurrentBackupPath string
|
||||||
Schedule string
|
Schedule string
|
||||||
MaxBackups int
|
MaxBackups int
|
||||||
|
CompletionWebhookURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -25,9 +26,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
envBackupFolder = `BACKUP_FOLDER`
|
envBackupFolder = `BACKUP_FOLDER`
|
||||||
envSchedule = `BACKUP_SCHEDULE`
|
envSchedule = `BACKUP_SCHEDULE`
|
||||||
envMax = `BACKUP_MAX`
|
envMax = `BACKUP_MAX`
|
||||||
|
envCompletionWebhookURL = `BACKUP_COMPLETION_WEBHOOK_URL`
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -60,6 +62,11 @@ func init() {
|
||||||
config.MaxBackups = int(maxBackups)
|
config.MaxBackups = int(maxBackups)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webhookURL, has := os.LookupEnv(envCompletionWebhookURL)
|
||||||
|
if has {
|
||||||
|
config.CompletionWebhookURL = webhookURL
|
||||||
|
}
|
||||||
|
|
||||||
updateFullBackupPath()
|
updateFullBackupPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
main.go
5
main.go
|
@ -32,6 +32,11 @@ func main() {
|
||||||
log.Fatalf("Could not dump databases: %s", err)
|
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.")
|
log.Println("Done.")
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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…
Reference in New Issue