mirror of
https://github.com/Luzifer/webcheck.git
synced 2025-01-08 19:41:39 +00:00
Add missing log cleanup
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
cc84933f05
commit
0ccbc80797
1 changed files with 22 additions and 0 deletions
22
main.go
22
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -149,6 +150,8 @@ func main() {
|
||||||
|
|
||||||
lastResult := newCheckResult(statusUnknown, "Uninitialized", 0)
|
lastResult := newCheckResult(statusUnknown, "Uninitialized", 0)
|
||||||
|
|
||||||
|
go cleanupLogFiles()
|
||||||
|
|
||||||
for range time.Tick(cfg.Interval) {
|
for range time.Tick(cfg.Interval) {
|
||||||
var (
|
var (
|
||||||
body *bytes.Buffer
|
body *bytes.Buffer
|
||||||
|
@ -180,6 +183,25 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanupLogFiles() {
|
||||||
|
for {
|
||||||
|
if err := filepath.Walk(cfg.LogDir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && time.Since(info.ModTime()) > cfg.LogRetention {
|
||||||
|
return os.Remove(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
fmt.Println()
|
||||||
|
log.WithError(err).Error("Could not clean up logs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func doCheck(url string, match *regexp.Regexp, responseBody io.Writer) *checkResult {
|
func doCheck(url string, match *regexp.Regexp, responseBody io.Writer) *checkResult {
|
||||||
req, _ := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue