aboutsummaryrefslogtreecommitdiff
path: root/pkg/zabbix/statefile.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/zabbix/statefile.go')
-rw-r--r--pkg/zabbix/statefile.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/zabbix/statefile.go b/pkg/zabbix/statefile.go
new file mode 100644
index 0000000..26ea650
--- /dev/null
+++ b/pkg/zabbix/statefile.go
@@ -0,0 +1,34 @@
+package zabbix
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+const (
+ bareosStateFile = "bareos-fd.9102.state"
+ baculaStateFile = "bacula-fd.9102.state"
+)
+
+func checkStateFile() error {
+ // Finds the state file to parse
+ if stateFileName != "" {
+ stateFileName = filepath.Join(workDir, stateFileName)
+ info, err := os.Stat(stateFileName)
+ if os.IsNotExist(err) || info.IsDir() {
+ return fmt.Errorf("The state file %s does not exist", stateFileName)
+ }
+ } else {
+ stateFileName = filepath.Join(workDir, bareosStateFile)
+ info, err := os.Stat(stateFileName)
+ if os.IsNotExist(err) || info.IsDir() {
+ stateFileName = filepath.Join(workDir, baculaStateFile)
+ info, err = os.Stat(stateFileName)
+ if os.IsNotExist(err) || info.IsDir() {
+ return fmt.Errorf("Could not find a suitable state file. Has a job ever run?")
+ }
+ }
+ }
+ return nil
+}