1
0
Fork 0

Added tests to the main package and completely reworked the code around that

This commit is contained in:
Julien Dessaux 2020-02-24 23:05:45 +01:00
parent 2661ce9a2b
commit cadb15f7af
17 changed files with 285 additions and 239 deletions

34
zabbix/statefile.go Normal file
View file

@ -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
}