aboutsummaryrefslogtreecommitdiff
path: root/zabbix/statefile.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-02-24 23:05:45 +0100
committerJulien Dessaux2020-02-25 09:46:38 +0100
commitcadb15f7afb5e7c88667eb4006209efca17744af (patch)
tree7e8e9e55c22bd4d195caf2b1dc1123500443ce75 /zabbix/statefile.go
parentAdded tests to the spool package, and reworked the code around that. (diff)
downloadbareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.tar.gz
bareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.tar.bz2
bareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.zip
Added tests to the main package and completely reworked the code around that1.0
Diffstat (limited to '')
-rw-r--r--zabbix/statefile.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/zabbix/statefile.go b/zabbix/statefile.go
new file mode 100644
index 0000000..26ea650
--- /dev/null
+++ b/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
+}