aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-05-19 10:58:22 +0200
committerJulien Dessaux2021-05-19 10:58:22 +0200
commitffa3b6f3d20db7d067272a0dc2245d724fbe1598 (patch)
tree8cc19286ec06bcdaf0f8acbbf723669b3c3fd9f3
parentUpdated for go 1.16 modules (diff)
downloadbareos-zabbix-check-ffa3b6f3d20db7d067272a0dc2245d724fbe1598.tar.gz
bareos-zabbix-check-ffa3b6f3d20db7d067272a0dc2245d724fbe1598.tar.bz2
bareos-zabbix-check-ffa3b6f3d20db7d067272a0dc2245d724fbe1598.zip
Fixes #1 segmentation violation with unprivileged user1.3
-rw-r--r--pkg/zabbix/statefile.go16
-rw-r--r--pkg/zabbix/workdir.go2
-rw-r--r--pkg/zabbix/zabbix_test.go10
3 files changed, 14 insertions, 14 deletions
diff --git a/pkg/zabbix/statefile.go b/pkg/zabbix/statefile.go
index 26ea650..ae8dd28 100644
--- a/pkg/zabbix/statefile.go
+++ b/pkg/zabbix/statefile.go
@@ -15,18 +15,18 @@ 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)
+ _, err := os.Stat(stateFileName)
+ if err != nil {
+ return fmt.Errorf("Could not open state file %s", stateFileName)
}
} else {
stateFileName = filepath.Join(workDir, bareosStateFile)
- info, err := os.Stat(stateFileName)
- if os.IsNotExist(err) || info.IsDir() {
+ _, err := os.Stat(stateFileName)
+ if err != nil {
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?")
+ _, err = os.Stat(stateFileName)
+ if err != nil {
+ return fmt.Errorf("Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use.")
}
}
}
diff --git a/pkg/zabbix/workdir.go b/pkg/zabbix/workdir.go
index 287c80a..eb35942 100644
--- a/pkg/zabbix/workdir.go
+++ b/pkg/zabbix/workdir.go
@@ -29,7 +29,7 @@ func checkWorkDir() error {
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?")
+ return fmt.Errorf("Could not autodetect a suitable work directory. Is bareos or bacula installed?")
}
}
}
diff --git a/pkg/zabbix/zabbix_test.go b/pkg/zabbix/zabbix_test.go
index d623d41..49c0dbc 100644
--- a/pkg/zabbix/zabbix_test.go
+++ b/pkg/zabbix/zabbix_test.go
@@ -34,12 +34,12 @@ func TestMain(t *testing.T) {
args []string
want string
}{
- {"failed bacula_auto_detect", 0, "tmp/bacula_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
- {"failed bareos_auto_detect", 0, "tmp/bareos_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
- {"failed auto_detect", 0, "tmp/non_existent", []string{}, "INFO Failed to init programm : Could not find a suitable work directory. Is bareos or bacula installed?"},
+ {"failed bacula_auto_detect", 0, "tmp/bacula_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
+ {"failed bareos_auto_detect", 0, "tmp/bareos_auto_detect_failed", []string{}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
+ {"failed auto_detect", 0, "tmp/non_existent", []string{}, "INFO Failed to init programm : Could not autodetect a suitable work directory. Is bareos or bacula installed?"},
{"no work directory", 0, "tmp", []string{"-w", "/non_existent"}, fmt.Sprintf("INFO Failed to init programm : Invalid work directory %s/tmp/non_existent : it does not exist or is not a directory", wd)},
- {"no state file auto_detect", 0, "tmp", []string{"-w", "/no_state_file"}, "INFO Failed to init programm : Could not find a suitable state file. Has a job ever run?"},
- {"no state file", 0, "tmp", []string{"-w", "/no_state_file", "-f", "test"}, fmt.Sprintf("INFO Failed to init programm : The state file %s/tmp/no_state_file/test does not exist", wd)},
+ {"no state file auto_detect", 0, "tmp", []string{"-w", "/no_state_file"}, "INFO Failed to init programm : Could not autodetect a suitable state file. Has a job ever run? Does the user you are running the check as has read access to bacula or bareos' /var/lib directory? Alternatively use the -w and -f flags to specify the work directory and state file to use."},
+ {"no state file", 0, "tmp", []string{"-w", "/no_state_file", "-f", "test"}, fmt.Sprintf("INFO Failed to init programm : Could not open state file %s/tmp/no_state_file/test", wd)},
{"ok bareos 18.2", 1582579731, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "OK"},
{"ok bareos 17.2", 1582579731, "tmp/ok-17.2", []string{"-w", "/", "-f", "state"}, "OK"},
{"missing", 1582709331, "tmp/ok-18.2", []string{"-w", "/", "-f", "state"}, "AVERAGE: missing: awhphpipam1_percona_xtrabackup, awhphpipam1_LinuxAll, awhphpipam1_www"},