aboutsummaryrefslogtreecommitdiff
path: root/config/statefile.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 /config/statefile.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 '')
-rw-r--r--config/statefile.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/config/statefile.go b/config/statefile.go
new file mode 100644
index 0000000..8b9f0a9
--- /dev/null
+++ b/config/statefile.go
@@ -0,0 +1,39 @@
+package config
+
+import (
+ "fmt"
+ "log"
+ "os"
+ "path"
+)
+
+const (
+ bareosStateFile = "bareos-fd.9102.state"
+ baculaStateFile = "bacula-fd.9102.state"
+)
+
+func (c *Config) checkStateFile() {
+ // Finds the state file to parse
+ if c.stateFile != "" {
+ c.stateFile = path.Join(c.workDir, c.stateFile)
+ info, err := os.Stat(c.stateFile)
+ if os.IsNotExist(err) || info.IsDir() {
+ fmt.Printf("INFO The state file %s does not exist.\n", c.stateFile)
+ os.Exit(0)
+ }
+ } else {
+ c.stateFile = path.Join(c.workDir, bareosStateFile)
+ info, err := os.Stat(c.stateFile)
+ if os.IsNotExist(err) || info.IsDir() {
+ c.stateFile = path.Join(c.workDir, baculaStateFile)
+ info, err = os.Stat(c.stateFile)
+ if os.IsNotExist(err) || info.IsDir() {
+ fmt.Println("INFO Could not find a suitable state file. Has a job ever run?")
+ os.Exit(0)
+ }
+ }
+ }
+ if c.verbose {
+ log.Println("Using state file ", c.stateFile)
+ }
+}