aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-02-22 12:35:05 +0100
committerJulien Dessaux2020-02-22 12:56:29 +0100
commit2661ce9a2bda2b6c1efc0ba1fef873c9dc91bb7c (patch)
tree155f36ee7f62f972fc49e5df0440948a4ba0348c /main.go
parentAdded tests to the state package, and reworked the code around that (diff)
downloadbareos-zabbix-check-2661ce9a2bda2b6c1efc0ba1fef873c9dc91bb7c.tar.gz
bareos-zabbix-check-2661ce9a2bda2b6c1efc0ba1fef873c9dc91bb7c.tar.bz2
bareos-zabbix-check-2661ce9a2bda2b6c1efc0ba1fef873c9dc91bb7c.zip
Added tests to the spool package, and reworked the code around that.
Diffstat (limited to '')
-rw-r--r--main.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/main.go b/main.go
index bc5945c..62347ab 100644
--- a/main.go
+++ b/main.go
@@ -8,13 +8,17 @@ import (
"fmt"
"log"
"os"
+ "path/filepath"
"time"
)
+const (
+ spoolFileName = "bareos-zabbix-check.spool"
+)
+
func main() {
var (
config config.Config
- spool spool.Spool
errorString string
missingString string
)
@@ -58,14 +62,24 @@ func main() {
// We will check for errors in loading the spool file only at the end. If all jobs ran successfully without errors
// in the state file and we manage to write a new spool file without errors, then we will ignore any error here to
// avoid false positives during backup bootstrap
- err = spool.Load(&config)
+ // Open the spool file
+ spoolFile, spoolErr := os.Open(filepath.Join(config.WorkDir(), spoolFileName))
+ var spoolJobs []job.Job
+ if err == nil {
+ defer spoolFile.Close()
+ spoolJobs, spoolErr = spool.Parse(spoolFile)
+ }
- jobs = job.KeepOldestOnly(append(jobs, spool.Jobs()...))
- spool.SetJobs(job.KeepSuccessOnly(jobs))
+ jobs = job.KeepOldestOnly(append(jobs, spoolJobs...))
// we write this new spool
- if err2 := spool.Save(); err2 != nil {
- fmt.Printf("AVERAGE: Error saving the spool file : %s\n", err2)
+ spoolFile, err = os.Create(filepath.Join(config.WorkDir(), spoolFileName))
+ if err == nil {
+ defer spoolFile.Close()
+ err = spool.Serialize(spoolFile, jobs)
+ }
+ if err != nil {
+ fmt.Printf("AVERAGE: Error saving the spool file : %s\n", err)
os.Exit(0)
}
@@ -91,8 +105,8 @@ func main() {
// Finally we output
if errorString != "" || missingString != "" {
fmt.Printf("AVERAGE: %s %s", errorString, missingString)
- if err != nil {
- fmt.Printf(" additionnal errors: %s", err)
+ if spoolErr != nil {
+ fmt.Printf(" additionnal errors: %s", spoolErr)
}
} else {
fmt.Printf("OK")