aboutsummaryrefslogtreecommitdiff
path: root/pkg/zabbix/statefile.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-04-23 16:51:22 +0200
committerJulien Dessaux2021-04-23 16:51:22 +0200
commit38d9c881b3b5ece91f428c87f0b7bb9efb3e88a8 (patch)
treed3f7167fae6388f4db35a63e660d1816c9c2943e /pkg/zabbix/statefile.go
parentFixed wrongfully hardcoded path in tests. (diff)
downloadbareos-zabbix-check-38d9c881b3b5ece91f428c87f0b7bb9efb3e88a8.tar.gz
bareos-zabbix-check-38d9c881b3b5ece91f428c87f0b7bb9efb3e88a8.tar.bz2
bareos-zabbix-check-38d9c881b3b5ece91f428c87f0b7bb9efb3e88a8.zip
Updated for go 1.16 modules1.2
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
+}