aboutsummaryrefslogtreecommitdiff
path: root/spool/load.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-01-30 17:44:42 +0100
committerJulien Dessaux2020-01-30 17:44:42 +0100
commitbea8e5aba8fc84dcb0c980c3948ed6d78719dded (patch)
treef84f2722b98f4c2996b64ce24ac322c9709617ed /spool/load.go
parentDocument where C structures for state file header and job entry come from (diff)
downloadbareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.tar.gz
bareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.tar.bz2
bareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.zip
Big rafactoring : code split in several modules and some other best practices
Diffstat (limited to 'spool/load.go')
-rw-r--r--spool/load.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/spool/load.go b/spool/load.go
new file mode 100644
index 0000000..282fdc6
--- /dev/null
+++ b/spool/load.go
@@ -0,0 +1,40 @@
+package spool
+
+import (
+ "bareos-zabbix-check/config"
+ "bareos-zabbix-check/job"
+ "encoding/csv"
+ "fmt"
+ "log"
+ "os"
+ "path"
+ "strconv"
+)
+
+// Load loads a spool file in path
+func (s *Spool) Load(c *config.Config) (err error) {
+ s.config = c
+ // We read the spool
+ file, err := os.Open(path.Join(c.WorkDir(), spoolFile))
+ if err != nil {
+ return fmt.Errorf("Couldn't open spool file, starting from scratch: %s", err)
+ }
+ defer file.Close()
+ lines, err := csv.NewReader(file).ReadAll()
+ if err != nil {
+ return fmt.Errorf("Corrupted spool file, starting from scratch : %s", err)
+ }
+ if c.Verbose() {
+ log.Printf("Spool file content : %v\n", lines)
+ }
+
+ for _, line := range lines {
+ var i int
+ i, err = strconv.Atoi(line[1])
+ if err != nil {
+ return fmt.Errorf("Corrupted spool file : couldn't parse timestamp entry")
+ }
+ s.jobs = append(s.jobs, job.Job{Name: line[0], Timestamp: uint64(i), Success: true})
+ }
+ return
+}