diff options
author | Julien Dessaux | 2021-04-23 16:51:22 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-04-23 16:51:22 +0200 |
commit | 38d9c881b3b5ece91f428c87f0b7bb9efb3e88a8 (patch) | |
tree | d3f7167fae6388f4db35a63e660d1816c9c2943e /pkg/zabbix/workdir.go | |
parent | Fixed wrongfully hardcoded path in tests. (diff) | |
download | bareos-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/workdir.go')
-rw-r--r-- | pkg/zabbix/workdir.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/pkg/zabbix/workdir.go b/pkg/zabbix/workdir.go new file mode 100644 index 0000000..287c80a --- /dev/null +++ b/pkg/zabbix/workdir.go @@ -0,0 +1,38 @@ +package zabbix + +import ( + "fmt" + "os" + "path/filepath" +) + +const ( + bareosWorkDir = "/var/lib/bareos" + baculaWorkDir = "/var/lib/bacula" +) + +var root = "/" + +// checkWorkDir checks if a work directory is valid +func checkWorkDir() error { + // Determine the work directory to use. + if workDir != "" { + workDir = filepath.Join(root, workDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + return fmt.Errorf("Invalid work directory %s : it does not exist or is not a directory", workDir) + } + } else { + workDir = filepath.Join(root, bareosWorkDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + workDir = filepath.Join(root, baculaWorkDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + return fmt.Errorf("Could not find a suitable work directory. Is bareos or bacula installed?") + } + } + } + workDir = filepath.Clean(workDir) + return nil +} |